fix: coerce nullish `<title>` to empty string

kit-gh-14548
ComputerGuy 9 hours ago
parent e0dba165b4
commit b5faa246f0

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: coerce nullish `<title>` to empty string

@ -12,8 +12,19 @@ export function TitleElement(node, context) {
/** @type {any} */ (node.fragment.nodes),
context
);
const evaluated = context.state.scope.evaluate(value);
const statement = b.stmt(b.assignment('=', b.id('$.document.title'), value));
const statement = b.stmt(
b.assignment(
'=',
b.id('$.document.title'),
evaluated.is_known
? b.literal(evaluated.value)
: evaluated.is_defined
? value
: b.logical('??', value, b.literal(''))
)
);
if (has_state) {
context.state.update.push(statement);

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
test({ assert, target }) {
assert.equal(target.ownerDocument.title, '');
}
});

@ -0,0 +1,6 @@
<script>
const thing = {};
</script>
<svelte:head>
<title>{thing.thing}</title>
</svelte:head>
Loading…
Cancel
Save