Skip to content

Docs: React 18 + _document.getInitialProps double-render issue #36268

@Andarist

Description

@Andarist

What is the improvement or update you wish to see?

Emotion maintainer here 👋

We got an issue report about a change in behavior with React 18 and Next.js here. I've managed to diagnose this a little bit and it seems that the issue is, at least partially, related to:

  1. hitting a React 18 code branch here that is supposed to render the shell early to the stream
  2. calling the provided _document.getInitialProps later on here

This creates a "double render" of sorts and the first render is not wrapped/enhanced with the Emotion's CacheProvider as that is used in the _document (here).

I've looked through the docs but I'm not sure how to reliably wrap the whole app with a component. Using _document.getInitialProps is recommended by the Material UI team to be compatible with SSG, see here

Is there any context that might help us understand?

No further context, everything was put in the main description of the issue.

Does the docs page already exist? Please link to it.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationRelated to Next.js' official documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions