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 value that is initialized as undefined is not updating the child route when bound to router-view in production mode #1216

Closed
mmrpm opened this issue Nov 24, 2021 · 2 comments
Labels
docs Concerns the documentation content or the documentation website

Comments

@mmrpm
Copy link

mmrpm commented Nov 24, 2021

Version

4.0.12

Reproduction link

github.com

Steps to reproduce

  1. Download GitHub repo, npm install, npm run build, npm run prod, open in browser
  2. Wait 300ms for exampleRef to get a value
  3. Click "Go to route2"
  4. See that the exampleRef prop is undefined

What is expected?

In development mode and production mode, when a ref that is initialized as undefined is passed into router-view as a prop and then updated to have a value, I expect that the child route will receive the updated prop value.

What is actually happening?

In production mode, when a ref that is initialized as undefined is passed into router-view as a prop and then updated to have a value, the child route only receives undefined, which is the value that the ref was initialized as.


I was updating from Vue 3.0 to Vue 3.2 and noticed that refs that are initialized as undefined and bound to router-view were not behaving correctly in production mode. I cannot repro this another way, such as using dynamic components, and believe it is something specific to router-view.

@posva
Copy link
Member

posva commented Nov 26, 2021

It's interesting it works in development because it shouldn't work in both environments. This is because RouterView has to rely on attrs to pass arbitrary props to the component it renders. The issue here is attrs is non-reactive, thus you won't see any updates. The correct way to do this is by using the v-slot syntax:

<router-view v-slot="{ Component }">
  <component :is="Component" :custom-prop="prop" />
</router-view>

I think this is worth a mention in the docs at https://next.router.vuejs.org/api/#router-view-s-v-slot

@posva posva added the docs Concerns the documentation content or the documentation website label Nov 26, 2021
@skirtles-code
Copy link
Contributor

I believe the underlying problem in Vue Core was fixed in vuejs/core#5017, released in 3.2.24.

I wonder whether this issue can now be closed? The current Router docs show the correct way to pass a prop at https://router.vuejs.org/guide/essentials/passing-props.html#Via-RouterView.

@posva posva closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Concerns the documentation content or the documentation website
Projects
None yet
Development

No branches or pull requests

3 participants