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(nuxt): preserve old vnode when leaving nested route #21823

Merged
merged 22 commits into from
Jul 5, 2023

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jun 27, 2023

πŸ”— Linked issue

resolves #20798
resolves #21417
resolves #21798

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Thjs handles a couple of extra suspense cases:

  • navigating into a nested route
  • navigating out of a nested route
  • navigating between nested routes where the parent rerenders the child

I think some of these really should be handled by the router, but for now this should make things more synchronous and reduce flickers/flashes/out-of-date state between route/layout transitions.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Jun 27, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@danielroe danielroe added the 3.x label Jun 27, 2023
@danielroe danielroe marked this pull request as ready for review July 4, 2023 11:48
@danielroe
Copy link
Member Author

danielroe commented Jul 4, 2023

@antfu Let me know if you can think of any more tests or edge cases to cover.

Co-authored-by: Horu <73709188+HigherOrderLogic@users.noreply.github.com>
Comment on lines +29 to +34
const route = {} as RouteLocation
for (const key in props.route) {
(route as any)[key] = computed(() => previousKey === props.renderKey ? props.route[key as keyof RouteLocationNormalizedLoaded] : previousRoute[key as keyof RouteLocationNormalizedLoaded])
}

provide(PageRouteSymbol, reactive(route))
Copy link
Member

Choose a reason for hiding this comment

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

Just an idea, I am a bit worried about too many computed and effects created for this. Maybe just a defineProperty getter would do? The calculation is simple, we probably don't need computed dirty check logic.

    const route = {} as RouteLocation
    for (const key in props.route) {
      Object.defineProperty(route, key, { get: () => ... })
    }

Copy link
Member

Choose a reason for hiding this comment

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

As the object we access are reactive, it will make the getter tracked on usage (reactivity will be inherited)

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's do it πŸ‘

@danielroe danielroe merged commit d0dde64 into main Jul 5, 2023
28 checks passed
@danielroe danielroe deleted the fix/preserve-old-vnode branch July 5, 2023 10:39
@github-actions github-actions bot mentioned this pull request Jul 5, 2023
@marr
Copy link
Contributor

marr commented Jul 7, 2023

I'm not sure how to reproduce in a minimal way, but this PR appears to have caused my app to stop working properly.
My app has route middleware that redirects to the /login page when not authorized. After logging in (form), I have a plugin that handles redirection. With d0dde64 in place, the redirect never happens. If I checkout the previous commit, things work fine.
Does that indicate that I might be doing something wrong? Any ideas would be helpful.

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