From 6cbe45085c5873dfdede87f6a5c9f9d1c131eb27 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Tue, 14 Feb 2023 10:43:30 +1100 Subject: [PATCH] fix(vue-renderer): insert `charset` before `title` (#18998) --- packages/vue-renderer/src/renderers/spa.js | 12 ++++++++++-- packages/vue-renderer/src/renderers/ssr.js | 9 ++++++++- test/dev/basic.ssr.test.js | 6 ++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/vue-renderer/src/renderers/spa.js b/packages/vue-renderer/src/renderers/spa.js index 196e837491..8bb1a9969f 100644 --- a/packages/vue-renderer/src/renderers/spa.js +++ b/packages/vue-renderer/src/renderers/spa.js @@ -71,10 +71,18 @@ export default class SPARenderer extends BaseRenderer { // BODY_ATTRS meta.BODY_ATTRS = m.bodyAttrs.text() + // charset must come before the title to avoid encoding issues + let metaTags = m.meta.text() + const charset = m.meta.text({ charset: true }) + if (charset) { + meta.HEAD += charset + metaTags = metaTags.replace(charset, '') + } + // HEAD tags - meta.HEAD = + meta.HEAD += m.title.text() + - m.meta.text() + + metaTags + m.link.text() + m.style.text() + m.script.text() + diff --git a/packages/vue-renderer/src/renderers/ssr.js b/packages/vue-renderer/src/renderers/ssr.js index ed7aba75bf..e58b169ebc 100644 --- a/packages/vue-renderer/src/renderers/ssr.js +++ b/packages/vue-renderer/src/renderers/ssr.js @@ -130,7 +130,14 @@ export default class SSRRenderer extends BaseRenderer { }) if (meta) { - HEAD += meta.title.text() + meta.meta.text() + // charset must come before the title to avoid encoding issues + let metaTags = meta.meta.text() + const charset = meta.meta.text({ charset: true }) + if (charset) { + HEAD += charset + metaTags = metaTags.replace(charset, '') + } + HEAD += meta.title.text() + metaTags } // Add meta if router base specified diff --git a/test/dev/basic.ssr.test.js b/test/dev/basic.ssr.test.js index 8cc0a7f7f1..646bafd1bb 100644 --- a/test/dev/basic.ssr.test.js +++ b/test/dev/basic.ssr.test.js @@ -86,6 +86,12 @@ describe('basic ssr', () => { expect(html).toContain('

I can haz meta tags

') expect(html).toContain('