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

Add default utf-8 charset. #270

Merged
merged 1 commit into from
Nov 17, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ class Head extends React.Component {
}
}

export function defaultHead () {
return [<meta charSet='utf-8' className='next-head' />]
}

function reduceComponents (components) {
return components
.map((c) => c.props.children)
.filter((c) => !!c)
.map((children) => React.Children.toArray(children))
.reduce((a, b) => a.concat(b), [])
.reverse()
.concat(...defaultHead())
.filter(unique())
.reverse()
.map((c) => {
Expand Down
4 changes: 2 additions & 2 deletions server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import read from './read'
import getConfig from './config'
import Router from '../lib/router'
import Document from '../lib/document'
import Head from '../lib/head'
import Head, {defaultHead} from '../lib/head'
import App from '../lib/app'

export async function render (url, ctx = {}, {
Expand All @@ -33,7 +33,7 @@ export async function render (url, ctx = {}, {
return (staticMarkup ? renderToStaticMarkup : renderToString)(app)
})

const head = Head.rewind() || []
const head = Head.rewind() || defaultHead()
Copy link
Contributor Author

@zpnk zpnk Nov 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want to use the default head tag(s) even if the page does not have a <Head>.

const config = await getConfig(dir)

const doc = createElement(Document, {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/basic/pages/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Head from 'next/head'

export default () => <div>
<Head>
<meta charSet='iso-8859-5' />
<meta content='my meta' />
</Head>
<h1>I can haz meta tags</h1>
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test.before(() => build(dir))

test(async t => {
const html = await render('/stateless')
t.true(html.includes('<meta charset="utf-8" class="next-head"/>'))
t.true(html.includes('<h1>My component!</h1>'))
})

Expand All @@ -25,6 +26,7 @@ test(async t => {

test(async t => {
const html = await (render('/head'))
t.true(html.includes('<meta charset="iso-8859-5" class="next-head"/>'))
t.true(html.includes('<meta content="my meta" class="next-head"/>'))
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
})
Expand Down