Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeFindMixin uses the same object instance for data #605

Open
kornalius opened this issue Jun 28, 2021 · 2 comments
Open

makeFindMixin uses the same object instance for data #605

kornalius opened this issue Jun 28, 2021 · 2 comments
Labels

Comments

@kornalius
Copy link

Steps to reproduce

This is a though one to explain, however I found the solution. I spent a few days on this one.

  1. Create 2 components that are called recursively within each other, where one of them use a makeFindMixin.
  2. Put a watcher on the is{name}FindPending data and console.log the newValue and the this._uid of the component instance.
mixins: [
  makeFindMixin({ service: 'documents', name: 'documents' })
],

watch: {
  isDocumentsFindPending (newValue) {
    console.log(newValue, this._uid)
  }
}

It will always log on the first component instance instead of on the proper instance the makeFindMixin is being used.

Solution

When you define the data function, you reuse the same data const in all instances of the makeFindMixin.
By recreating a new object from the data const, all is good.

data () {
  return { ...data }
}

An object.assign should do the job here too.

Expected behavior

The is{name}FindPending (or all props of the data object) should be changed only on the instance of the component where the mixin is defined.

Actual behavior

The is{name}FindPending data is reused on all component instances instead of having one data instance object per component instance. In other words, the dynamic data props are reused by all component instances that use the makeFindMixin mixin.

@J3m5
Copy link
Contributor

J3m5 commented Jun 28, 2021

Good point!

@marshallswain
Copy link
Member

Good catch! @kornalius it's funny to me that I never noticed this. I guess I didn't spend much time with the mixins before switching to the composition api. This is definitely a bug and should be an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants