Fix soft navigation leaving previous route metadata in document.head - #97482
Draft
jasleenkaur-qed42 wants to merge 1 commit into
Draft
Fix soft navigation leaving previous route metadata in document.head#97482jasleenkaur-qed42 wants to merge 1 commit into
jasleenkaur-qed42 wants to merge 1 commit into
Conversation
Remount the deferred head when swapping from the prefetch shell to the final head so hoistable og/twitter meta tags from the previous tree are released.
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
After a client soft navigation to an already-prefetched route, the previous route's resolved metadata (
og:*,twitter:*,description) could stay mounted in<head>next to the new route's tags. Hard loads were always clean. Most visible with cold VercelPRERENDERprefetch responses.Why
HeadusesuseDeferredValueto show the prefetch/shell head first, then the final head. Hoistable metadata is inserted intodocument.headoutside the React tree, so swapping the RSC tree without remounting does not release the old tags.How
Key the deferred head by whether the prefetch or final value is showing, so the prefetch → final transition remounts and clears prior hoistables.
Test plan
HEADLESS=true NEXT_SKIP_ISOLATE=1 pnpm test-start-turbo test/e2e/app-dir/metadata-soft-nav-cache-components/metadata-soft-nav-cache-components.test.ts/→ article while prefetch is cold, assert a singlemeta[property="og:type"]Fixes #97472