From 96326db9626b01a6a45461df9d45f0e624399996 Mon Sep 17 00:00:00 2001
From: Bjorn Lu <34116392+bluwy@users.noreply.github.com>
Date: Thu, 16 Sep 2021 04:23:41 +0800
Subject: [PATCH] [fix] run else-if reactive function on re-renders (#6727)
---
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 557176bace..b3bbf9becd 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 0000000000..1910281566
--- /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 0000000000..69fd95d008
--- /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 0000000000..adf7cc3e0b
--- /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}