-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Navigation issue with Browser Back Button Click #7091
Comments
@ninjawhocodes I can't reproduce the problem, can you post a reproduction repo and the version of your browser |
Thanks @MarchWorks |
https://github.com/ninjawhocodes/react-with-next I have upload the code on above repo. Steps to reproduce the issue :
|
#7091 (comment) |
@timneutkens there is an issue caused by importing css files. I will open a new issue with what I found |
okay so for time being could you please suggest a workaround ? |
@ninjawhocodes use styled-jsx https://github.com/zeit/next.js#built-in-css-support |
@ninjawhocodes personally I will recommend you to use styled-jsx but if you want to use css file then make sure that you are importing one in every page it can be the same or a different one it doesn't matter |
Yeah, I have to add style.css for each page then only it will work. |
@ninjawhocodes you should also know that if you import |
New distinct issue that occurs even without a page refresh: #9989 |
Every time I hit the back button on mobile the site I'm working on loads the page for a second but then the whole page goes blank, and I get the message "An unexpected error occurred." Only happens in mobile (on both Chrome and Safari) but not on desktop. My code: To reproduce it you just visit the site on mobile and then hit the back button on your browser. |
@zachwhitedev I have the same problem. Do you find some solution? |
I have also added shallow to the Link component, as in this example, and the error still appears:
|
I have a similar issue: |
@timneutkens Any update on this? This is a pretty massive issue. Is there an open issue to follow here at least? |
@timneutkens Any update here? |
I have this issue navigating between two static pages. I have to click back twice.
We use a mix of:
Not sure how CSS is causing the issue but wanted to share what we do. I've tried on both v9.4.0 and v9.5.3-canary.27 and v9.5.3 |
We're seeing this issue too - navigating forward works OK but navigating backwards doesn't work. Tested with Next version 9.5.1 and 9.5.3 Also using Chakra, as well as global CSS import. Link (from
Clicking the link once takes me to
Clicking the browser Even weirder, if I click back twice (taking me to the page before I clicked the link, in this case If I refresh the page, I get the content for Does anyone know if there's a workaround, even if it forces a hard reload of the page? After some further investigation, I think this is caused by having a hash in the URL when navigating back. If I remove the hash, the navigation works correctly. |
Upgraded to 9.5.3. Still reproduces for me. Hitting browser's back button results in URL in address bar update, but content on the page remains the same. |
@Spirik can you provide a repo with a reproduction where this is occurring for you? |
I have the same issue. Tried to update to 9.5.3 but it didn't help. |
Will try to recreate the issue with clean install, but not sure, when I'll be able to. The only significant difference with my current setup from clean install is that I don't use CSS modules. And occasionally, I use HOCs with |
@chiqui3d were you able to resolve the back button showing expected error issue? This same problem is killing me here |
@aberba Supposedly it is fixed in the canary version. But I haven't tried it, as what it's doing was for a static website, what I did was to replace the Link component with "a" tag to prevent it, this is only a temporary solution for static pages. |
UPDATE. The issue is fixed for me. It was a bug on our end. We were using The issue was that the page being navigated to was immediately using The page displays a list of items and has filters, so we have code to keep the URL in sync with the filters that the user selects. Well, apparently when the page first loads we did a pushState even when the filters weren't different from the URL. So please double-check the page you are navigating to and be sure you aren't manipulating the history with |
+1 with 9.5.5 |
Still having this issue I've tried 9.5.3-canary.21. I'm also using a hash in my link. I can use normal a tag to fix it but the page reloads, and it doesnt feel like a react website anymore |
Facing the same issue. Any updates or solution? |
Still having an issue here. Any updates? |
The |
I'm still experiencing this issue. Forward and back buttons work as long as I don't refresh, but after a refresh on a page with dynamic content, pressing the back button results in the url updating correctly but the page not rendering the correct page. I'm not getting any errors, either. The page just doesn't re-render with the content for the correct route. |
@cambaughn that sounds related to the page state with dynamic routes, I added a note for this behavior in #26320 does the note added there help with your case? |
@ijjk That makes sense, but in this case it's not an issue of navigating between the same pages with dynamic routes, it's any page at all, I'm finding. I finally solved it, and it turned out to be an issue with some code I had to fix scroll restoration on my app. Here is the code before the fix:
The issue was that I didn't have router.beforePopState returning
|
@ayush-pe this seems to be related |
still have this problem with clicking back after page was reloaded, just nothing changes. |
Same here |
+1 |
Have been facing this problem for long time. Problem still exists after updating from next js version 9 to the latest. it's a pretty major issue. |
Make sure you're using no third party library that messes with your browsers history. Taking care of a clean history fixed it for me. |
This! I had posted what I thought was a force fix, but after walking away from it for a coffee break, I realized it did nothing, so I began to disconnected other libraries, and to my surprise it was the Service Worker I had. It was capturing .json requests and messing up with the back button. Specifically it was MSW, once I turned it off, things worked swell. |
For my solution don't use the component Link of Next switch to using the tag a. hope it helps someone. |
We are having this problem when using Did anyone manage to solve it? |
i solved my problem by finding that router.replace triggers on every page by mistake |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Issue :
I am using "next": "^8.1.0".
The text was updated successfully, but these errors were encountered: