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

fix: does not pass data provided to mount to wrapper component #1750

Merged
merged 1 commit into from Dec 14, 2020

Conversation

xanf
Copy link
Contributor

@xanf xanf commented Dec 12, 2020

#1661 introduced copying of passed options to parent wrapper. However it fails in a weird way if you are using data option for mount/shallowMount with external variable.

i.e.

    const defaultData = { foo: 3 }
    const wrapper = mountingMethod(TestComponent, { data: () => defaultData })

In this case data function will be invoked two times:

  • one for Parent component (wrapper for our TestComponent) - at this point defaultData will be "poisoned" (will become reactive, and observed by Parent component for changes)
  • one when Parent wrapper will be mounted, causing TestComponent instance to mount - at this point Vue will complain
[Vue warn]: Avoid adding reactive properties to a Vue instance or its root $data at runtime - declare it upfront in the data option.

because defaultData is treated as $data for Parent wrapper component already

In general, we do not need setting data on parent wrapper, so I just eliminate this propety before copying

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

Other information:

@xanf
Copy link
Contributor Author

xanf commented Dec 12, 2020

/cc @lmiller1990 as author of #1661

Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, interesting! I guess using an external variable for data is only really something you do in tests?

Either way, seems fine!

@lmiller1990 lmiller1990 merged commit d03f7d3 into vuejs:dev Dec 14, 2020
@lmiller1990
Copy link
Member

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

Successfully merging this pull request may close these issues.

None yet

2 participants