SSR should only render one <title> (#4250)

pull/4266/head
Tan Li Hau 5 years ago committed by Conduitry
parent 7c3e34c00b
commit ef56a70acb

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

@ -1,10 +1,16 @@
import Renderer, { RenderOptions } from '../Renderer'; import Renderer, { RenderOptions } from '../Renderer';
import Title from '../../nodes/Title'; import Title from '../../nodes/Title';
import { x } from 'code-red';
export default function(node: Title, renderer: Renderer, options: RenderOptions) { export default function(node: Title, renderer: Renderer, options: RenderOptions) {
renderer.push();
renderer.add_string(`<title>`); renderer.add_string(`<title>`);
renderer.render(node.children, options); renderer.render(node.children, options);
renderer.add_string(`</title>`); renderer.add_string(`</title>`);
const result = renderer.pop();
renderer.add_expression(x`($$result.title = ${result}, "")`);
} }

@ -103,12 +103,13 @@ export function create_ssr_component(fn) {
on_destroy = []; on_destroy = [];
const result: { const result: {
title: string;
head: string; head: string;
css: Set<{ css: Set<{
map: null; map: null;
code: string; code: string;
}>; }>;
} = { head: '', css: new Set() }; } = { title: '', head: '', css: new Set() };
const html = $$render(result, props, {}, options); const html = $$render(result, props, {}, options);
@ -120,7 +121,7 @@ export function create_ssr_component(fn) {
code: Array.from(result.css).map(css => css.code).join('\n'), code: Array.from(result.css).map(css => css.code).join('\n'),
map: null // TODO map: null // TODO
}, },
head: result.head head: result.title + result.head
}; };
}, },

@ -0,0 +1,3 @@
<svelte:head>
<title>A</title>
</svelte:head>

@ -0,0 +1,3 @@
<svelte:head>
<title>B</title>
</svelte:head>

@ -0,0 +1,10 @@
<script>
import A from './A.svelte';
import B from './B.svelte';
</script>
<svelte:head>
<title>Main</title>
</svelte:head>
<A />
<B />
Loading…
Cancel
Save