From 658290546a546c751cf4cb3b282647c75b57c13a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 9 Jun 2019 17:35:36 -0400 Subject: [PATCH] allow empty tags - fixes #2980 (#2988) --- src/compiler/compile/render-dom/wrappers/Title.ts | 5 ++++- test/runtime/samples/head-title-empty/_config.js | 5 +++++ test/runtime/samples/head-title-empty/main.svelte | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/head-title-empty/_config.js create mode 100644 test/runtime/samples/head-title-empty/main.svelte 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 @@ +<svelte:head> + <title> + \ No newline at end of file