Skip to content
Source
Sign inSign up
TanStack/router

`createServerComponentFromStream`: `getTree` skips `use()` after decoding, triggering React 19's "conditional use()" warning #8725

Closedhavalex(GitHub profile, opens in a new tab) opened this issue 0 comments

Which project does this relate to?

Start (@tanstack/react-start-rsc 0.1.63, @tanstack/react-start 1.169.2, React 19.3.0)

Describe the bug

In setupStreamDecode (createServerComponentFromStream.ts), the tree getter calls use() only while the Flight stream is still decoding:

const getTree = () => {
  if (cacheReady) return cachedTree;
  return use(startDecode());
};

When a component that renders the RSC proxy suspends through that use(), and the decode finishes before React retries the render, the retry takes the cacheReady branch and does not call use(). React 19 logs:

This library called use() to suspend in a previous render but did not call use() when it finished.

It is the same pattern as #8487 (lazyRouteComponent). We see it on client navigations to a page whose RSC payload streams in after the first render attempt.

Expected behavior

No warning: the getter calls use() on every render, and a decoded tree never suspends.

Proposed fix

Mark the decode promise fulfilled when it settles, so use() returns synchronously, and always call it:

         cachedTree = unwrapRscCssEnvelope(result);
         cacheReady = true;
+        transformedTreePromise.status = "fulfilled";
+        transformedTreePromise.value = cachedTree;
         return cachedTree;
@@
-  const getTree = () => {
-    if (cacheReady) return cachedTree;
-    return use(startDecode());
-  };
+  const getTree = () => use(startDecode());

use() reads status/value from a thenable it has not tracked yet, so a tree decoded before its first render does not suspend either. We run this as a local patch in production. Happy to open a PR (cacheReady / cachedTree could then go).

Sign in to join this conversation.