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

Merging inherited data #1953

Closed
skirtles-code opened this issue Aug 24, 2020 · 1 comment
Closed

Merging inherited data #1953

skirtles-code opened this issue Aug 24, 2020 · 1 comment

Comments

@skirtles-code
Copy link
Contributor

Version

3.0.0-rc.7

Reproduction link

https://jsfiddle.net/skirtle/p469rhax/7/

For comparison, Vue 2: https://jsfiddle.net/skirtle/eo2y9f3b/1/

What is expected?

The output should be John - 14.

What is actually happening?

The output is Liz - 14.


There are two differences from Vue 2:

  1. Inherited properties in data are taking precedence over those of the component itself. A typical use case would be providing default values for data properties that can be overridden by the extending component.
  2. In Vue 2 the merge was recursive, so objects within data were also merged. Personally I've never relied on this recursion but there are likely applications that do rely on it.

This is explicitly mentioned in the Vue 2 documentation:

For example, data objects undergo a recursive merge, with the component’s data taking priority in cases of conflicts.

This line still appears in the latest Vue 3 documentation.

Perhaps these changes are intentional but I couldn't find a relevant RFC.

A similar problem was discussed in #1187 but I see nothing there to suggest that this is an intentional change.

@yyx990803
Copy link
Member

The merging behavior is rarely used and IMO it'd be better to stop supporting it, since it leads really implicit coupling that is hard to reason about. Will draft an RFC.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants