question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suspended component during server rendering blocks request instead of using fallback. v12.1.2+

See original GitHub issue

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.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000
Binaries:
  Node: 16.14.2
  npm: 8.1.4
  Yarn: 1.22.1
  pnpm: 6.32.4
Relevant packages:
  next: 12.1.6-canary.12
  react: 18.1.0
  react-dom: 18.1.0

Describe the Bug

Prior to Next.js v12.1.2, throwing a promise during server rendering that never resolves resulted in the suspense fallback being rendered on the server. But now that results in the request never completing and next build never resolving.

All users of react-query + suspense, including all Blitz.js based apps, rely on that previous behavior. In the case of react-query, you usually want client-side data fetching, so you need the suspense fallback loading screen to be rendered on the server. Then on the client, the suspense fallback will continue to render until the data is loaded client side.

This is the PR that changed this: https://github.com/vercel/next.js/pull/35490

Expected Behavior

I’m not sure if this new behavior is a bug or is intended with the new streaming rendering things.

Either way, it’s critical for us to have a way to opt into the previous behavior. One idea is a special flag to set on the thrown promise that would tell next.js/react to immediately render the fallback.

Example

const promise = new Promise(()=>{})
promise.reactForceFallback = true
throw promise

To Reproduce

Demo with latest nextjs version. The page never renders because it’s stuck in server rendering. https://codesandbox.io/s/divine-glitter-n07pnb?file=/pages/index.js

import { Suspense } from "react";

function Thing() {
  if (typeof window === "undefined") {
    throw new Promise(() => {});
  }
  return "Thing";
}

export default function IndexPage() {
  return (
    <div>
      <p>Next.js Example</p>
      <Suspense fallback="Loading...">
        <Thing />
      </Suspense>
    </div>
  );
}

Update: Throwing an error on the server instead of a promise causes the fallback to be rendered correctly, but then we get a flash of unstyled content on the client

import { Suspense } from "react";

function Thing() {
  if (typeof window === "undefined") {
    const e = new Error()
    e.name = "Rendering Suspense fallback..."
    delete e.stack
    throw e
  }
  return "Thing";
}

export default function IndexPage() {
  return (
    <div>
      <p>Next.js Example</p>
      <Suspense fallback="Loading...">
        <Thing />
      </Suspense>
    </div>
  );
}

If you downgrade nextjs to 12.1.1, then you’ll see the loading indicator flash before the “Thing” text is rendered.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
flybayercommented, May 7, 2022

I talked with @acdlite this week and they are adding an API to React within 2-3 weeks for forcing rendering of suspense fallback on the server without throwing an error. This will the proper solution to my original need.

0reactions
github-actions[bot]commented, Jun 7, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A React component suspended while rendering, but no ...
It was using <Suspense /> element in the component but I removed it. Then application is crashed with above error. Is there any...
Read more >
All You Need To Know About React Suspense - CopyCat Blog
It suspends the component from rendering until the required data is obtained and provides a fallback UI during the fetch duration.
Read more >
Loading States with Suspense - Relay
Suspense is a new feature in React that allows components to interrupt or "suspend" rendering in order to wait for some asynchronous ...
Read more >
Changelog - Cypress Documentation
Fixed an issue with Angular Component Testing where urls within SASS/SCSS ... In Cypress v12, the testIsolation configuration values have changed from on...
Read more >
Supplemental Document: BIG-IP 15.1.2 Fixes and Known Issues
The Georedundancy traps introduced in 15.0.1.2 with trap IDs in the F5 ... APM virtual server user's GUI (e.g., 'Logon page') cannot be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found