Skip to content

Commit 90f9710

Browse files
committed
fix: dont change title when value is undefined (fix #396)
1 parent 4ca3050 commit 90f9710

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

examples/basic/index.html

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<!DOCTYPE html>
2-
<link rel="stylesheet" href="/global.css">
3-
<a href="/">&larr; Examples index</a>
4-
<div id="app"></div>
5-
<script src="/__build__/basic.js"></script>
2+
<html>
3+
<head>
4+
<title>Basic Title</title>
5+
<link rel="stylesheet" href="/global.css">
6+
</head>
7+
<body>
8+
<a href="/">&larr; Examples index</a>
9+
<div id="app"></div>
10+
<script src="/__build__/basic.js"></script>
11+
</body>
12+
</html>

src/client/updaters/title.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
*
44
* @param {String} title - the new title of the document
55
*/
6-
export default function updateTitle(title = document.title) {
6+
export default function updateTitle(title) {
7+
if (title === undefined) {
8+
return
9+
}
10+
711
document.title = title
812
}

src/shared/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// set some sane defaults
66
export const defaultInfo = {
7-
title: '',
7+
title: undefined,
88
titleChunk: '',
99
titleTemplate: '%s',
1010
htmlAttrs: {},

test/unit/components.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('client', () => {
9090

9191
jest.runAllTimers()
9292
metaInfo = getMetaInfo(wrapper.vm.$parent)
93-
expect(metaInfo.title).toEqual('')
93+
expect(metaInfo.title).toEqual(undefined)
9494
})
9595

9696
test('meta-info can be rendered with inject', () => {

test/unit/getMetaInfo.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('getMetaInfo', () => {
1313
const component = new Vue()
1414

1515
expect(getMetaInfo(component)).toEqual({
16-
title: '',
16+
title: undefined,
1717
titleChunk: '',
1818
titleTemplate: '%s',
1919
htmlAttrs: {},
@@ -654,7 +654,7 @@ describe('getMetaInfo', () => {
654654
})
655655

656656
expect(getMetaInfo(component)).toEqual({
657-
title: '',
657+
title: undefined,
658658
titleChunk: '',
659659
titleTemplate: '%s',
660660
htmlAttrs: {},
@@ -802,7 +802,7 @@ describe('getMetaInfo', () => {
802802
})
803803

804804
expect(getMetaInfo(component)).toEqual({
805-
title: '',
805+
title: undefined,
806806
titleChunk: '',
807807
titleTemplate: '%s',
808808
htmlAttrs: {},

0 commit comments

Comments
 (0)