fix: coerce symbols to empty string in set_text

Under experimental.async, $bindable can surface Symbol(UNINITIALIZED).
set_text previously passed symbols through and threw when setting nodeValue.
pull/18650/head
asphum 4 weeks ago
parent c0987c09f8
commit fa226778b0

@ -0,0 +1,9 @@
---
'svelte': patch
---
fix: coerce symbols to empty string in `set_text`
Under `experimental.async`, `$bindable` props can briefly surface `Symbol(UNINITIALIZED)`.
`set_text` treated symbols as already-stringifiable values, then threw when assigning
`text.nodeValue = \`${str}\``. Treat symbols like nullish values so text nodes stay stable.

@ -45,7 +45,7 @@ export function set_should_intro(value) {
*/ */
export function set_text(text, value) { export function set_text(text, value) {
// For objects, we apply string coercion (which might make things like $state array references in the template reactive) before diffing // For objects, we apply string coercion (which might make things like $state array references in the template reactive) before diffing
var str = value == null ? '' : typeof value === 'object' ? `${value}` : value; var str = value == null || typeof value === 'symbol' ? '' : typeof value === 'object' ? `${value}` : value;
// prettier-ignore // prettier-ignore
if (str !== (/** @type {any} */ (text)[TEXT_CACHE] ??= text.nodeValue)) { if (str !== (/** @type {any} */ (text)[TEXT_CACHE] ??= text.nodeValue)) {
/** @type {any} */ (text)[TEXT_CACHE] = str; /** @type {any} */ (text)[TEXT_CACHE] = str;

Loading…
Cancel
Save