From 951cbcd58593fb633ce81aa4954bd14b7887aab5 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 8 Dec 2018 22:14:34 -0500 Subject: [PATCH] fix dynamic title bug --- src/compile/render-dom/wrappers/Title.ts | 9 +++------ .../samples/head-title-dynamic-simple/_config.js | 12 ++++++++++++ .../samples/head-title-dynamic-simple/main.html | 3 +++ test/store/index.js | 2 +- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 test/runtime/samples/head-title-dynamic-simple/_config.js create mode 100644 test/runtime/samples/head-title-dynamic-simple/main.html diff --git a/src/compile/render-dom/wrappers/Title.ts b/src/compile/render-dom/wrappers/Title.ts index 7baa98073f..aa6268653e 100644 --- a/src/compile/render-dom/wrappers/Title.ts +++ b/src/compile/render-dom/wrappers/Title.ts @@ -4,6 +4,7 @@ import Block from '../Block'; import Title from '../../nodes/Title'; import FragmentWrapper from './Fragment'; import { stringify } from '../../../utils/stringify'; +import addToSet from '../../../utils/addToSet'; export default class TitleWrapper extends Wrapper { node: Title; @@ -32,12 +33,8 @@ export default class TitleWrapper extends Wrapper { if (this.node.children.length === 1) { // single {tag} — may be a non-string const { expression } = this.node.children[0]; - const { dependencies, snippet } = this.node.children[0].expression; - - value = snippet; - dependencies.forEach(d => { - allDependencies.add(d); - }); + value = expression.render(); + addToSet(allDependencies, expression.dynamic_dependencies); } else { // '{foo} {bar}' — treat as string concatenation value = diff --git a/test/runtime/samples/head-title-dynamic-simple/_config.js b/test/runtime/samples/head-title-dynamic-simple/_config.js new file mode 100644 index 0000000000..682a841fcd --- /dev/null +++ b/test/runtime/samples/head-title-dynamic-simple/_config.js @@ -0,0 +1,12 @@ +export default { + props: { + foo: 'A Title' + }, + + test({ assert, component, target, window }) { + assert.equal(window.document.title, 'A Title'); + + component.foo = 'Also A Title'; + assert.equal(window.document.title, 'Also A Title'); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/head-title-dynamic-simple/main.html b/test/runtime/samples/head-title-dynamic-simple/main.html new file mode 100644 index 0000000000..d2ff2c596b --- /dev/null +++ b/test/runtime/samples/head-title-dynamic-simple/main.html @@ -0,0 +1,3 @@ + + {foo} + \ No newline at end of file diff --git a/test/store/index.js b/test/store/index.js index 4bcae173ef..355cea4442 100644 --- a/test/store/index.js +++ b/test/store/index.js @@ -1,7 +1,7 @@ import * as assert from 'assert'; import { readable, writable, derive } from '../../store.js'; -describe.only('store', () => { +describe('store', () => { describe('writable', () => { it('creates a writable store', () => { const count = writable(0);