mirror of https://github.com/sveltejs/svelte
fix: show `:then` block for `null` value (#14440)
fixes #14439 This bug was introduced in #13642 because setting the input to null means the equality check ("is the input different") fails if you set the value to null Also fixes #14441 - this bug was present for a long time, and the reason is the same as for the other bug: The equality check always returns "yes this is the same" if the value is undefined initially. The fix is similar; we need to initialize the input to something that can never be equal to whatever value is passedpull/14444/head
parent
9e9fb2463c
commit
3fa08d565c
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: show `:then` block for `null/undefined` value
|
@ -1,9 +1,27 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { ok, test } from '../../test';
|
||||
|
||||
export default test({
|
||||
compileOptions: {
|
||||
dev: true
|
||||
},
|
||||
test() {}
|
||||
test({ assert, target }) {
|
||||
const [btn1, btn2] = target.querySelectorAll('button');
|
||||
const p = target.querySelector('p');
|
||||
ok(p);
|
||||
|
||||
assert.htmlEqual(p.outerHTML, `<p></p>`);
|
||||
|
||||
btn1.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(p.outerHTML, `<p>1</p>`);
|
||||
|
||||
btn2.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(p.outerHTML, `<p></p>`);
|
||||
|
||||
btn1.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(p.outerHTML, `<p>1</p>`);
|
||||
}
|
||||
});
|
||||
|
@ -1,9 +1,14 @@
|
||||
<script>
|
||||
let count = $state(43);
|
||||
let count = $state();
|
||||
</script>
|
||||
|
||||
{#await count}
|
||||
loading
|
||||
{:then count}
|
||||
{count}
|
||||
{/await}
|
||||
<button onclick={() => count = 1}>number</button>
|
||||
<button onclick={() => count = null}>nullify</button>
|
||||
|
||||
<p>
|
||||
{#await count}
|
||||
loading
|
||||
{:then count}
|
||||
{count}
|
||||
{/await}
|
||||
</p>
|
||||
|
Loading…
Reference in new issue