React 19 Prerendering Bug Causes Duplicate Title and Meta Tags in Static HTML
A developer discovered that prerendered pages built with Vite and React 19 were shipping with multiple duplicate title, meta, and canonical tags in the final HTML files. React 19's new feature of hoisting head elements from anywhere in the component tree into the document head causes stale tags from transitional route components to persist during prerendering. An initial fix that attempted to remove duplicates via DOM manipulation failed silently, because React's reconciler runs after the cleanup and reinserts the deleted nodes before the page is serialized. The root cause is that page.evaluate() and page.content() are separate browser round-trips, giving React time to recommit removed elements between the two calls. The working solution bypasses DOM mutation entirely, instead reading the resolved title and canonical values and applying deduplication as a pure string transformation on the raw HTML output.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in