mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
fix(vue-renderer): insert charset
before title
(#18998)
This commit is contained in:
parent
b0b90ca2ea
commit
6cbe45085c
@ -71,10 +71,18 @@ export default class SPARenderer extends BaseRenderer {
|
|||||||
// BODY_ATTRS
|
// BODY_ATTRS
|
||||||
meta.BODY_ATTRS = m.bodyAttrs.text()
|
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
|
// HEAD tags
|
||||||
meta.HEAD =
|
meta.HEAD +=
|
||||||
m.title.text() +
|
m.title.text() +
|
||||||
m.meta.text() +
|
metaTags +
|
||||||
m.link.text() +
|
m.link.text() +
|
||||||
m.style.text() +
|
m.style.text() +
|
||||||
m.script.text() +
|
m.script.text() +
|
||||||
|
@ -130,7 +130,14 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (meta) {
|
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 <base href=""> meta if router base specified
|
// Add <base href=""> meta if router base specified
|
||||||
|
@ -86,6 +86,12 @@ describe('basic ssr', () => {
|
|||||||
expect(html).toContain('<div><h1>I can haz meta tags</h1></div>')
|
expect(html).toContain('<div><h1>I can haz meta tags</h1></div>')
|
||||||
expect(html).toContain('<script data-n-head="ssr" src="/body.js" data-body="true">')
|
expect(html).toContain('<script data-n-head="ssr" src="/body.js" data-body="true">')
|
||||||
|
|
||||||
|
// charset should be before title
|
||||||
|
const charset = html.indexOf('<meta data-n-head="ssr" charset="utf-8">')
|
||||||
|
const title = html.indexOf('<title>My title - Nuxt</title>')
|
||||||
|
expect(charset).toBeLessThan(title)
|
||||||
|
expect(charset).toBeGreaterThan(0)
|
||||||
|
|
||||||
const metas = window.document.getElementsByTagName('meta')
|
const metas = window.document.getElementsByTagName('meta')
|
||||||
expect(metas[1].getAttribute('content')).toBe('my meta')
|
expect(metas[1].getAttribute('content')).toBe('my meta')
|
||||||
expect(consola.log).toHaveBeenCalledWith('Body script!')
|
expect(consola.log).toHaveBeenCalledWith('Body script!')
|
||||||
|
Loading…
Reference in New Issue
Block a user