Skip to content

Fix soft navigation leaving previous route metadata in document.head - #97482

Draft
jasleenkaur-qed42 wants to merge 1 commit into
vercel:canaryfrom
jasleenkaur-qed42:fix/soft-nav-duplicate-metadata
Draft

Fix soft navigation leaving previous route metadata in document.head#97482
jasleenkaur-qed42 wants to merge 1 commit into
vercel:canaryfrom
jasleenkaur-qed42:fix/soft-nav-duplicate-metadata

Conversation

@jasleenkaur-qed42

Copy link
Copy Markdown

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 Vercel PRERENDER prefetch responses.

Why

Head uses useDeferredValue to show the prefetch/shell head first, then the final head. Hoistable metadata is inserted into document.head outside 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

Fixes #97472

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Soft navigation leaves the previous route's metadata mounted in head (duplicate og/twitter tags) on Vercel with 16.3

1 participant