nuxt: Error When Fast Navigating "Failed to execute 'insertBefore' on 'Node'"
Environment
- Operating System:
Darwin - Node Version:
v17.2.0 - Nuxt Version:
3.0.0-27404660.0f9bcbf - Package Manager:
yarn@1.22.17 - Bundler:
Vite - User Config:
meta,css,plugins,build,buildModules,components,vite,intlify,vueuse - Runtime Modules:
- - Build Modules:
@nuxtjs/eslint-module@3.0.2,@pinia/nuxt@0.1.8,unplugin-icons/nuxt,@nuxtjs/svg@0.3.0,@intlify/nuxt3@0.1.10,@vueuse/nuxt@7.5.5,~/modules/tailwind-viewer
Reproduction
Using Minimal Nuxt 3 Template : https://codesandbox.io/s/loving-feather-utoky
Using My Template : https://codesandbox.io/s/github/viandwi24/nuxt3-awesome-starter
I tested on both templates above the results are the same
Describe the bug
when navigating too fast an error appears like the log below and the application stops working.
for example when I navigate to the “about” page then quickly navigate again to the “home” page.
Additional context
No response
Logs
### **CHROME & BRAVE**
VM946 vue.js:7086 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 (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:7086:12)
at move (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:5432:9)
at move (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:5405:7)
at Object.activeBranch.transition.afterLeave (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:2273:15)
at performRemove (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:5509:20)
at el._leaveCb (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:2874:9)
at finishLeave (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:7713:13)
at resolve2 (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:7743:30)
at whenTransitionEnds (https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:7825:12)
at https://utoky.sse.codesandbox.io/_nuxt/node_modules/.vite/vue.js?v=71a85d57:7751:11
### **SAFARI**
[Error] NotFoundError: The object can not be found here.
insertBefore (vue.js:7086)
insert (vue.js:7086)
move (vue.js:5432)
move (vue.js:5405)
(anonymous function) (vue.js:2273)
performRemove (vue.js:5509)
(anonymous function) (vue.js:2874)
finishLeave (vue.js:7713)
(anonymous function) (vue.js:7751)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 48
- Comments: 95 (21 by maintainers)
Commits related to this issue
- fix: fix: handle error when fast navigate https://github.com/nuxt/framework/issues/3141 — committed to viandwi24/nuxt3-awesome-starter by viandwi24 2 years ago
- fix: re-render page when navigation error occurred temporary solution taken from - https://github.com/nuxt/framework/issues/3141 Signed-off-by: Pranav C <pranavxc@gmail.com> — committed to nocodb/nocodb by pranavxc 2 years ago
- fix: re-render page when navigation error occurred temporary solution taken from - https://github.com/nuxt/framework/issues/3141 Signed-off-by: Pranav C <pranavxc@gmail.com> — committed to nocodb/nocodb by pranavxc 2 years ago
- fix: re-render page when navigation error occurred temporary solution taken from - https://github.com/nuxt/framework/issues/3141 Signed-off-by: Pranav C <pranavxc@gmail.com> — committed to nocodb/nocodb by pranavxc 2 years ago
- fix: re-render page when navigation error occurred temporary solution taken from - https://github.com/nuxt/framework/issues/3141 Signed-off-by: Pranav C <pranavxc@gmail.com> — committed to nocodb/nocodb by pranavxc 2 years ago
- Fix transition bug workaround https://github.com/nuxt/framework/issues/3141 — committed to d0rich/d0rich.github.io by d0rich a year ago
- fix:https://github.com/nuxt/nuxt/issues/13350,Error When Fast Navigating "Failed to execute 'insertBefore' on 'Node'" — committed to starNGC2237/zhilutianji by starNGC2237 a year ago


