Repository navigation
[web] Gate page tree fetch on auth readiness - #481
2witstudios wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughAdds authentication and hydration awareness to the usePageTree hook. The hook now checks auth state before fetching, gates data loading initiation based on completion of hydration and authentication flows, and extends the loading indicator to reflect these states. Test setup is augmented with hoisted mock auth state for controlled testing. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/src/hooks/__tests__/usePageTree.test.ts (1)
99-108: 🛠️ Refactor suggestion | 🟠 MajorNo tests exercise the auth-gating logic this PR introduces.
All tests set
mockAuthStateto the fully-authenticated happy path. The core behavior change — gating fetches onhasHydrated,isAuthLoading, andisAuthenticated— has zero coverage:
hasHydrated: false→isLoadingshould betrue, SWR key should benull(no fetch).isAuthenticated: false(after hydration) →isLoadingshould befalse, tree should be[].- Transition from not-hydrated to hydrated+authenticated → should trigger fetch.
Since this is the exact bug the PR fixes (infinite skeleton on cold start), at least the first two scenarios should have regression tests.
🧹 Nitpick comments (3)
apps/web/src/hooks/usePageTree.ts (2)
178-178:isLoadinglogic is subtly correct but warrants a clarifying comment.The expression
(!hasHydrated || isAuthLoading || isAuthenticated)serves as "auth not ready OR user is authenticated (so we expect data to come)." When auth completes and the user is not authenticated,isLoadingdrops tofalse— avoiding the infinite skeleton this PR aims to fix. The logic checks out, but a future reader could misreadisAuthenticatedas a bug (why would "authenticated" mean "loading"?).Consider adding a brief inline comment:
Suggested clarification
return { tree: data ?? [], - isLoading: !error && !data && !!driveId && (!hasHydrated || isAuthLoading || isAuthenticated), + // Show loading while auth isn't ready, or while authenticated and waiting for data. + // When auth is ready and user is NOT authenticated, immediately stop loading (no fetch will occur). + isLoading: !error && !data && !!driveId && (!hasHydrated || isAuthLoading || isAuthenticated), isError: error,
85-100: MissingrevalidateOnFocus: falsein SWR config.The SWR options don't include
revalidateOnFocus: false. Per the project guidelines, this should be set for editing protection so that tabbing back into the app doesn't trigger a tree refetch mid-edit. This is pre-existing, so not blocking this PR, but worth noting since you're already touching the SWR configuration surface.Based on learnings: "Use SWR for server state and caching with proper configuration including
revalidateOnFocus: falsefor editing protection".apps/web/src/hooks/__tests__/usePageTree.test.ts (1)
26-30: Consider addingauthFailedPermanentlyto the mock state.The auth store exposes
authFailedPermanently(visible in the relevant snippet fromuseAuthStore.ts). IfusePageTreeor a future consumer ever needs to distinguish "not authenticated" from "auth failed permanently," the mock would need this field. Low priority for now, but noting it since you're defining the mock shape.
Motivation
usePageTreestill initiated SWR fetches too early when session/auth state wasn't ready.Description
usePageTreefetch key on auth readiness by readinghasHydrated,isLoading, andisAuthenticatedfromuseAuthStoreand only setting the SWR key when auth is ready (shouldFetch).isLoadingreturned byusePageTreeto account for auth hydration/loading state so the UI doesn't misinterpret pre-auth state as a permanent fetch failure.usePageTreeto mock the auth store (useAuthStore) and set expected hydrated/auth states inapps/web/src/hooks/__tests__/usePageTree.test.ts.Testing
apps/web/src/hooks/__tests__/usePageTree.test.tsto mockuseAuthStorestate for the new gating logic; tests were modified but not executed as part of this change.Codex Task
Summary by CodeRabbit
Tests
Bug Fixes