From 24068f630ebd40e419e840212367a542900d8f64 Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 14 Sep 2021 18:05:23 +0800 Subject: [PATCH] [fix] run else-if reactive function on re-renders --- src/compiler/compile/render_dom/wrappers/IfBlock.ts | 2 +- .../if-block-outro-computed-function/Foo.svelte | 1 + .../if-block-outro-computed-function/_config.js | 12 ++++++++++++ .../if-block-outro-computed-function/main.svelte | 13 +++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/if-block-outro-computed-function/Foo.svelte create mode 100644 test/runtime/samples/if-block-outro-computed-function/_config.js create mode 100644 test/runtime/samples/if-block-outro-computed-function/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index 557176bace20..b3bbf9becd77 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -391,7 +391,7 @@ export default class IfBlockWrapper extends Wrapper { ? b` ${snippet && ( dependencies.length > 0 - ? b`if (${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}` + ? b`if (${condition} == null || ${block.renderer.dirty(dependencies)}) ${condition} = !!${snippet}` : b`if (${condition} == null) ${condition} = !!${snippet}` )} if (${condition}) return ${i};` diff --git a/test/runtime/samples/if-block-outro-computed-function/Foo.svelte b/test/runtime/samples/if-block-outro-computed-function/Foo.svelte new file mode 100644 index 000000000000..19102815663d --- /dev/null +++ b/test/runtime/samples/if-block-outro-computed-function/Foo.svelte @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/test/runtime/samples/if-block-outro-computed-function/_config.js b/test/runtime/samples/if-block-outro-computed-function/_config.js new file mode 100644 index 000000000000..69fd95d0085c --- /dev/null +++ b/test/runtime/samples/if-block-outro-computed-function/_config.js @@ -0,0 +1,12 @@ +export default { + props: { + foo: true + }, + + html: 'foo', + + test({ assert, component, target }) { + component.foo = false; + assert.htmlEqual(target.innerHTML, 'bar'); + } +}; diff --git a/test/runtime/samples/if-block-outro-computed-function/main.svelte b/test/runtime/samples/if-block-outro-computed-function/main.svelte new file mode 100644 index 000000000000..adf7cc3e0b8c --- /dev/null +++ b/test/runtime/samples/if-block-outro-computed-function/main.svelte @@ -0,0 +1,13 @@ + + +{#if foo} + +{:else if bar()} + bar +{:else} + else +{/if}