next.js: ⚠ Constent tab crashes when using browser's navigation buttons in soft navigation in app dir - reproduces across projects, envs, browsers and devices
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
---
Which area(s) of Next.js are affected? (leave empty if unsure)
Entire app, it’s a navigation bug
Link to the code that reproduces this issue or a replay of the bug
https://github.com/FearlessSlug/nextjs-app-dir-router-bugs
To Reproduce
TLDR: Soft navigate between the pages and then try to slightly spam the browser’s back button (it has to be the broswer’s navigation buttons!) you will see that the tab freezes and then crashes
I published this nextjs blank project that just has a bunch of different ways to navigate in nextjs app dir, if you soft navigate between the pages (don’t go to the 404 pages because they’ll do full refresh) and then try to slightly spam the browser’s back button you will see that the tab freezes and then crashes, this kind of tab freeze and crash is especialy frequent when using path params hight up in the url, for example when using localization and you need to add /[locale]… to the root of your app directory… I have tested it on multiple browsers and multiple PCs both locally as well as Vercel hosted, it’s consistently crashing and freezing tabs, and keep in mind this is a blank project that has no extra code… Github repo: https://github.com/FearlessSlug/nextjs-app-dir-router-bugs Vercel hosted: https://nextjs-app-dir-router-bugs.vercel.app/test1
Describe the Bug
Tab freeze and crash
Expected Behavior
I expect the tab to not freeze and crash
Which browser are you using? (if relevant)
Brave, Firefox, Safari (iOS), Edge
How are you deploying your application? (if relevant)
Vercel
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 19
- Comments: 25 (5 by maintainers)
Hi @FearlessSlug after wasting almost 1 hour I found that you have used async in page component function (may be by mistake), due to this it is hanging on browser back/forward click. remove async from here: https://github.com/FearlessSlug/nextjs-app-dir-router-bugs/blob/main/src/app/test1/page.tsx#L5
This bug has huge impact on DX I literally cannot develop my app, I get constant tab crashes after every single fast refresh during development, how is this considered stable? The more my code base grows the more unbearable the DX become this is actually insane…
For me, It was because “async” keyword with “use client”. So. I want to know why client components shouldn’t be used with “Async”. I think Async client components should be no problem because async/await is a super common pattern in Javascript world.
First make sure that you are not using async with client components, I think this occurs for some specific cases, if you think this happens for simple navigations, please create new reproduction (with specific reproduction steps) or even a new issue because it looks like no one from team is paying attention to this.
In my use case, I have a fetch function in page.tsx and in some components, it has to be async in my case. Prop drilling is out of question, since I have various component combinations with Storyblok (Headless-CMS) for a relatively large website with multiple pages in two languages.
Is there any “temporary” workaround?
I think this is not such a rare case, that several components have to be async.
Hi, checked quickly & I can confirm that it messes up after you visit any 404 page from async server component & then go back by using browser back button. May be some bug with async server component. But in actual app user won’t visit 404 page by clicking some site button, so I think its less serious than before, but still a bug. will try to find out more later.
Also by looking at docs it seems this is still at RFC stage in React, but Next team has implemented it in advance.
@imaksp So I managed to reproduce the new bug, I pushed the changes to the repo above, I just moved the pages to a
(test-pages)directory for convenience, and the problems occurs for some reason because of the client component page/test1/page.tsxis using the/test1/components/SomeComp.tsxclient component, here’s how to reproduce:/test1you will still see the content of the/test2pageCan confirm, happens for me too when testing the above repo/deployment.