Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-insects-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: show `:then` block for `null/undefined` value
9 changes: 5 additions & 4 deletions packages/svelte/src/internal/client/dom/blocks/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '../../runtime.js';
import { hydrate_next, hydrate_node, hydrating } from '../hydration.js';
import { queue_micro_task } from '../task.js';
import { UNINITIALIZED } from '../../../../constants.js';

const PENDING = 0;
const THEN = 1;
Expand All @@ -40,8 +41,8 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
/** @type {any} */
var component_function = DEV ? component_context?.function : null;

/** @type {V | Promise<V> | null} */
var input;
/** @type {V | Promise<V> | typeof UNINITIALIZED} */
var input = UNINITIALIZED;

/** @type {Effect | null} */
var pending_effect;
Expand Down Expand Up @@ -156,8 +157,8 @@ export function await_block(node, get_input, pending_fn, then_fn, catch_fn) {
update(THEN, false);
}

// Set the input to null, in order to disable the promise callbacks
return () => (input = null);
// Set the input to something else, in order to disable the promise callbacks
return () => (input = UNINITIALIZED);
});

if (hydrating) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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>`);
}
});
Original file line number Diff line number Diff line change
@@ -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>