Repository navigation
Dashboard: show new forms after Back without a reload - #14
Merged
Merged
Conversation
Next.js restores its saved copy of a page on Back/Forward (browser, or the phone's back button in the app), from before any change: a form created in the builder was missing from the dashboard until a reload. Now every Back/Forward shows the saved page instantly and then fetches the fresh one. The refresh is queued after Next.js handles the same popstate, because it can show the saved page synchronously.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
components/nav-progress.tsx(already on every page) now listens forpopstateand callsrouter.refresh()right after Next.js has handled it.Why
#13 set
staleTimes.dynamic = 0, which fixed link clicks, but Next.js 14 always restores Back/Forward from its client router cache. Creating a form from the dashboard and then pressing Back (browser or the Android app's back button) showed the dashboard from before the form existed until a full reload.The refresh is queued with
setTimeout(…, 0): when the cached tree is available, Next.js renders the restored page synchronously inside the samepopstateevent, so a flag read in an effect was too late.Testing
tsc --noEmitpasses.history.back(). Before: dashboard showed 4 forms, the new one missing. After: the new form appears within ~250 ms. Link-click path unchanged.