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

metatags are not being populated when I use custom _document #2890

Closed
AvraamMavridis opened this issue Sep 1, 2017 · 4 comments
Closed

metatags are not being populated when I use custom _document #2890

AvraamMavridis opened this issue Sep 1, 2017 · 4 comments

Comments

@AvraamMavridis
Copy link

I created a very simple _document element just to add the lang='en' to the html tag

import Document, { Main, NextScript } from 'next/document';
import React from 'react';
import flush from 'styled-jsx/server';

export default class MyDocument extends Document {

  static getInitialProps ({ renderPage }) {
    const {html, head, errorHtml, chunks} = renderPage()
    const styles = flush()
    return { html, head, errorHtml, chunks, styles }
  }

  render () {
    return (
     <html lang="en">
        <Main />
        <NextScript />
     </html>
    )
  }
}

The problem that I am facing is that the <Head /> is not rendered on the server (if I disable the javascript I see an empty head tag), but it is correctly populated dynamically on the client. Am I missing something or this is a bug?

@timneutkens
Copy link
Member

https://github.com/zeit/next.js#custom-document

You're missing this bit:
import Document, { Head, Main, NextScript } from 'next/document'

<Head />

@AvraamMavridis
Copy link
Author

AvraamMavridis commented Sep 6, 2017

@timneutkens I was using the <Head /> in my <Layout /> component (same as the layout example in the repo) so I wasn't missing it. The head was populated on the client, but not on the server. If I had't include it at all I wouldn't see any head I guess (?)

@timneutkens
Copy link
Member

You literally need to add <Head /> above <Main /> then it'll work, this is the sole reason it's not showing up on the server 😄 this head component is something different than next/head.

@AvraamMavridis
Copy link
Author

@timneutkens I see, thx a lot.

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants