Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support hydrating around <noscript> #9953

Merged
merged 3 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/smart-zebras-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: support hydrating around `<noscript>`
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,7 @@ function create_block(parent, name, nodes, context) {
context.path,
namespace,
context.state.preserve_whitespace,
context.state.options.preserveComments,
false
context.state.options.preserveComments
);

if (hoisted.length === 0 && trimmed.length === 0) {
Expand Down Expand Up @@ -1821,6 +1820,11 @@ export const template_visitors = {
);
},
RegularElement(node, context) {
if (node.name === 'noscript') {
context.state.template.push('<!>');
return;
}

const metadata = context.state.metadata;
const child_metadata = {
...context.state.metadata,
Expand Down Expand Up @@ -2012,8 +2016,7 @@ export const template_visitors = {
context.path,
child_metadata.namespace,
state.preserve_whitespace,
state.options.preserveComments,
false
state.options.preserveComments
);

for (const node of hoisted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ function create_block(parent, nodes, context, anchor) {
context.path,
namespace,
context.state.preserve_whitespace,
context.state.options.preserveComments,
true
context.state.options.preserveComments
);

if (hoisted.length === 0 && trimmed.length === 0 && !anchor) {
Expand Down Expand Up @@ -1189,8 +1188,7 @@ const template_visitors = {
inner_context.path,
metadata.namespace,
state.preserve_whitespace,
state.options.preserveComments,
true
state.options.preserveComments
);

for (const node of hoisted) {
Expand Down
8 changes: 1 addition & 7 deletions packages/svelte/src/compiler/phases/3-transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,14 @@ export function is_hoistable_function(node) {
* @param {import('#compiler').Namespace} namespace
* @param {boolean} preserve_whitespace
* @param {boolean} preserve_comments
* @param {boolean} preserve_noscript
*/
export function clean_nodes(
parent,
nodes,
path,
namespace = 'html',
preserve_whitespace,
preserve_comments,
preserve_noscript
preserve_comments
) {
/** @type {import('#compiler').SvelteNode[]} */
const hoisted = [];
Expand All @@ -105,10 +103,6 @@ export function clean_nodes(
continue;
}

if (node.type === 'RegularElement' && node.name === 'noscript' && !preserve_noscript) {
continue;
}

if (
node.type === 'ConstTag' ||
node.type === 'DebugTag' ||
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/tests/hydration/samples/noscript/_before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!--ssr:0--><noscript>JavaScript is required for this site.</noscript>
<h1>Hello!</h1><p>Count: 0</p><!--ssr:0-->
9 changes: 9 additions & 0 deletions packages/svelte/tests/hydration/samples/noscript/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import { onMount } from "svelte";
let count = 0;
onMount(() => count++);
</script>

<noscript>JavaScript is required for this site.</noscript>

<h1>Hello!</h1><p>Count: {count}</p>