diff --git a/src/compiler/compile/render-dom/wrappers/Title.ts b/src/compiler/compile/render-dom/wrappers/Title.ts index 75dbc44202..456a833a8f 100644 --- a/src/compiler/compile/render-dom/wrappers/Title.ts +++ b/src/compiler/compile/render-dom/wrappers/Title.ts @@ -91,7 +91,10 @@ export default class TitleWrapper extends Wrapper { ); } } else { - const value = stringify((this.node.children[0] as Text).data); + const value = this.node.children.length > 0 + ? stringify((this.node.children[0] as Text).data) + : '""'; + block.builders.hydrate.add_line(`document.title = ${value};`); } } diff --git a/test/runtime/samples/head-title-empty/_config.js b/test/runtime/samples/head-title-empty/_config.js new file mode 100644 index 0000000000..497855156c --- /dev/null +++ b/test/runtime/samples/head-title-empty/_config.js @@ -0,0 +1,5 @@ +export default { + test({ assert, window }) { + assert.equal(window.document.title, ''); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/head-title-empty/main.svelte b/test/runtime/samples/head-title-empty/main.svelte new file mode 100644 index 0000000000..3f81715df5 --- /dev/null +++ b/test/runtime/samples/head-title-empty/main.svelte @@ -0,0 +1,3 @@ + + + \ No newline at end of file