Skip to content

Commit

Permalink
fix: dont change title when value is undefined (fix #396)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Jun 22, 2019
1 parent 4ca3050 commit 90f9710
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
15 changes: 11 additions & 4 deletions examples/basic/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<!DOCTYPE html>
<link rel="stylesheet" href="/global.css">
<a href="/">&larr; Examples index</a>
<div id="app"></div>
<script src="/__build__/basic.js"></script>
<html>
<head>
<title>Basic Title</title>
<link rel="stylesheet" href="/global.css">
</head>
<body>
<a href="/">&larr; Examples index</a>
<div id="app"></div>
<script src="/__build__/basic.js"></script>
</body>
</html>
6 changes: 5 additions & 1 deletion src/client/updaters/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*
* @param {String} title - the new title of the document
*/
export default function updateTitle(title = document.title) {
export default function updateTitle(title) {
if (title === undefined) {
return
}

document.title = title
}
2 changes: 1 addition & 1 deletion src/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// set some sane defaults
export const defaultInfo = {
title: '',
title: undefined,
titleChunk: '',
titleTemplate: '%s',
htmlAttrs: {},
Expand Down
2 changes: 1 addition & 1 deletion test/unit/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('client', () => {

jest.runAllTimers()
metaInfo = getMetaInfo(wrapper.vm.$parent)
expect(metaInfo.title).toEqual('')
expect(metaInfo.title).toEqual(undefined)
})

test('meta-info can be rendered with inject', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/getMetaInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('getMetaInfo', () => {
const component = new Vue()

expect(getMetaInfo(component)).toEqual({
title: '',
title: undefined,
titleChunk: '',
titleTemplate: '%s',
htmlAttrs: {},
Expand Down Expand Up @@ -654,7 +654,7 @@ describe('getMetaInfo', () => {
})

expect(getMetaInfo(component)).toEqual({
title: '',
title: undefined,
titleChunk: '',
titleTemplate: '%s',
htmlAttrs: {},
Expand Down Expand Up @@ -802,7 +802,7 @@ describe('getMetaInfo', () => {
})

expect(getMetaInfo(component)).toEqual({
title: '',
title: undefined,
titleChunk: '',
titleTemplate: '%s',
htmlAttrs: {},
Expand Down

0 comments on commit 90f9710

Please sign in to comment.