Repository navigation
fix(ssr,react-ssr,preact-ssr,svelte-ssr): escape head values and the dehydrated snapshot in the rendered html - #239
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #239 +/- ##
==========================================
+ Coverage 83.05% 83.32% +0.26%
==========================================
Files 98 98
Lines 2532 2554 +22
Branches 545 549 +4
==========================================
+ Hits 2103 2128 +25
+ Misses 315 314 -1
+ Partials 114 112 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…dehydrated snapshot in the rendered html The renderers built the document from raw strings: `<title>` (and `lang` / `dir` in the Svelte renderer) were interpolated as is, `headDescriptorToHtml` escaped attribute quotes with a backslash, and `dehydratedScript` inlined the `JSON.stringify` output, so a dehydrated value containing `</script>` closed the tag. `@nano_kit/ssr/renderer` now exports `escapeHtml`, used for head attribute values and titles, and `dehydratedScript` escapes `<` as `\u003c`.
dangreen
force-pushed
the
fix/ssr-html-escaping
branch
from
September 8, 2026 13:12
2a8cfaf to
1581a66
Compare
Merged
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.
Why
The SSR renderers built the document from raw strings:
<title>(andlang/dirin the Svelte renderer) were interpolated as is,headDescriptorToHtmlescaped attribute quotes with a backslash instead of an entity, anddehydratedScriptinlined theJSON.stringifyoutput, so a dehydrated value containing</script>closed the tag and the rest of the value was parsed as markup.What
@nano_kit/ssr/renderer: newescapeHtml(&,<,>,") that returns strings without special characters as is and otherwise scans withcharCodeAt;headDescriptorToHtmluses it for attribute values;dehydratedScriptescapes<as\u003c.langanddir(there the whole document is a template string).escapeHtml, attribute values (static, reactive, empty), rawscriptcode, the</script>case fordehydratedScript, and title escaping in all three adapters (pluslangfor Svelte).oxlint,vitestandtsc --noEmitpass inssr,react-ssr,preact-ssrandsvelte-ssr.