react / react/react

Bug: Don't crash the app if an async component is accidentally used on the client

Open
#26,801 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Suspense React Core Team
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

We don't yet officially support async/await in client components. (Refer to the RFC for more details: https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md#why-cant-client-components-be-async-functions)

Confusingly, though, it does sometimes work, because the primitives are there to support it in the future.

However, if you accidentally render an async component on the client (for example, when refactoring a Server Component to a client one), React should fail gracefully. Right now, in some cases, it will instead crash the app by falling into an infinite loop.

Let's use this issue to track how we'll improve the DX for preventing async components (and async/await data fetching more generally) on the client.

This is not about implementing support for async/await on the client. Although we will probably do that eventually, for now we're just focused on making it fail more gracefully.

In the meantime, if you're using a Server Components enabled framework like Next.js, you should prefer to do as much data fetching as possible in Server Components. For the remaining client cases, use an established framework like useSWR or React Query.

  • Detect and prevent an infinite loop caused by when uncached promise is rendered outside of a Suspense boundary.
  • Add a warning if an uncached promise is detected outside of a transition.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the client-rendered async component case described in the issue, especially an uncached promise outside a Suspense boundary. Investigate the client rendering path involved in the infinite loop, then verify that the app fails gracefully and that the warning for an uncached promise outside a transition appears as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.