From e79ee34c258d6550ad5600e11ef918294c8f41e6 Mon Sep 17 00:00:00 2001 From: Billy Levin Date: Sun, 17 May 2020 20:40:54 +0100 Subject: [PATCH] react to array mutation in each block with static content --- .../compile/render_dom/wrappers/EachBlock.ts | 13 +++++++++++++ .../samples/each-block-static-update/_config.js | 7 +++++++ .../samples/each-block-static-update/main.svelte | 13 +++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 test/runtime/samples/each-block-static-update/_config.js create mode 100644 test/runtime/samples/each-block-static-update/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index 1efadfb90c..f963929625 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -96,6 +96,19 @@ export default class EachBlockWrapper extends Wrapper { bindings: new Map(block.bindings) }); + const reassigned_deps: Set = new Set(); + + block.dependencies.forEach(dep => { + const info = renderer.context_lookup.get(dep); + if (info && info.variable.reassigned) { + reassigned_deps.add(dep); + } + }); + + if (reassigned_deps.size) { + this.block.add_dependencies(reassigned_deps); + } + // TODO this seems messy this.block.has_animation = this.node.has_animation; diff --git a/test/runtime/samples/each-block-static-update/_config.js b/test/runtime/samples/each-block-static-update/_config.js new file mode 100644 index 0000000000..dc1047e99b --- /dev/null +++ b/test/runtime/samples/each-block-static-update/_config.js @@ -0,0 +1,7 @@ +export default { + html: ``, + + test({ assert, target }) { + assert.htmlEqual(target.innerHTML, `staticstatic`); + } +}; diff --git a/test/runtime/samples/each-block-static-update/main.svelte b/test/runtime/samples/each-block-static-update/main.svelte new file mode 100644 index 0000000000..6cbd1e7548 --- /dev/null +++ b/test/runtime/samples/each-block-static-update/main.svelte @@ -0,0 +1,13 @@ + + +{#each arr as num} + static +{/each} \ No newline at end of file