diff --git a/src/compiler/compile/render_dom/wrappers/shared/Tag.ts b/src/compiler/compile/render_dom/wrappers/shared/Tag.ts index 8d73b0329d..cb5c817834 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/Tag.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/Tag.ts @@ -45,13 +45,17 @@ export default class Tag extends Wrapper { condition = x`!#current || ${condition}`; } - const update_cached_value = x`${value} !== (${value} = ${snippet})`; - if (this.node.should_cache) { - condition = x`${condition} && ${update_cached_value}`; + block.chunks.update.push(b` + if (${condition}) { + if (${value} !== (${value} = ${snippet})) { + ${update(content as Node)} + } + }` + ); + } else { + block.chunks.update.push(b`if (${condition}) ${update(content as Node)}`); } - - block.chunks.update.push(b`if (${condition}) ${update(content as Node)}`); } return { init: content }; diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 02be04c26e..f2b5b0073a 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -56,7 +56,11 @@ function create_each_block(ctx) { insert_dev(target, t1, anchor); }, p: function update(ctx, dirty) { - if (dirty & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[4].name + "")) set_data_dev(t0, t0_value); + if (dirty & /*things*/ 1) { + if (t0_value !== (t0_value = /*thing*/ ctx[4].name + "")) { + set_data_dev(t0, t0_value); + } + } if (dirty & /*foo, bar, baz, things*/ 15) { const foo = /*foo*/ ctx[1]; diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 84dedb0a91..e8e8f5f092 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -53,7 +53,11 @@ function create_each_block(ctx) { insert_dev(target, t1, anchor); }, p: function update(ctx, dirty) { - if (dirty & /*things*/ 1 && t0_value !== (t0_value = /*thing*/ ctx[2].name + "")) set_data_dev(t0, t0_value); + if (dirty & /*things*/ 1) { + if (t0_value !== (t0_value = /*thing*/ ctx[2].name + "")) { + set_data_dev(t0, t0_value); + } + } if (dirty & /*foo*/ 2) { const foo = /*foo*/ ctx[1]; diff --git a/test/js/samples/deconflict-builtins/expected.js b/test/js/samples/deconflict-builtins/expected.js index 8c9bb83b5b..d7a6c8376a 100644 --- a/test/js/samples/deconflict-builtins/expected.js +++ b/test/js/samples/deconflict-builtins/expected.js @@ -36,7 +36,11 @@ function create_each_block(ctx) { append(span, t); }, p(ctx, dirty) { - if (dirty & /*createElement*/ 1 && t_value !== (t_value = /*node*/ ctx[1] + "")) set_data(t, t_value); + if (dirty & /*createElement*/ 1) { + if (t_value !== (t_value = /*node*/ ctx[1] + "")) { + set_data(t, t_value); + } + } }, d(detaching) { if (detaching) detach(span); diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index a94cf7b5f2..46b1702ac9 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -43,7 +43,12 @@ function create_fragment(ctx) { append_dev(p, t2); }, p: function update(ctx, [dirty]) { - if (dirty & /*foo*/ 1 && t0_value !== (t0_value = Math.max(0, /*foo*/ ctx[0]) + "")) set_data_dev(t0, t0_value); + if (dirty & /*foo*/ 1) { + if (t0_value !== (t0_value = Math.max(0, /*foo*/ ctx[0]) + "")) { + set_data_dev(t0, t0_value); + } + } + if (dirty & /*bar*/ 2) set_data_dev(t2, /*bar*/ ctx[1]); }, i: noop, diff --git a/test/js/samples/each-block-array-literal/expected.js b/test/js/samples/each-block-array-literal/expected.js index bb5a04e952..9ad9d9767d 100644 --- a/test/js/samples/each-block-array-literal/expected.js +++ b/test/js/samples/each-block-array-literal/expected.js @@ -36,7 +36,11 @@ function create_each_block(ctx) { append(span, t); }, p(ctx, dirty) { - if (dirty & /*a, b, c, d, e*/ 31 && t_value !== (t_value = /*num*/ ctx[5] + "")) set_data(t, t_value); + if (dirty & /*a, b, c, d, e*/ 31) { + if (t_value !== (t_value = /*num*/ ctx[5] + "")) { + set_data(t, t_value); + } + } }, d(detaching) { if (detaching) detach(span); diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index e91f77ecd8..3460645b15 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -71,9 +71,23 @@ function create_each_block(ctx) { html_tag.m(raw_value, div); }, p(ctx, dirty) { - if (dirty & /*comments*/ 1 && t2_value !== (t2_value = /*comment*/ ctx[4].author + "")) set_data(t2, t2_value); - if (dirty & /*elapsed, comments, time*/ 7 && t4_value !== (t4_value = /*elapsed*/ ctx[1](/*comment*/ ctx[4].time, /*time*/ ctx[2]) + "")) set_data(t4, t4_value); - if (dirty & /*comments*/ 1 && raw_value !== (raw_value = /*comment*/ ctx[4].html + "")) html_tag.p(raw_value); + if (dirty & /*comments*/ 1) { + if (t2_value !== (t2_value = /*comment*/ ctx[4].author + "")) { + set_data(t2, t2_value); + } + } + + if (dirty & /*elapsed, comments, time*/ 7) { + if (t4_value !== (t4_value = /*elapsed*/ ctx[1](/*comment*/ ctx[4].time, /*time*/ ctx[2]) + "")) { + set_data(t4, t4_value); + } + } + + if (dirty & /*comments*/ 1) { + if (raw_value !== (raw_value = /*comment*/ ctx[4].html + "")) { + html_tag.p(raw_value); + } + } }, d(detaching) { if (detaching) detach(div); @@ -170,4 +184,4 @@ class Component extends SvelteComponent { } } -export default Component; +export default Component; \ No newline at end of file diff --git a/test/js/samples/each-block-keyed-animated/expected.js b/test/js/samples/each-block-keyed-animated/expected.js index 6f7c22a086..5936137d08 100644 --- a/test/js/samples/each-block-keyed-animated/expected.js +++ b/test/js/samples/each-block-keyed-animated/expected.js @@ -45,7 +45,12 @@ function create_each_block(key_1, ctx) { }, p(new_ctx, dirty) { ctx = new_ctx; - if (dirty & /*things*/ 1 && t_value !== (t_value = /*thing*/ ctx[1].name + "")) set_data(t, t_value); + + if (dirty & /*things*/ 1) { + if (t_value !== (t_value = /*thing*/ ctx[1].name + "")) { + set_data(t, t_value); + } + } }, r() { rect = div.getBoundingClientRect(); diff --git a/test/js/samples/each-block-keyed/expected.js b/test/js/samples/each-block-keyed/expected.js index a275697d8e..3f29eaeae9 100644 --- a/test/js/samples/each-block-keyed/expected.js +++ b/test/js/samples/each-block-keyed/expected.js @@ -41,7 +41,12 @@ function create_each_block(key_1, ctx) { }, p(new_ctx, dirty) { ctx = new_ctx; - if (dirty & /*things*/ 1 && t_value !== (t_value = /*thing*/ ctx[1].name + "")) set_data(t, t_value); + + if (dirty & /*things*/ 1) { + if (t_value !== (t_value = /*thing*/ ctx[1].name + "")) { + set_data(t, t_value); + } + } }, d(detaching) { if (detaching) detach(div); diff --git a/test/js/samples/instrumentation-script-x-equals-x/expected.js b/test/js/samples/instrumentation-script-x-equals-x/expected.js index ea0d65acb9..dc0c3a4909 100644 --- a/test/js/samples/instrumentation-script-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-script-x-equals-x/expected.js @@ -46,7 +46,11 @@ function create_fragment(ctx) { } }, p(ctx, [dirty]) { - if (dirty & /*things*/ 1 && t3_value !== (t3_value = /*things*/ ctx[0].length + "")) set_data(t3, t3_value); + if (dirty & /*things*/ 1) { + if (t3_value !== (t3_value = /*things*/ ctx[0].length + "")) { + set_data(t3, t3_value); + } + } }, i: noop, o: noop, diff --git a/test/js/samples/instrumentation-template-x-equals-x/expected.js b/test/js/samples/instrumentation-template-x-equals-x/expected.js index 55cd310661..63aaf4aed1 100644 --- a/test/js/samples/instrumentation-template-x-equals-x/expected.js +++ b/test/js/samples/instrumentation-template-x-equals-x/expected.js @@ -46,7 +46,11 @@ function create_fragment(ctx) { } }, p(ctx, [dirty]) { - if (dirty & /*things*/ 1 && t3_value !== (t3_value = /*things*/ ctx[0].length + "")) set_data(t3, t3_value); + if (dirty & /*things*/ 1) { + if (t3_value !== (t3_value = /*things*/ ctx[0].length + "")) { + set_data(t3, t3_value); + } + } }, i: noop, o: noop, diff --git a/test/js/samples/optional-chaining/expected.js b/test/js/samples/optional-chaining/expected.js index 57369ddb72..5310d26edc 100644 --- a/test/js/samples/optional-chaining/expected.js +++ b/test/js/samples/optional-chaining/expected.js @@ -92,12 +92,41 @@ function create_fragment(ctx) { current = true; }, p(ctx, [dirty]) { - if ((!current || dirty & /*a*/ 1) && t0_value !== (t0_value = /*a*/ ctx[0].normal + "")) set_data(t0, t0_value); - if ((!current || dirty & /*b*/ 2) && t1_value !== (t1_value = /*b*/ ctx[1]?.optional + "")) set_data(t1, t1_value); - if ((!current || dirty & /*c*/ 4) && t3_value !== (t3_value = /*c*/ ctx[2]['computed'] + "")) set_data(t3, t3_value); - if ((!current || dirty & /*d*/ 8) && t4_value !== (t4_value = /*d*/ ctx[3]?.['computed_optional'] + "")) set_data(t4, t4_value); - if ((!current || dirty & /*e*/ 16) && t6_value !== (t6_value = /*e*/ ctx[4]() + "")) set_data(t6, t6_value); - if ((!current || dirty & /*f*/ 32) && t7_value !== (t7_value = /*f*/ ctx[5]?.() + "")) set_data(t7, t7_value); + if (!current || dirty & /*a*/ 1) { + if (t0_value !== (t0_value = /*a*/ ctx[0].normal + "")) { + set_data(t0, t0_value); + } + } + + if (!current || dirty & /*b*/ 2) { + if (t1_value !== (t1_value = /*b*/ ctx[1]?.optional + "")) { + set_data(t1, t1_value); + } + } + + if (!current || dirty & /*c*/ 4) { + if (t3_value !== (t3_value = /*c*/ ctx[2]['computed'] + "")) { + set_data(t3, t3_value); + } + } + + if (!current || dirty & /*d*/ 8) { + if (t4_value !== (t4_value = /*d*/ ctx[3]?.['computed_optional'] + "")) { + set_data(t4, t4_value); + } + } + + if (!current || dirty & /*e*/ 16) { + if (t6_value !== (t6_value = /*e*/ ctx[4]() + "")) { + set_data(t6, t6_value); + } + } + + if (!current || dirty & /*f*/ 32) { + if (t7_value !== (t7_value = /*f*/ ctx[5]?.() + "")) { + set_data(t7, t7_value); + } + } if (!current || dirty & /*a*/ 1 && div_a_value !== (div_a_value = /*a*/ ctx[0].normal)) { attr(div, "a", div_a_value);