Skip to content

Commit

Permalink
React: Run ConvexAuthState as layout effect (#28408)
Browse files Browse the repository at this point in the history
Use `useLayoutEffect` so that the call to `setAuth` runs before any query subscriptions from child components.

GitOrigin-RevId: 999ff5219de51533281c873c232051c5d58441e9
  • Loading branch information
xixixao authored and Convex, Inc. committed Jul 30, 2024
1 parent 93cdba5 commit ae099e3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions npm-packages/convex/src/react/ConvexAuthState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {
createContext,
ReactNode,
useContext,
useEffect,
useLayoutEffect,
useState,
} from "react";
import { AuthTokenFetcher } from "../browser/sync/client.js";
Expand Down Expand Up @@ -89,7 +89,7 @@ export function ConvexProviderWithAuth({
boolean | null
>(null);

useEffect(() => {
useLayoutEffect(() => {
let isThisEffectRelevant = true;
if (isAuthenticated) {
client.setAuth(fetchAccessToken, (isAuthenticated) => {
Expand Down

0 comments on commit ae099e3

Please sign in to comment.