try setting a key to the top level
NuxtPageinapp.vuelike so:It happens for me too
Just to be clear, this is an upstream
vuebug with nested<Suspense>and until it is fixed there it will be present in Nuxt: follow https://github.com/vuejs/core/issues/5513🩼🩼🩼
I tried this on Nuxt 3.5.2 and it worked but after upgrading to 3.6.5 it didn’t. I updated the code following the Lifecycle Hooks Usage with Plugins Documentation and converted it into TypeScript.
plugins/router.ts
Thanks for this snippet!
Instead of performing a hard reload, I managed to just hot reload the application by keying the layout (basically remounted the content). This allows transitions to keep working (they would just be skipped when navigating too fast) but also to keep the application state.
Same disclaimer as above, it’s fragile, use at your own risk.
@AkioSarkiz Check this link for a temporary solution: https://stackoverflow.com/questions/70396414/nuxtlink-is-updating-route-in-nuxt-3-app-but-not-rendering-contents/70404764
What seems to be the root cause of this problem is now fixed in VueJS core https://github.com/vuejs/core/issues/8105
for now I’m overcoming this error with the @vanling example above. at least this way ensures the client doesn’t have a bad experience when an error occurs.
https://github.com/viandwi24/nuxt3-awesome-starter/blob/d8b1c3bba15cb6fa42573b8c04eaa0b62edfe94c/utils/app.ts#L30-L41
We needed to get a presentation-like application tested and testers&customer got stuck spamming the next button. So for the time being, while hoping for a fix, we just reload the page when this error appears.
It’s a dirty trick 👀 and not recommended, but for now it does the trick to make the application not unresponsive. You can run the following code as client-only code somewhere.
Vue 3.3.10 was just released 🎉
As this issues was linked to the issue I mentioned, there is a good chance this issue could be resolved by updating Vue to
v3.3.10. Would anyone affected please verify?Hi everyone 👋🏻
I’ve found a temporary solution to get around this problem with a plugin.
The plugin will disable navigation when the ‘page:start’ hook is triggered, then re-enable it with the ‘page:transition:finish’ hook. This way, if there’s a route change during the page transition, the router won’t take it into consideration
It’s not very clean, but I think it’ll do the job just fine until they fix it 😁
I guess the best thing is to modify your layout or App.vue and add the following:
<NuxtPage :key="$route.fullPath" />This worked for me and seems to be the latest fix according to this thread hereJust tested quickly to update vue to 3.3.10, it seems to have fix the issue for me !
The issue I linked earlier may be linked, but I’ve reproduced more specifically within Vue core: https://github.com/vuejs/core/issues/8105. This does not seem to be an issue in
vue-router. (cc: @posva)Hi, I had the same bug in my app. After hours of struggling and searching for the best solution, I ended with a plugin, middleware and custom page transitions using GSAP (ofc can use any other library or vanilla js transitions). Finally it seems to work just fine, without any flickering or browser refreshes.
I wrapped NuxtPage component in app.vue in a div with .page-wrapper class, then animated it within the middleware and app hook. Here’s my solution:
@kissu yes, but I think the problem is different than the one in this issue 😃 The solution in that link is about using a single root element which has nothing to do with this issue.
v3.5.1 still exists this problem,hope fix it soon.
Fixed in this release for me https://github.com/nuxt/nuxt/releases/tag/v3.9.1
By denying users too fast routing, we can use middleware, this value should be greater than twice animation time (I tested).
but until the perfect solution is found, perhaps we should give the user (courageous user!!) some hints, not to operate too fast (although this is counter-intuitive).
Edit: this method will delay routing, and prevent the user from continuing the operation during this period.
Just tried with a rc12 deployment and it still ran into the same same issues. Are you sure @IsraelOrtuno?
An unbelievable early Christmas present! 🎁 🎉
@YozhikR @CodeLearningSlayer давайте, пожалуйста, на английском в таких репозиториях. Особенно, когда цель получить помощь или помочь кому-то, вас просто не поймут.
"nuxt": "3.8.1",the problem still exists. (I ve tried most of the solutions above but none of them is really fixed)Temporarily fixed using this(Although it causes flashing on rerenders):
Edit: Added message for firefox
After trying all recommended solutions for quite a while, @lihbr’s seems to be the most stable for my case
Got an E-Mail Notification for every reply here and after 1 year and 4 months it’s finally fixed 🥹
It works on my side i createed a file named router in /plugins then pasth the code and restart your app nuxt: 3.6.0
I had already commented #12735, but the issue was already closed. I hope my experience on this helps to solve this issue.
Nuxt version: ^3.3.2
For me, this error only happens when I have set the page transition mode to ‘out-in’ and I change a page again during a page transition (switch pages fast).
When I set the page transition mode to ‘default’, or disable page transitions, the error is gone.
Transitions are a better UX, but you can develop without them.
I’m going to put up a ticket as an issue for my company and wait until the core problem is resolved, but I want it to be resolved as soon as possible. We want to give our users an experience that exceeds their expectations.
Changing my app.vue content to the above solved it for me. Somehow this solved my problem, I don’t know the reason. Hope it helps you
@genu your solution worked to get rid of the error. but the animations transition page is not working again.
the transition I use is like my reproduction code above.
and it becomes a problem as @olivervorasai explained above, that in his case this problem will arise when he defines the transitions for the page.
Strange hyperlink given above, this one should be better: https://stackoverflow.com/questions/70396414/nuxtlink-is-updating-route-in-nuxt-3-app-but-not-rendering-contents/70404764
@pdahlenburg Nuxt 3.8.2 does not have the latest version of Vue. Please update Vue or wait for a new version of Nuxt.
В моем случае я столкнулся с такими проблемами: Эта ошибка возникает когда в компоненте из хранилища или в самом компоненте я использую
useFetch. Поэтому добавлениеkeyдля ближайшего уровня<NuxtPage>решает мою проблему, но теряется анимация.Поэтому, я использую (костыль?). Я не могу найти точно, где в документации говорится что так делать не рекомендуется.
В моем случае это работает, и вроде бы ничего не ломается.
None of the solutions above worked for me. I got this error on any page calling
useFetch(), and I it also threw a Vue internal scheduler flush issue warning in the console (similar to #22552).After hours of messing around, the only solution that worked was crating a custom RouterLink component and manually disabling it with a timeout to prevent fast navigation. Works for now, but hopefully this gets fixed soon.
CustomNuxtLink.vue
I think it should currently be the default behavior. I made a little change to keep the last intended route so user won’t lose his last click.
I can confirm this still happens, when using page transitions.
updated one of the above reproductions here: https://github.com/vanling/nuxt-3-error-on-fast-navigate
I was not using an
App.vuefile and I was facing this issue when navigating from a page with disabled layout option to a page with layout enabled.https://github.com/nuxt/nuxt.js/issues/14744
I created the
App.vuefile just like this and seems to work:Don’t really know what’s happening here but seems to work.
@genu’s solution is working for me. Thanks. Incase you don’t want to use
app.vue, putting a key in the root element of a layout seems to work.Yeah, i have fully cleared node_modules, .nuxt and package-lock. But seems like the issue is related to mounting algorithm changes, or to some hydration problems. Still figuring out 😕
Still facing this issue while using router.replace with nuxt@3.10.2.
If you can reproduce the issue, then please create a new issue (and feel free to link to this one) @IvanWala Please make sure to include a minimal reproduction though. Saying “I use this and this packages” or dumping the whole project is not a valid repro.
It brings another problem. If you want to add query on your currwnt route, o=full page will be reload
Random unknown issue in console maybe? 😄
Great! I understand the previous answers as confirmation, so I’ll go ahead an close this issue 🎉 If there are related issues please consider opening a new issue or - of course - we can reopen this issue if the issue would in fact turn out to not be resolved after all.
I’m glad I subscribed to this thread!
https://nuxt.com/docs/api/components/nuxt-page#example - тут приведен правильный вариант, потому что использование $route может привести к проблемам с <Suspense>
async requests are highly increasing the chance of this problem occurs. (almost 70%)
Hello, same problem with page transition and when the tab becomes inactive (when I do something else on my PC or on other tabs and then come back to the page).
I had the same problem and based on the article @kissu mentioned, the problem was that I had commented code in the root of the index.vue, so it seems that nuxt understood that it had more than one root node.
This is what works for me. A combo of other peoples work in this thread (thanks all!)
Its not ideal, as I think the messages varies slightly between browser versions.
I found that if this was running on develop then hot reloading no longer worked. So wrapped in the env check.
Unfortunately not. The issue is https://github.com/vuejs/core/issues/8105 (more context: https://github.com/nuxt/nuxt/issues/13350#comment-2175900).
@Sun-ZhenXing I had a similar workaround for that, but users like to use browser navigation and hardware button on mobile so still I was getting a lot of errors.
Currently testing this: https://github.com/nuxt/nuxt/issues/13350#issuecomment-1397297967 . It glitches animations sometimes, but it’s a price I’m willing to pay.
If it doesn’t work then I will add this heavy solution: https://github.com/nuxt/nuxt/issues/13350#issuecomment-1397297690
@madebyfabian There is an upstream bug linked in https://github.com/nuxt/nuxt/issues/13350#issuecomment-1397297522, so as long as this one isn’t fixed it will be a problem.
nuxt is coming release at 3 day, but this bug is not resolved
Also need to add, that such
<NuxtPage :key="$route.fullPath" />workaround broke component reuse. F.e. when you pagination across one component with different data, because it re-render it’s completely. On small examples you don’t see that, but if on something bigger it’s took quite a long time.@viandwi24 So I seem to have found a temporary fix for this. By still using the
:keymethod like @genu suggests but instead wrapping a<Transition>with a keyed div around the<NuxtPage />.Bug still present on latest:
3.0.0-27496606.e43ba6e