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

redirection within onMounted hook with transition enabled causes a hydration error #14524

Open
sxgrant opened this issue Aug 8, 2022 · 4 comments

Comments

@sxgrant
Copy link

sxgrant commented Aug 8, 2022

Environment


  • Operating System: Darwin
  • Node Version: v16.13.0
  • Nuxt Version: 3.0.0-rc.6
  • Package Manager: npm@8.11.0
  • Builder: vite
  • User Config: build, buildModules, runtimeConfig
  • Runtime Modules: -
  • Build Modules: @pinia/nuxt@0.3.1

Reproduction

Was able to reproduce a simplified version of my code which sees the same problem:
https://stackblitz.com/edit/github-r6amfg?file=app.vue

Describe the bug

Update: See comment thread for simpler description of the issue - my original description is unnecessarily complicated to reproduce the problem.

In my project, I have two levels of routing. The app.vue has a <NuxtPage>, and the /home/ route has a <NuxtPage>

A logo is always present in the top left, which will navigate to /home/ (no subroute specified). A pages/home/index.vue file provides a default subroute by calling navigateTo('home/foo'), which so far as I can tell is the best way to handle a default subroute in Nuxt 3.

Clicking this logo works fine from most pages, but if clicked from within home/foo or home/bar it causes the following error:
Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node

No home/* subroutes will load successfully from then on.

I'm aware of #12735 and don't see how the solution therein around ensuring only single-root elements is relevant to my codebase, or the stackblitz reproduction linked here.

Additional context

No response

Logs

runtime-dom.esm-bundler.js:10 Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
    at insert (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:7330:12)
    at move (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:5964:9)
    at move (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:5937:7)
    at move (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:5937:7)
    at activeBranch.transition.afterLeave (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:2388:15)
    at performRemove (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:6051:20)
    at el._leaveCb (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:3025:9)
    at finishLeave (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:7960:13)
    at resolve2 (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:7991:30)
    at whenTransitionEnds (http://localhost:3000/_nuxt/node_modules/.vite/deps/chunk-MC4345I5.js?v=338140a1:8076:12)
@danielroe
Copy link
Member

danielroe commented Aug 8, 2022

It may not be the issue - not looked into it in more detail - but your index page does have two root elements:

<template>
  <nuxt-link to="/parent">Go to parent</nuxt-link>
  <nuxt-link to="/other">Go to other</nuxt-link>
</template>

@sxgrant
Copy link
Author

sxgrant commented Aug 8, 2022

🤦‍♂️ Oops, you're right. I've fixed that in the linked StackBlitz and the behaviour is still the same.

@sxgrant
Copy link
Author

sxgrant commented Aug 11, 2022

I've updated the title because this issue seems simpler than my original case.

Nested routes are irrelevant, this behaviour is the same with a simple routing structure:
https://stackblitz.com/edit/github-fu1vnc?file=app.vue

Using pages/index.vue to redirect to a "default" route works fine initially when first loading root domain, but will break when. you either navigateTo("/") or use a <nuxt-link to="/">

@sxgrant sxgrant changed the title Nested-route redirection: 'default' nested route will not load if navigated to from another subroute Route redirection: 'default' routes will not work when navigated to in nuxt-link Aug 11, 2022
@danielroe
Copy link
Member

I think the root issue here is the same as #13471 and is an upstream suspense + transition issue.

You can work around it by disabling page transitions, which will be easier once nuxt/framework#5859 is merged.

See for example: https://stackblitz.com/edit/github-fu1vnc-9x1zyu

@danielroe danielroe changed the title Route redirection: 'default' routes will not work when navigated to in nuxt-link redirection within onMounted hook with transition enabled causes a hydration error Aug 11, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants