diff --git a/.changeset/unlucky-points-clap.md b/.changeset/unlucky-points-clap.md new file mode 100644 index 0000000000..c53d5cbb80 --- /dev/null +++ b/.changeset/unlucky-points-clap.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ensure nullish expressions render empty text diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js index bd43075e6f..b7ec27f6e3 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js @@ -59,7 +59,13 @@ export function build_template_literal(values, visit, state) { id, create_derived( state, - b.thunk(/** @type {Expression} */ (visit(node.expression, state))) + b.thunk( + b.logical( + '??', + /** @type {Expression} */ (visit(node.expression, state)), + b.literal('') + ) + ) ) ) ); diff --git a/packages/svelte/tests/runtime-runes/samples/text-multiple-nullish-expression/_config.js b/packages/svelte/tests/runtime-runes/samples/text-multiple-nullish-expression/_config.js new file mode 100644 index 0000000000..04d463d117 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/text-multiple-nullish-expression/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: '
' +}); diff --git a/packages/svelte/tests/runtime-runes/samples/text-multiple-nullish-expression/main.svelte b/packages/svelte/tests/runtime-runes/samples/text-multiple-nullish-expression/main.svelte new file mode 100644 index 0000000000..ea67d3e7eb --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/text-multiple-nullish-expression/main.svelte @@ -0,0 +1,4 @@ + +