-
Notifications
You must be signed in to change notification settings - Fork 380
Error when using @ProvideReactive: Cannot redefine property #277
Comments
I just ran into the same issue. When a second instance of a component that uses Downgrading to 8.2.2 fixes the issue. |
Yes. The ProvideReactive/InjectReactive feature is broken in 8.3.0 after this change. In my child components, I get: |
any news here? I'm getting this error too. |
set const InjectKey = Symbol();
@Component({ inject: [] })
class ParentComponent extends Vue {
@ProvideReactive(InejctKey) foo: any = {};
}
@Component
class ChildComponent extends Vue {
@InjectReactive({
from: InejctKey,
default: ({})
})
readonly foo!: any;
} because // inject parent reactive services (if any)
if (!Array.isArray(componentOptions.inject)) {
componentOptions.inject = componentOptions.inject || {};
componentOptions.inject[reactiveInjectKey] = { from: reactiveInjectKey, default: {}};
} |
@Mrminfive That works in 8.3.0. For a temporarily solution. |
@Mrminfive thanks! |
it will lead the injects in component get undefined |
Any updates for this issue?
This (new) problem affected from I'm rollback to |
Same here again ...with version 9.0.0 😕 Edit: Ok, i dont't know why but in package.json i got version 9.0.0. Since the last one is 8.4.2 i changed to it and now seems to work fine. The affected version i were using before was 8.3.0. |
I'm having this issue on v8.5.1. Is everyone still just using 8.3.0 for now? I can look into a PR if anyone has insight as to what exactly broke.. |
FYI, this would be fixed in PR #330. |
Same problem here on 9.0.0.
Update: The above seems to work fine for me. |
Same problem here (v.8.4.0) |
Same problem here on 8.5.1 |
Same problem here (v.8.5.2). |
actually, you no need to use Vue.observable to create a observer object. just let foo = {key: value}. |
any progress? |
I think it is fixed now in latest: 9.1.2, isn't it? |
This issue is fixed since v9.0.2. Refer to this https://github.com/kaorun343/vue-property-decorator/blob/v9.0.2/src/vue-property-decorator.ts#L69. function produceProvide(original: any) {
let provide: provideFunc = function (this: any) {
let rv = typeof original === 'function' ? original.call(this) : original
rv = Object.create(rv || null)
// set reactive services (propagates previous services if necessary)
rv[reactiveInjectKey] = Object.create(this[reactiveInjectKey] || {})
for (let i in provide.managed) {
rv[provide.managed[i]] = this[i]
}
for (let i in provide.managedReactive) {
rv[provide.managedReactive[i]] = this[i] // Duplicates the behavior of `@Provide`
Object.defineProperty(rv[reactiveInjectKey], provide.managedReactive[i], {
enumerable: true,
get: () => this[i],
})
}
return rv
}
provide.managed = {}
provide.managedReactive = {}
return provide
} Provided reactive object is changed from rv[reactiveInjectKey] = this[reactiveInjectKey] || {} to rv[reactiveInjectKey] = Object.create(this[reactiveInjectKey] || {})
After this fix, every time a newly created object is provided to avoid Object.defineProperty called multiples on same object. By the way, it seems to fix another issue, but coincidentally fixes this issue too, which explains why this issue is still open. |
我将 |
When I upgrade vue-property-decorator to 8.3.0, it comes with a
TypeError: Cannot redefine property
on lineObject.defineProperty(rv[reactiveInjectKey], provide.managedReactive[i], {
.I think it was related to #249 and caused by #264 .
The text was updated successfully, but these errors were encountered: