From 0b4dc5297729ff3d564338b9e10ee43106277ad8 Mon Sep 17 00:00:00 2001 From: Maximiliano Ruani Date: Thu, 4 Aug 2022 10:59:33 -0300 Subject: [PATCH] - Changed comment style to HEAD_${head_id}_START and HEAD_${head_id}_END - Improved claim logic - Changed tests accordingly --- src/compiler/compile/render_ssr/handlers/Head.ts | 2 +- src/runtime/internal/dom.ts | 15 +++++++++------ .../head-html-and-component/_after_head.html | 8 ++++---- .../head-html-and-component/_before_head.html | 8 ++++---- .../head-meta-hydrate-duplicate/_after_head.html | 4 ++-- .../head-meta-hydrate-duplicate/_before_head.html | 4 ++-- .../{_expected_head.html => _expected-head.html} | 9 ++++----- .../_expected-head.html | 4 ++-- 8 files changed, 28 insertions(+), 26 deletions(-) rename test/server-side-rendering/samples/head-html-and-component/{_expected_head.html => _expected-head.html} (67%) diff --git a/src/compiler/compile/render_ssr/handlers/Head.ts b/src/compiler/compile/render_ssr/handlers/Head.ts index c7b315ae64..f4bb3fa118 100644 --- a/src/compiler/compile/render_ssr/handlers/Head.ts +++ b/src/compiler/compile/render_ssr/handlers/Head.ts @@ -12,5 +12,5 @@ export default function(node: Head, renderer: Renderer, options: RenderOptions) renderer.render(node.children, head_options); const result = renderer.pop(); - renderer.add_expression(x`$$result.head += '' + ${result} + '', ""`); + renderer.add_expression(x`$$result.head += '' + ${result} + '', ""`); } diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 8aacd94856..37d920c6f5 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -645,12 +645,15 @@ export function head_selector(nodeId: string, head: HTMLElement) { let started = 0; for (const node of head.childNodes) { - if (node.nodeType === 8 /* comment node */ && node.textContent.trim() === `HEAD_END data-svelte="${nodeId}"`) { - started -= 1; - result.push(node); - } else if (node.nodeType === 8 /* comment node */ && node.textContent.trim() === `HEAD_START data-svelte="${nodeId}"`) { - started += 1; - result.push(node); + if (node.nodeType === 8 /* comment node */) { + const comment = node.textContent.trim(); + if (comment === `HEAD_${nodeId}_END`) { + started -= 1; + result.push(node); + } else if (comment === `HEAD_${nodeId}_START`) { + started += 1; + result.push(node); + } } else if (started > 0) { result.push(node); } diff --git a/test/hydration/samples/head-html-and-component/_after_head.html b/test/hydration/samples/head-html-and-component/_after_head.html index 0d379ce562..d7f94eda1b 100644 --- a/test/hydration/samples/head-html-and-component/_after_head.html +++ b/test/hydration/samples/head-html-and-component/_after_head.html @@ -1,12 +1,12 @@ - + - + - + - + diff --git a/test/hydration/samples/head-html-and-component/_before_head.html b/test/hydration/samples/head-html-and-component/_before_head.html index 130c18254c..da265f414d 100644 --- a/test/hydration/samples/head-html-and-component/_before_head.html +++ b/test/hydration/samples/head-html-and-component/_before_head.html @@ -1,11 +1,11 @@ - + - + - + - + diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html b/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html index 5e90150217..bdd08c32f5 100644 --- a/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_after_head.html @@ -1,6 +1,6 @@ Some Title - + - + diff --git a/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html b/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html index 5e90150217..bdd08c32f5 100644 --- a/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html +++ b/test/hydration/samples/head-meta-hydrate-duplicate/_before_head.html @@ -1,6 +1,6 @@ Some Title - + - + diff --git a/test/server-side-rendering/samples/head-html-and-component/_expected_head.html b/test/server-side-rendering/samples/head-html-and-component/_expected-head.html similarity index 67% rename from test/server-side-rendering/samples/head-html-and-component/_expected_head.html rename to test/server-side-rendering/samples/head-html-and-component/_expected-head.html index 0d379ce562..da265f414d 100644 --- a/test/server-side-rendering/samples/head-html-and-component/_expected_head.html +++ b/test/server-side-rendering/samples/head-html-and-component/_expected-head.html @@ -1,12 +1,11 @@ - + - + - + - - + diff --git a/test/server-side-rendering/samples/head-meta-hydrate-duplicate/_expected-head.html b/test/server-side-rendering/samples/head-meta-hydrate-duplicate/_expected-head.html index 7a70b2ff46..bdd08c32f5 100644 --- a/test/server-side-rendering/samples/head-meta-hydrate-duplicate/_expected-head.html +++ b/test/server-side-rendering/samples/head-meta-hydrate-duplicate/_expected-head.html @@ -1,6 +1,6 @@ Some Title - + - +