From 94bfeae5d560e229b8add61838ce1804c7d74c90 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 1 May 2021 23:08:30 +0800 Subject: [PATCH] fix claim_text (#6275) --- src/runtime/internal/dom.ts | 2 +- test/hydration/samples/claim-text/Component.svelte | 5 +++++ test/hydration/samples/claim-text/Layout.svelte | 2 ++ test/hydration/samples/claim-text/_after.html | 3 +++ test/hydration/samples/claim-text/_before.html | 5 +++++ test/hydration/samples/claim-text/main.svelte | 8 ++++++++ 6 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/hydration/samples/claim-text/Component.svelte create mode 100644 test/hydration/samples/claim-text/Layout.svelte create mode 100644 test/hydration/samples/claim-text/_after.html create mode 100644 test/hydration/samples/claim-text/_before.html create mode 100644 test/hydration/samples/claim-text/main.svelte diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 03f076df5e..b0cc2c5841 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -216,7 +216,7 @@ export function claim_text(nodes, data) { const node = nodes[i]; if (node.nodeType === 3) { node.data = '' + data; - return nodes.shift(); + return nodes.splice(i, 1)[0]; } } diff --git a/test/hydration/samples/claim-text/Component.svelte b/test/hydration/samples/claim-text/Component.svelte new file mode 100644 index 0000000000..c4a56edceb --- /dev/null +++ b/test/hydration/samples/claim-text/Component.svelte @@ -0,0 +1,5 @@ + + Title + + +
There should be one
diff --git a/test/hydration/samples/claim-text/Layout.svelte b/test/hydration/samples/claim-text/Layout.svelte new file mode 100644 index 0000000000..b37cf18832 --- /dev/null +++ b/test/hydration/samples/claim-text/Layout.svelte @@ -0,0 +1,2 @@ +

This p and the slot below are direct children of the root.

+ diff --git a/test/hydration/samples/claim-text/_after.html b/test/hydration/samples/claim-text/_after.html new file mode 100644 index 0000000000..6f79ed7159 --- /dev/null +++ b/test/hydration/samples/claim-text/_after.html @@ -0,0 +1,3 @@ +

This p and the slot below are direct children of the root.

+ +
There should be one
\ No newline at end of file diff --git a/test/hydration/samples/claim-text/_before.html b/test/hydration/samples/claim-text/_before.html new file mode 100644 index 0000000000..e5653f47fe --- /dev/null +++ b/test/hydration/samples/claim-text/_before.html @@ -0,0 +1,5 @@ +

This p and the slot below are direct children of the root.

+ +
There should be one
+ + \ No newline at end of file diff --git a/test/hydration/samples/claim-text/main.svelte b/test/hydration/samples/claim-text/main.svelte new file mode 100644 index 0000000000..46c001589d --- /dev/null +++ b/test/hydration/samples/claim-text/main.svelte @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file