Skip to content

fix: append data script tags to head during partial navigation#3720

Merged
bartlomieju merged 5 commits into
mainfrom
fix/partial-head-scripts
Mar 29, 2026
Merged

fix: append data script tags to head during partial navigation#3720
bartlomieju merged 5 commits into
mainfrom
fix/partial-head-scripts

Conversation

@bartlomieju

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Script tags are not being pushed to document when using partials #2805 — "Script tags are not being pushed to document when using partials"
  • <script type="application/ld+json"> tags (SEO structured data) inside <Head> were silently dropped during partial navigation due to a // TODO placeholder in the script handling code
  • Now data scripts are appended to document.head during partial application

What changed

In applyPartials(), the SCRIPT node 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/json
  • Any other non-executable type

Still skipped (executable, would cause re-execution):

  • No type (default JS)
  • module
  • text/javascript
  • importmap

Test plan

  • Lint/format clean
  • Manual test: <Head> containing <script type="application/ld+json"> inside a partial should appear in document.head after partial navigation

🤖 Generated with Claude Code

bartlomieju and others added 4 commits March 28, 2026 09:48
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
@bartlomieju bartlomieju enabled auto-merge (squash) March 29, 2026 19:16
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>
@bartlomieju bartlomieju merged commit 4f82c91 into main Mar 29, 2026
9 checks passed
@bartlomieju bartlomieju deleted the fix/partial-head-scripts branch March 29, 2026 19:29
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.

Script tags are not being pushed to document when using partials

1 participant