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

_document.js does not work for React.JS v18 #35711

Closed
1 task done
okisdev opened this issue Mar 30, 2022 · 5 comments · Fixed by #35736
Closed
1 task done

_document.js does not work for React.JS v18 #35711

okisdev opened this issue Mar 30, 2022 · 5 comments · Fixed by #35736
Labels
bug Issue was opened via the bug report template.

Comments

@okisdev
Copy link

okisdev commented Mar 30, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:36:53 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T8101
    Binaries:
      Node: 17.8.0
      npm: 8.5.5
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 12.1.2
      react: 18.0.0
      react-dom: 18.0.0

Describe the Bug

_document.js does not work for React.JS v18

Expected Behavior

_document.js and components such as next/head should work for React.JS v18

To Reproduce

create a basic next.js project and create a _document.js file in /pages.

@okisdev okisdev added the bug Issue was opened via the bug report template. label Mar 30, 2022
@SukkaW
Copy link
Contributor

SukkaW commented Mar 30, 2022

Have you tried react@18 with next@12.1.1?

I have run into a similar issue, and downgrading to next@12.1.1 the issue is gone. I am still comparing the changes to see which change might cause the issue.


Update

The custom _document.js doesn't work on 12.1.2-canary.0, too. So the change that causes the issue is between 12.1.1 and 12.1.2-canary.0.


Update

The change related to the issue is 4f6bb5e.

Custom _document.js (class component + getInitialProps) is not compatible with React 18 Stream SSR at the moment. However, since the commit mentioned above, Next.js now always uses Stream SSR when React 18 is installed, thus causing the issue.

It also means that any feature provided by Next.js that is not yet supported by React 18 (E.g. next/head) will stop working.

@okisdev
Copy link
Author

okisdev commented Mar 30, 2022

Hi @SukkaW

Yes. I have tried to downgrade to next@12.1.1 before, it works, but I don't think this is a long-term solution.

I recognize that the changes between 12.1.1 and 12.1.2-canary.0 caused _document.js to malfunction, as you found.

Looking forward to a further answer & solution to this issue.

@timneutkens
Copy link
Member

We're working on a fix for this issue in #35736. Will be out on stable today 🙏

@kachkaev
Copy link
Contributor

kachkaev commented Mar 30, 2022

Looks like the bug is still there in 12.1.3: #35758. Maybe it’s not the same one, but something quite similar.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants