Skip to content

Commit 8fe6cfb

Browse files
committed
🤖 fix: initialize ORPCProvider in connected state when client prop provided
Fixes Storybook tests failing in CI. When a client prop is passed to ORPCProvider, the component now starts in "connected" state immediately instead of waiting for useEffect. This prevents a flash of null content that caused tests to see an empty storybook-root div. Change-Id: I048104e7f2fe434efcf9b50db0bae445d912b014 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent eeaa91d commit 8fe6cfb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

‎src/browser/orpc/react.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,16 @@ function createBrowserClient(authToken: string | null): {
7070
}
7171

7272
export const ORPCProvider = (props: ORPCProviderProps) => {
73-
const [state, setState] = useState<ConnectionState>({ status: "connecting" });
73+
// If client is provided externally, start in connected state immediately
74+
// This avoids a flash of null content on first render
75+
const [state, setState] = useState<ConnectionState>(() => {
76+
if (props.client) {
77+
// Also set the global client reference immediately
78+
window.__ORPC_CLIENT__ = props.client;
79+
return { status: "connected", client: props.client, cleanup: () => undefined };
80+
}
81+
return { status: "connecting" };
82+
});
7483
const [authToken, setAuthToken] = useState<string | null>(() => {
7584
// Check URL param first, then localStorage
7685
const urlParams = new URLSearchParams(window.location.search);

0 commit comments

Comments
 (0)