Skip to content

Commit ef56a70

Browse files
tanhauhauConduitry
authored andcommittedJan 13, 2020
SSR should only render one <title> (#4250)
1 parent 7c3e34c commit ef56a70

File tree

9 files changed

+30
-2
lines changed

9 files changed

+30
-2
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fix reactive assignments with destructuring and stores where the destructured value should be undefined ([#4170](https://github.com/sveltejs/svelte/issues/4170))
99
* Fix hydrating `{:else}` in `{#each}` ([#4202](https://github.com/sveltejs/svelte/issues/4202))
1010
* Do not automatically declare variables in reactive declarations when assigning to a member expression ([#4212](https://github.com/sveltejs/svelte/issues/4212))
11+
* Only render one `<title>` in SSR mode when multiple components provide one ([#4250](https://github.com/sveltejs/svelte/pull/4250))
1112

1213
## 3.16.7
1314

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import Renderer, { RenderOptions } from '../Renderer';
22
import Title from '../../nodes/Title';
3+
import { x } from 'code-red';
34

45
export default function(node: Title, renderer: Renderer, options: RenderOptions) {
6+
renderer.push();
7+
58
renderer.add_string(`<title>`);
69

710
renderer.render(node.children, options);
811

912
renderer.add_string(`</title>`);
13+
const result = renderer.pop();
14+
15+
renderer.add_expression(x`($$result.title = ${result}, "")`);
1016
}

‎src/runtime/internal/ssr.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ export function create_ssr_component(fn) {
103103
on_destroy = [];
104104

105105
const result: {
106+
title: string;
106107
head: string;
107108
css: Set<{
108109
map: null;
109110
code: string;
110111
}>;
111-
} = { head: '', css: new Set() };
112+
} = { title: '', head: '', css: new Set() };
112113

113114
const html = $$render(result, props, {}, options);
114115

@@ -120,7 +121,7 @@ export function create_ssr_component(fn) {
120121
code: Array.from(result.css).map(css => css.code).join('\n'),
121122
map: null // TODO
122123
},
123-
head: result.head
124+
head: result.title + result.head
124125
};
125126
},
126127

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<svelte:head>
2+
<title>A</title>
3+
</svelte:head>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<svelte:head>
2+
<title>B</title>
3+
</svelte:head>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<title>B</title>

‎test/server-side-rendering/samples/head-multiple-title/_expected.html

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"adjective": "custom"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
import A from './A.svelte';
3+
import B from './B.svelte';
4+
</script>
5+
6+
<svelte:head>
7+
<title>Main</title>
8+
</svelte:head>
9+
<A />
10+
<B />

0 commit comments

Comments
 (0)
Please sign in to comment.