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

[next@12.1.1-canary.17 + react@18.0.0-rc.3] The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering #35564

Closed
1 task done
nghiepdev opened this issue Mar 24, 2022 · 21 comments
Labels
bug Issue was opened via the bug report template.

Comments

@nghiepdev
Copy link
Contributor

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64
Binaries:
  Node: 16.13.1
  npm: 8.1.2
  Yarn: 1.22.18
  pnpm: N/A
Relevant packages:
  next: 12.1.1-canary.17
  react: 18.0.0-rc.3
  react-dom: 18.0.0-rc.3

What browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

next dev

Describe the Bug

The next@12.1.1-canary.17 and react@18.0.0-rc.3 does not work with Suspense mode.

import {lazy, Suspense} from 'react';

const MyComponent = lazy(() => import('../components/MyComponent'));
...
  <Suspense fallback='Loading...'>
      <MyComponent />
   </Suspense>
...

image

Expected Behavior

Just works

To Reproduce

0/ Clone https://github.com/nghiepit/next-12-react-18-rc
1/ yarn install
2/ yarn dev
3/ See error...

Note: The error appears only once, to show the error again we need to restart the server with yarn dev

@nghiepdev nghiepdev added the bug Issue was opened via the bug report template. label Mar 24, 2022
@huozhi
Copy link
Member

huozhi commented Mar 24, 2022

This is because of React.lazy requires using streaming rendering to work the Suspense, next.js will do it soon when detect user is using react 18.

Atm you could add experimental.runtime: 'nodejs' to forces next.js enable streaming rendering to solve this.

@phuwin95
Copy link

phuwin95 commented Mar 25, 2022

@huozhi When I use experimental.runtime: 'nodejs', the page doesn't load, it keeps on loading:
https://www.youtube.com/embed/dErzBwI6DeQ?start=76
I'm using node v15. My dependencies:

    "axios": "^0.26.1",
    "next": "^12.1.0",
    "react": "^18.0.0-rc.3",
    "react-dom": "^18.0.0-rc.3"

@huozhi
Copy link
Member

huozhi commented Mar 25, 2022

@phuwin95 Can you try the canary version? "next": "^12.1.0", seems that you're using the latest stable but current support of react 18 rc >= 2 is on canary

@phuwin95
Copy link

@phuwin95 Can you try the canary version? "next": "^12.1.0", seems that you're using the latest stable but current support of react 18 rc >= 2 is on canary

It works now! Thank you. I'm checking this on the doc and it doesn't mention the canary version of next at all.
https://nextjs.org/docs/advanced-features/react-18/overview#using-react-18-with-nextjs
image

@huozhi
Copy link
Member

huozhi commented Mar 25, 2022

There're few pending changes that about to release soon, might have some mismatch between the online docs with changes. Community folks has filed PR to change that part to next@canary in the doc, it will gets updated in next release.

@nghiepdev
Copy link
Contributor Author

Hey,
React v18.0 was released. Waiting for a PR make Next.js works without manually add experimental.runtime: 'nodejs'

@huozhi
Copy link
Member

huozhi commented Mar 29, 2022

@nghiepit you should be able to achieve it with next@12.1.2, let us know if you have any issue with it.

@harisraharjo
Copy link

harisraharjo commented Apr 2, 2022

Can confirm that this is still an issue on next 12.1.4. In my case I can't load Canvas from react-three-fiber (which is a big component) using next/dynamic with {ssr: false, suspense: true}. But if I tried to load small components, it works.
Edit: It works with React.lazy but not with next/dynamic {ssr: false, suspense: true}

@huozhi
Copy link
Member

huozhi commented Apr 2, 2022

@harisraharjo can you provide a minimal reproduction for this? If you specify suspense: true dynamic component should use React.lazy and ignore the ssr option since it will be SSR'd.

Reflex2468 pushed a commit to Reflex2468/nextjs-suspense-boundary-test that referenced this issue Apr 20, 2022
Reflex2468 pushed a commit to Reflex2468/nextjs-suspense-boundary-test that referenced this issue Apr 20, 2022
@Reflex2468
Copy link

Reflex2468 commented Apr 20, 2022

I'm currently experiencing the same issue when trying to put a <Suspense> around a plot from react-plotly.
I've created a minimal reproduction here: https://github.com/Reflex2468/nextjs-suspense-boundary-test.

I'm not sure if this issue belongs here or in the repository for react-plotly, though.

EDIT: I also made a branch where I have experimental.runtime on nodejs with react@rc and next on the latest canary build.

@flybayer
Copy link
Contributor

flybayer commented May 3, 2022

Since React.lazy is working with latest React and next@canary, I've opened a new issue for dynamic with {suspense: true, ssr: false}

#36636

randreu28 referenced this issue in randreu28/ParticlesShowcase Jun 21, 2022
@tmcw
Copy link
Contributor

tmcw commented Nov 2, 2022

Oddly I'm seeing this bug pop up when I upgrade from 13.0.0 to 13.0.1. I'd love to help out with a better error stacktrace, but it's basically the same as the OP - no real sign of what component or part of the codebase in general is causing this error.

@huozhi
Copy link
Member

huozhi commented Nov 3, 2022

@tmcw can you confirm that if you're seeing it in app/ dir?

@tmcw
Copy link
Contributor

tmcw commented Nov 3, 2022

Yes, in an app/ directory, which I was using before the next 13 release concidentally. I have not set appDir: true in my configuration though, so I think - I assume? - that app/ would not have any of the new experimental behavior?

@huozhi
Copy link
Member

huozhi commented Nov 3, 2022

@tmcw thanks for confirmation, it should work, next/dynamic will behave like React.lazy that ignoring the options when it's being used in app dir.
I filed #42426 that targets to fix that issue for app dir

@tmcw
Copy link
Contributor

tmcw commented Nov 7, 2022

Not sure if the intent was to fix this in 13.0.2, but just tested in 13.0.2 and I can confirm that the issue persists, seeing the same bug.

@huozhi
Copy link
Member

huozhi commented Nov 7, 2022

@tmcw can you provide a reproduction for us to investigate? that would be super helpful 🙏 The comments in this issue are crowded with few different issues, previously I thought your case is breaking with ssr: false, maybe I missed something

@tmcw
Copy link
Contributor

tmcw commented Nov 7, 2022

Sure, I'll give it a shot. This bug is unfortunately really hard to narrow down because the error message has no information, function names, line numbers, etc., so it's pretty much shooting in the dark. I'll try just deleting code until it stops crashing 🤣


Okay, according to the folks working on Blitz, this is a known issue for them that there are incompatibilities with Next 13. Anyway, here's a repro repo, this bug manifests if you just create a new Blitz project and update Next to 13.x. https://github.com/tmcw/next-13-test-result

@huozhi
Copy link
Member

huozhi commented Nov 8, 2022

Gotcha so it's an issue on blitz. I'll close this issue for now since I cannot repro with nextjs as the issue is resolved.

@huozhi huozhi closed this as completed Nov 8, 2022
@flybayer
Copy link
Contributor

flybayer commented Nov 8, 2022

to be clear, this is still an issue with nextjs because nextjs has no way to render a suspense fallback on the server without an error message showing.

Functionally everything works expect for this incorrect error.

In blitz we patch the nextjs reactdom error function to hide this error. We'll update that for nextjs this week, but functionality still works correctly.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

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 Dec 8, 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

No branches or pull requests

7 participants