Skip to content

Commit c0a357c

Browse files
authored
fix: support hydrating around <noscript> (#9953)
* add test * fix: support hydrating around `<noscript>` * changeset
1 parent bd34367 commit c0a357c

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

.changeset/smart-zebras-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: support hydrating around `<noscript>`

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,7 @@ function create_block(parent, name, nodes, context) {
10151015
context.path,
10161016
namespace,
10171017
context.state.preserve_whitespace,
1018-
context.state.options.preserveComments,
1019-
false
1018+
context.state.options.preserveComments
10201019
);
10211020

10221021
if (hoisted.length === 0 && trimmed.length === 0) {
@@ -1823,6 +1822,11 @@ export const template_visitors = {
18231822
);
18241823
},
18251824
RegularElement(node, context) {
1825+
if (node.name === 'noscript') {
1826+
context.state.template.push('<!>');
1827+
return;
1828+
}
1829+
18261830
const metadata = context.state.metadata;
18271831
const child_metadata = {
18281832
...context.state.metadata,
@@ -2014,8 +2018,7 @@ export const template_visitors = {
20142018
context.path,
20152019
child_metadata.namespace,
20162020
state.preserve_whitespace,
2017-
state.options.preserveComments,
2018-
false
2021+
state.options.preserveComments
20192022
);
20202023

20212024
for (const node of hoisted) {

packages/svelte/src/compiler/phases/3-transform/server/transform-server.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ function create_block(parent, nodes, context, anchor) {
248248
context.path,
249249
namespace,
250250
context.state.preserve_whitespace,
251-
context.state.options.preserveComments,
252-
true
251+
context.state.options.preserveComments
253252
);
254253

255254
if (hoisted.length === 0 && trimmed.length === 0 && !anchor) {
@@ -1186,8 +1185,7 @@ const template_visitors = {
11861185
inner_context.path,
11871186
metadata.namespace,
11881187
state.preserve_whitespace,
1189-
state.options.preserveComments,
1190-
true
1188+
state.options.preserveComments
11911189
);
11921190

11931191
for (const node of hoisted) {

packages/svelte/src/compiler/phases/3-transform/utils.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@ export function is_hoistable_function(node) {
8383
* @param {import('#compiler').Namespace} namespace
8484
* @param {boolean} preserve_whitespace
8585
* @param {boolean} preserve_comments
86-
* @param {boolean} preserve_noscript
8786
*/
8887
export function clean_nodes(
8988
parent,
9089
nodes,
9190
path,
9291
namespace = 'html',
9392
preserve_whitespace,
94-
preserve_comments,
95-
preserve_noscript
93+
preserve_comments
9694
) {
9795
/** @type {import('#compiler').SvelteNode[]} */
9896
const hoisted = [];
@@ -105,10 +103,6 @@ export function clean_nodes(
105103
continue;
106104
}
107105

108-
if (node.type === 'RegularElement' && node.name === 'noscript' && !preserve_noscript) {
109-
continue;
110-
}
111-
112106
if (
113107
node.type === 'ConstTag' ||
114108
node.type === 'DebugTag' ||
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!--ssr:0--><noscript>JavaScript is required for this site.</noscript>
2+
<h1>Hello!</h1><p>Count: 0</p><!--ssr:0-->
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
import { onMount } from "svelte";
3+
let count = 0;
4+
onMount(() => count++);
5+
</script>
6+
7+
<noscript>JavaScript is required for this site.</noscript>
8+
9+
<h1>Hello!</h1><p>Count: {count}</p>

0 commit comments

Comments
 (0)