Replies: 4 comments
-
Hey! I ran into something very similar when testing Suspense in React 19. Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Hi! What you’re observing is actually expected behavior in React’s Suspense mechanism, especially in React 18 and beyond (including React 19.1.0). Why does MyComponent render twice even though it throws a never-resolving promise? Here’s why you see the double rendering: Initial Render Attempt: React calls MyComponent, which throws a Promise. Suspense Handling: React catches that Promise and triggers the Suspense fallback. Re-render Attempt: React tries rendering again to prepare the fallback UI (or to check if anything else can be rendered). Because the Promise never resolves, it still throws. This results in the component function being called multiple times even though it never commits. Important points: In the render phase, React can call your components multiple times to figure out what the UI should look like. Suspense’s fallback UI is only committed after React settles on the render tree. Because your promise never resolves, React never commits the fallback UI, but still tries rendering the component multiple times internally. How to verify this: The multiple calls you see are during rendering, which React can repeat several times for correctness and performance reasons. TL;DR React’s Suspense mechanism can call component functions multiple times before committing fallback UI. This is part of React’s concurrent rendering and is normal behavior. |
Beta Was this translation helpful? Give feedback.
-
Hi! You're running into a subtle yet expected behavior of React Suspense. Even though you're not using Here's what's happening:
This doesn't happen in production builds the same way. Why does React do this?While React shouldn't retry rendering for a permanently suspended component (like yours), it may still re-render once more to confirm the suspension and possibly cache the thrown promise in the internal fiber tree. Also, as of React 18+, ✅ Recommendation:If you want to verify the "true" runtime behavior:
So yes — what you're seeing is expected in development, and not necessarily a bug. Let me know if you'd like a deeper dive into how React handles thrown promises internally in the fiber tree! |
Beta Was this translation helpful? Give feedback.
-
Thanks to everyone who responded! This issue occurs in both production and development modes. My expectation is that once an exception is thrown, React would discard any Suspense children and render only the fallback component on subsequent renders. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I ran into something a bit unexpected while playing around with Suspense in React 19.1.0 (using Vite 6.3.5, no StrictMode).
Here’s the example:
When I run this, I see "MyComponent" logged twice, even though the component throws a never resolving promise right away.
My understanding was that React would try to render
MyComponent
, see the thrown promise, and immediately switch to the fallback without trying to renderMyComponent
again (since the promise never resolves). So I’m not sure why the component renders twice.Is this expected behavior with Suspense?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions