-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Incorrent route props in beforeRouteEnter when using <transition> #2062
Comments
Note to myself: make sure it comes from vue-router and not from vue's transition |
This is quite strange issue.
Result:
So now it works. Moreover, if reproducing just like @mrnateriver said I get following results:
which is very strange, because as the last click I clicked "first a", not "first b". |
After more testing: Clicking: So what exactly is bugged? It seems, that after switching from component 1 to component 2, 1's last state gets cached. If 1's last state cache isn't diffferent from the new cache (it means, that before leaving component we were on state "A", and we are returning to state "A") everything works at it should: mounted hook is executed before But if 1's state cache differs from new state (before leaving component we were on state "B", and we are returning to state "A") things get broken, and According to: The bug is present only in logged values, if we try to display the prop in DOM it works as it should (after clicking "A" we get "A" - not "B" - in DOM). |
Just to be clear - this bug affects not only logging of those values, but also using them for any operation in general, i.e. fetching data. My guess is that the value is displayed correctly as prop because arguments for the hook are taken from the component instance which is updated after the hook is called, but before component is re-mounted. Thought to emphasise that so that people who stumble upon this issue don't underestimate its significance. |
This is a huge issue because mostly these hooks are used to check if a user is allowed to enter the page (e.g. do not show internal routes if user is not logged in) so this bug could result into a very broken app behaviour for some users and is not easy to be tracked. I hope that somebody will find a solution soon. |
Not sure if my issue is related, but it looks like the closest so far. |
Version
3.0.1
Reproduction link
http://jsfiddle.net/L7hscd8h/3877/
Steps to reproduce
What is expected?
Component props should be set to ones defined in route in
beforeRouteEnter
hook even when transitions are used.Expected output:
What is actually happening?
It seems that props are set after the transition is finished, as well as the
mounted
hook is called. The connection between those two is easily determined by looking at the order of console output with or without transition tag (like at this slightly modified JSFiddle: http://jsfiddle.net/L7hscd8h/3878/).Actual output:
I presume this issue has something to do with Vue reusing components (which had only been a pain in the head for me), since it doesn't occur when switching routes with the same component.
It is undeniably vital for correct values of props to be available in
beforeRouteEnter
since they can be used to fetch data asynchronously for components. Or, if you like, not fetching, but sending.Used versions:
vue-router 3.0.1 (sha512-vLLoY452L JBpALMP5UHum9 7nzR9PeIBCghU9ZtJ1eWm6ieUI8Zb/DI3MYxH32bxkjzYV1LRjNv4qr8d uX/w==)
vue 2.5.13 (sha512-3D lY7HTkKbtswDM4BBHgqyq qo8IAEE8lz8va1dz3LLmttjgo0FxairO4r1iN2OBqk8o1FyL4hvzzTFEdQSEw==)
The text was updated successfully, but these errors were encountered: