From 8cb5ab93090e6df417d993e0fc4278cefd1b8bf0 Mon Sep 17 00:00:00 2001 From: Sina Salahshour Date: Wed, 13 Sep 2023 00:06:21 +0330 Subject: [PATCH 1/5] fix: ignore comments while comparing nodes in node_match --- .../svelte/src/compiler/compile/render_dom/invalidate.js | 2 +- packages/svelte/src/compiler/utils/nodes_match.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/svelte/src/compiler/compile/render_dom/invalidate.js b/packages/svelte/src/compiler/compile/render_dom/invalidate.js index 83423e952bc3..624893f098b6 100644 --- a/packages/svelte/src/compiler/compile/render_dom/invalidate.js +++ b/packages/svelte/src/compiler/compile/render_dom/invalidate.js @@ -50,7 +50,7 @@ export function invalidate(renderer, scope, node, names, main_execution_context if ( node.type === 'AssignmentExpression' && node.operator === '=' && - nodes_match(node.left, node.right) && + nodes_match(node.left, node.right, ["trailingComments","leadingComments"]) && tail.length === 0 ) { return get_invalidated(head, node); diff --git a/packages/svelte/src/compiler/utils/nodes_match.js b/packages/svelte/src/compiler/utils/nodes_match.js index ff841d5f02f7..2337416f0eed 100644 --- a/packages/svelte/src/compiler/utils/nodes_match.js +++ b/packages/svelte/src/compiler/utils/nodes_match.js @@ -1,4 +1,4 @@ -export function nodes_match(a, b) { +export function nodes_match(a, b, ignoreKeys=[]) { if (!!a !== !!b) return false; if (Array.isArray(a) !== Array.isArray(b)) return false; @@ -8,8 +8,8 @@ export function nodes_match(a, b) { return a.every((child, i) => nodes_match(child, b[i])); } - const a_keys = Object.keys(a).sort(); - const b_keys = Object.keys(b).sort(); + const a_keys = Object.keys(a).sort().filter(key => !ignoreKeys.includes(key)); + const b_keys = Object.keys(b).sort().filter(key => !ignoreKeys.includes(key)); if (a_keys.length !== b_keys.length) return false; From 53918bbd0adef9e896dec563161b05b8f143801c Mon Sep 17 00:00:00 2001 From: Sina Salahshour Date: Wed, 20 Sep 2023 12:37:41 +0330 Subject: [PATCH 2/5] chore: use change double quote to single quote --- packages/svelte/src/compiler/compile/render_dom/invalidate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/compiler/compile/render_dom/invalidate.js b/packages/svelte/src/compiler/compile/render_dom/invalidate.js index 624893f098b6..a007d1af7dbd 100644 --- a/packages/svelte/src/compiler/compile/render_dom/invalidate.js +++ b/packages/svelte/src/compiler/compile/render_dom/invalidate.js @@ -50,7 +50,7 @@ export function invalidate(renderer, scope, node, names, main_execution_context if ( node.type === 'AssignmentExpression' && node.operator === '=' && - nodes_match(node.left, node.right, ["trailingComments","leadingComments"]) && + nodes_match(node.left, node.right, ['trailingComments','leadingComments']) && tail.length === 0 ) { return get_invalidated(head, node); From 811132a098db0ec575a77e40b5fcf0f8a2b792dc Mon Sep 17 00:00:00 2001 From: Sina Salahshour Date: Wed, 20 Sep 2023 12:38:01 +0330 Subject: [PATCH 3/5] fix: add test for node-match trailing comment problem --- .../SomeComponent.svelte | 20 +++++++++++++++++++ .../comment-effect-on-reactivity/_config.js | 9 +++++++++ .../comment-effect-on-reactivity/main.svelte | 8 ++++++++ 3 files changed, 37 insertions(+) create mode 100644 packages/svelte/test/runtime/samples/comment-effect-on-reactivity/SomeComponent.svelte create mode 100644 packages/svelte/test/runtime/samples/comment-effect-on-reactivity/_config.js create mode 100644 packages/svelte/test/runtime/samples/comment-effect-on-reactivity/main.svelte diff --git a/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/SomeComponent.svelte b/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/SomeComponent.svelte new file mode 100644 index 000000000000..5c7f400318a2 --- /dev/null +++ b/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/SomeComponent.svelte @@ -0,0 +1,20 @@ + + + + +{objectPropCopy} +
{count}
diff --git a/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/_config.js b/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/_config.js new file mode 100644 index 000000000000..d1b7d61dcc8d --- /dev/null +++ b/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/_config.js @@ -0,0 +1,9 @@ +export default { + async test({ assert, target, window }) { + const incrementButton = target.querySelector('button'); + + assert.equal(target.querySelector('#render-count').innerHTML, '1'); + await incrementButton.dispatchEvent(new window.MouseEvent('click')); + assert.equal(target.querySelector('#render-count').innerHTML, '2'); + } +}; diff --git a/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/main.svelte b/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/main.svelte new file mode 100644 index 000000000000..6d1985392a4d --- /dev/null +++ b/packages/svelte/test/runtime/samples/comment-effect-on-reactivity/main.svelte @@ -0,0 +1,8 @@ + + + From 7c92f0f3b094085c2df8ac45e4dd309def5dead4 Mon Sep 17 00:00:00 2001 From: Sina Salahshour Date: Wed, 20 Sep 2023 13:36:04 +0330 Subject: [PATCH 4/5] chore add changeset for node-match trailing comment problem --- .changeset/thirty-steaks-dream.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/thirty-steaks-dream.md diff --git a/.changeset/thirty-steaks-dream.md b/.changeset/thirty-steaks-dream.md new file mode 100644 index 000000000000..645ced1b9c1e --- /dev/null +++ b/.changeset/thirty-steaks-dream.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +ignore trailing comments when comparing nodes while invalidating From 4093a59c2e091fd7ba1c02460b981d9372469b4e Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 19 Oct 2023 10:27:42 +0200 Subject: [PATCH 5/5] Update .changeset/thirty-steaks-dream.md --- .changeset/thirty-steaks-dream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/thirty-steaks-dream.md b/.changeset/thirty-steaks-dream.md index 645ced1b9c1e..a14677bad7d1 100644 --- a/.changeset/thirty-steaks-dream.md +++ b/.changeset/thirty-steaks-dream.md @@ -2,4 +2,4 @@ 'svelte': patch --- -ignore trailing comments when comparing nodes while invalidating +fix: ignore trailing comments when comparing nodes