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

Prop order effects withDefaults factory function #6940

Closed
CamBurris opened this issue Oct 24, 2022 · 2 comments
Closed

Prop order effects withDefaults factory function #6940

CamBurris opened this issue Oct 24, 2022 · 2 comments

Comments

@CamBurris
Copy link

Vue version

3.2.41

Link to minimal reproduction

https://sfc.vuejs.org/#eNrNUr1uwjAQfpWTl4BUYpXRDaCqfYBuXbwYcMAosS37AkOUd+/ZARTazlUX636/++479+zV+/LcaSZYFXfBeISosfNraU3rXUB4c61/hjq4FoqSZy81FC8PFcuHiuWtouIjKMGRg7r1jUJNHkC1N+dskDnOELVzK8kwdFoy4DkpMSeXvyYrPmJU/I7MntjIatEqX56is7RZn5GuiSiZgBxJMeKZfMmOiD4KzmO9S+RPsXThwMkqQ2fRtLrUsV1sg7tEHQhYsgQxSDvQyLsqScbJlsT+uLwu2fewVQEGaknMc3xCPAs0vQA0yh7SxjQqXcOiDrXaafgIzsdxA9JEwNa5RitLakOasBEQMRh7oECeJe3F4PFd16prMM72ujZWZ5Aqv+vZ/GmEo24BM2MN5sQcVuubUoEoBQv3XEmjYQPFp4qQblKAGJ1aNVEXN23m0z9wFSp/jj8W6psuP5T7Z0INX/BUNps=

Steps to reproduce

Issue appears on screen on load. There are two identical components except the order of the foo and bar props in the Props interface are different. Both are using withDefault with a factory function for setting the value of bar based on the value of foo. Both components have foo passed as true and both are using identical factory functions to set the value of bar. You can see each component sets bar to different values when they should be the same.

In Comp1, foo is defined before bar is. When the factory function for bar is called, the value of foo has been set and can be used to set the value of bar.

In Comp2, bar is defined before foo is. When the factory function for bar is called, the value of foo has not been set and cannot be used to set the value of bar.

What is expected?

The order of props in the interface should not affect using prop values in withDefault factory function.

What is actually happening?

Order of props affects using prop values in withDefault factory function.

System Info

No response

Any additional comments?

No response

@ysy945
Copy link
Contributor

ysy945 commented Oct 24, 2022

This is because the order of 'props' compiled from' interfaces' in different orders is also different. If you put 'foo' on it, you will first process the 'foo' attribute and put it into 'props', and then process' bar'. At this time, 'foo' attribute can be read from 'props', so' true 'is displayed. If 'foo' is placed below, 'foo' has not been placed in 'props' when' bar 'is initialized. So there are two results.
image
image

@posva
Copy link
Member

posva commented Oct 24, 2022

Duplicate of vuejs/vue#6358 and #3254

@posva posva marked this as a duplicate of vuejs/vue#6358 Oct 24, 2022
@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2022
@vuejs vuejs locked and limited conversation to collaborators Oct 26, 2022
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

3 participants