Browser back causing client rendering in nextjs #76147
Unanswered
Hardik3296
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I have a next js project where I have a form using which I fetch some data from backend and display to the user. The displayed data is in the form of a table and the user can click on the table row to go to the detail page.
But when the user presses browser back from the detail page, it comes to the previous page but the user values in the input are gone.
I checked why that is happening and I realised that since the page to fetch the data was a client component, it is getting re rendered (Which as per documentation is default behaviour) when navigated back to, which is resetting the state.
I assumed that since only the current page is being removed from the browser stack the page behind it should just exist and not re-render.
So can I somehow prevent this behaviour or do I need to somehow use the url to send the previous form data back as it needs to be populated with the values that were already entered before pushing in the detail page on top?
One workaround would be to either append values to searchparams or keep in session storage and use them again, but for my use case it may not be always feasible.
This is a little confusing as it is opposite from the standard html behaviour, where the page is just in the browser stack and is shown to the user without any re-rendering
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions