Repository navigation
Make route-loader consumption self-correcting - #666
Conversation
tryConsumeRouteLoaderData mutates route closure state mid-render, so any values a route derived earlier in the same render pass were stale with no follow-up render queued -- the bug class behind the empty secrets list (#664) and the stale /admin/users detail panel. A successful consume now schedules one corrective re-render of the consuming component; the scheduler flushes it in the same microtask (before paint) and consume-once semantics guarantee it cannot loop. Also reorder /admin/users derivations after the apply call (last mis-ordered route), assert the auto-selected detail panel after SPA navigation in the admin RBAC e2e journey, and document the safety net in the request lifecycle notes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe PR adds a corrective re-render mechanism to ChangesCorrective render for route-loader consumption
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
🔎 Preview deployed: https://kody-pr-666.kody-a99.workers.dev Worker: Mocks:
|
Problem
tryConsumeRouteLoaderDataruns mid-render and routes apply the consumed payload by mutating closure state. Any value a route derived before the consume call in the same render pass renders stale — and because the preload was successfully applied, no fallback refetch is queued, so the stale UI persists until the next unrelated update or a full reload. This class caused the empty secrets list (#664) and, still live onmain, a stale/admin/usersdetail panel: after SPA navigation the sidebar auto-highlights the first user but the panel shows "Choose an account from the list..." (and pagination can be hidden).Fix
Eliminate the class at the consumption layer instead of relying on per-route statement ordering:
tryConsumeRouteLoaderDatanow schedules one corrective re-render of the consuming component whenever it returns data (handle.queueTask(() => handle.update())). Theremix/uischeduler flushes queued tasks and the resulting update inside the same microtask-driven flush loop as the current render — before the browser paints — so even a mis-ordered route can no longer show stale derivations. Consume-once semantics guarantee the follow-up pass consumes nothing, so it cannot loop (and the scheduler's cascading-update guard backstops that). On the serverqueueTaskis a no-op, so SSR is unaffected./admin/usersto consume before derivingtotalPages/selectedUser(the last mis-ordered route), keeping "consume first" the primary contract with the framework behavior as safety net./admin/usersit now asserts the auto-selected detail panel actually rendered ("Account metadata only"), which fails without this fix.docs/contributing/architecture/request-lifecycle.md.Evidence
The safety net was verified in isolation: with only the
loader-data-context.tsxchange applied (admin-users still mis-ordered), the/admin/usersdetail panel rendered correctly after SPA navigation, with no visible flash.Before (current
main): stale placeholder panel after clicking Admin in the top nav; correct after F5:After (framework fix only, route untouched):
Final demo — SPA navigation to admin users (twice) and secrets, all populated immediately:
Testing
npm run validate(format, lint, typecheck, 631 unit tests, 10 Playwright e2e incl. the strengthened admin assertion, MCP e2e)/admin/userspanel onmain, verified the framework fix corrects it with the route still mis-ordered, then applied the route reorder and re-verified both admin and secrets pages across repeated client-side navigations.System recap — extends a primitive (medium risk)
Mode: recap · Base:
main@27b28a4c· Head:c9e0bff6Classification: extends — changes the client route-loader consumption contract in
app-ui(successful consumes now schedule a corrective re-render). No primitives added.Primitives touched
app-uitryConsumeRouteLoaderDataself-corrects;/admin/usersrender-order cleanupSystem map
Change flow
Summary by CodeRabbit
Bug Fixes
Documentation