Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place 'charset' element at the top of <head> #28119

Merged
merged 3 commits into from Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file modified examples/cms-umbraco-heartcore/.gitignore 100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions packages/next/pages/_document.tsx
Expand Up @@ -684,11 +684,11 @@ export class Head extends Component<
</noscript>
</>
)}
{!isDeferred && getDynamicHeadContent()}

{children}
{optimizeFonts && <meta name="next-font-preconnect" />}

{!isDeferred && getDynamicHeadContent()}

{inAmpMode && (
<>
<meta
Expand Down
25 changes: 25 additions & 0 deletions test/integration/client-navigation/pages/_document.js
@@ -0,0 +1,25 @@
import Document, { Html, Head, Main, NextScript } from 'next/document'

class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}

render() {
return (
<Html>
<Head>
{/* This tag is used to test head-priority */}
<meta name="keywords" content="document head test" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
)
}
}

export default MyDocument
14 changes: 14 additions & 0 deletions test/integration/client-navigation/pages/head-priority.js
@@ -0,0 +1,14 @@
import Head from 'next/head'

export default () => {
return (
<div>
<Head>
<meta charSet="iso-8859-5" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="title" content="head title" />
</Head>
<p>next/head should be placed above the document/head.</p>
</div>
)
}
12 changes: 12 additions & 0 deletions test/integration/client-navigation/test/rendering.js
Expand Up @@ -192,6 +192,18 @@ export default function (render, fetch, ctx) {
expect(html).toContain('<script src="/test-defer.js" defer="">')
})

it('should place charset element at the top of <head>', async () => {
const html = await render('/head-priority')
const nextHeadElement =
'<meta charSet="iso-8859-5"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="title" content="head title"/>'
const nextHeadCountElement = '<meta name="next-head-count" content="3"/>'
const documentHeadElement =
'<meta name="keywords" content="document head test"/>'
expect(html).toContain(
`${nextHeadElement}${nextHeadCountElement}${documentHeadElement}`
)
})

it('should render the page with custom extension', async () => {
const html = await render('/custom-extension')
expect(html).toContain('<div>Hello</div>')
Expand Down