fix: append data script tags to head during partial navigation#3720
Merged
Conversation
Script tags with non-executable types (e.g. application/ld+json) inside <Head> were silently dropped during partial navigation. This broke SEO structured data when delivered via partials. Now data scripts are appended to document.head, while executable script types (module, text/javascript, importmap) are still skipped to avoid unintended re-execution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Data scripts (e.g. application/ld+json) were appended to document.head on every partial navigation without deduplication, causing duplicates to accumulate. Now scripts with matching type+content or type+id are reused instead of duplicated. Adds browser tests for data script injection and deduplication. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts: # packages/fresh/tests/partials_test.tsx
JSX children inside <script> tags get HTML-escaped by Preact's SSR, breaking JSON.parse on the client. Use dangerouslySetInnerHTML to emit raw JSON content, matching how real apps render structured data. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
<script type="application/ld+json">tags (SEO structured data) inside<Head>were silently dropped during partial navigation due to a// TODOplaceholder in the script handling codedocument.headduring partial applicationWhat changed
In
applyPartials(), theSCRIPTnode handler previously skipped all non-runtime scripts with a TODO comment. Now it appends scripts with non-executable types to the document head.Appended (data scripts, safe to add):
application/ld+json(structured data)application/jsonStill skipped (executable, would cause re-execution):
moduletext/javascriptimportmapTest plan
<Head>containing<script type="application/ld+json">inside a partial should appear indocument.headafter partial navigation🤖 Generated with Claude Code