Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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/thirty-steaks-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

ignore trailing comments when comparing nodes while invalidating
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/compiler/utils/nodes_match.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script>
export let objectProp;
let count = 0;
$: objectPropCopy = [...objectProp];

$: incrementCount(), console.log('propDependencyChanged', objectProp);
const incrementCount = () => {
count++;
};
const clickAction = () => {
//note that this file shouldn't be formatted and the trailing comment must be rightnext to the variable name
// prettier-ignore
objectPropCopy = objectPropCopy// trailing comment
};
</script>

<button on:click={clickAction}>click me!</button>

{objectPropCopy}
<div id="render-count">{count}</div>
Original file line number Diff line number Diff line change
@@ -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');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import SomeComponent from './SomeComponent.svelte';
let objectProp = ['name', 'age'];

// look in SomeComponent.svelte for explaination
</script>

<SomeComponent {objectProp} />