Skip to content

Commit

Permalink
[fix] duplicate meta tags during hydration (#7941)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored Oct 14, 2022
1 parent bb83edd commit e8b4997
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/compiler/compile/render_ssr/handlers/Head.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Renderer, { RenderOptions } from '../Renderer';
import Head from '../../nodes/Head';
import { x } from 'code-red';
import { Node } from 'estree';

export default function(node: Head, renderer: Renderer, options: RenderOptions) {
const head_options = {
Expand All @@ -11,6 +12,12 @@ export default function(node: Head, renderer: Renderer, options: RenderOptions)
renderer.push();
renderer.render(node.children, head_options);
const result = renderer.pop();
let expression: Node = result;
if (options.hydratable) {
const start_comment = `HEAD_${node.id}_START`;
const end_comment = `HEAD_${node.id}_END`;
expression = x`'<!-- ${start_comment} -->' + ${expression} + '<!-- ${end_comment} -->'`;
}

renderer.add_expression(x`$$result.head += '<!-- HEAD_${node.id}_START -->' + ${result} + '<!-- HEAD_${node.id}_END -->', ""`);
renderer.add_expression(x`$$result.head += ${expression}, ""`);
}
4 changes: 3 additions & 1 deletion test/server-side-rendering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ describe('ssr', () => {
fs.writeFileSync(`${dir}/_actual-head.html`, head);

try {
assert.htmlEqual(
(compileOptions.hydratable
? assert.htmlEqualWithComments
: assert.htmlEqual)(
head,
fs.readFileSync(`${dir}/_expected-head.html`, 'utf-8')
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
compileOptions: {
hydratable: true
}
},
withoutNormalizeHtml: true
};

0 comments on commit e8b4997

Please sign in to comment.