react icon indicating copy to clipboard operation
react copied to clipboard

Bug: `use` function doesn't warn about uncached promise when promise doesn't resolve immediately

Open tomdohnal opened this issue 1 year ago • 8 comments

When I pass an uncached promise that doesn't resolve immediately to the use function, (e. g. use(new Promise(resolve => setTimeout(resolve, 1000)))), I don't get the "A component was suspended by an uncached promise. Creating promises inside a Client Component or hook is not yet supported, except via a Suspense-compatible library or framework." warning.

Instead, I get into an infinite loop as the Promise keeps getting recreated.

(When I use a promise that gets resolved immediately, like use(new Promise(resolve => resolve()), I do get the warning message as expected)

React version: ^19.0.0

Steps To Reproduce

  1. Go to https://codesandbox.io/p/sandbox/modest-merkle-cr7qcn
  2. Open the preview and devtools
  3. See there's no warning message about an uncached promise
  4. See that the "hi from Promise" gets logged indefinitely

Link to code example: https://codesandbox.io/p/sandbox/modest-merkle-cr7qcn

The current behavior

No warning message gets logged

The expected behavior

I get the "A component was suspended by an uncached promise. Creating promises inside a Client Component or hook is not yet supported, except via a Suspense-compatible library or framework." warning regardless of how long the promise passed to the use function takes to resolve.

tomdohnal avatar Dec 15 '24 13:12 tomdohnal

Same here

OhFlohre avatar Dec 26 '24 02:12 OhFlohre

I'm experiencing the same issue with v19.0.0. It works fine with the version used in React's doc (link to codesandbox)

khanghoang avatar Jan 07 '25 18:01 khanghoang

Same issue. Great way to DOS yourself :)

ctnelson1997 avatar Jan 30 '25 22:01 ctnelson1997

Same, instead i'm get the error: An unknown Component is an async Client Component. Only Server Components can be async at the moment. This error is often caused by accidentally adding 'use client' to a module that was originally written for the server.

mmarcmartins avatar May 05 '25 20:05 mmarcmartins

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Aug 03 '25 21:08 github-actions[bot]

Related to this: https://github.com/vercel/next.js/issues/83643#event-19665718686

I have a question: why can't I memo a Promise (created inside a client component) so I can use it? It seems to follow the "rules" defined in "A component was suspended by an uncached promise. Creating promises inside a Client Component or hook is not yet supported, except via a Suspense-compatible library or framework." (Btw I am testing in Next.js [https://codesandbox.io/p/devbox/xw4tmx]). If the caveats of use say we should "prefer" creating them in Server Components, I would love to understand better what exactly the downsides of doing it are.

filipesmedeiros avatar Sep 13 '25 13:09 filipesmedeiros

"react": "^19.1.1", "react-dom": "^19.1.1" same issue

nomanisaisland avatar Oct 23 '25 02:10 nomanisaisland

I opened #36802 with a focused fix for this case. It adds the missing uncached-promise warning before the shell ping-loop guard throws, and includes a regression test for an uncached React.use() promise that resolves in a later task.

ulises-jeremias avatar Jun 16 '26 15:06 ulises-jeremias