Convert route guards to React Router v8 middleware#11780
Open
nbudin wants to merge 6 commits into
Open
Conversation
Single-event conventions redirect /admin_events to /:eventId/edit, but that path had no matching route — only the multi-event paths existed under the siteMode !== SingleEvent guard. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Extract RouteErrorBoundary to its own module for reuse - Convert AppRoot from a static element to a lazy-loaded route module (exports Component, loader, ErrorBoundary instead of default export) - Enable v8_middleware in createBrowserRouter; add appRootDataContext to the per-navigation router context so middleware can share data with loaders - Add appRootMiddleware on the AppRoot route: runs the AppRootQuery once per navigation and stores the result in appRootDataContext, so the query is never duplicated across middleware and loaders - AppRoot loader now reads from appRootDataContext rather than issuing its own query; retains the profile-setup mutation and redirect logic - Replace EditEventGuard (render-time side-effect guard) with editEventMiddleware: reads siteMode from appRootDataContext and redirects single-event sites to /admin_events before any rendering occurs; restore LoginRequiredRouteGuard as the route element - Fix EventPageGuard: move navigate() call into useEffect to avoid calling a side effect during render Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Converts the render-time EventPageGuard component to a middleware function, consistent with editEventMiddleware. Removes useEffect/useNavigate imports that were only needed for the guard's render-side navigation call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the render-time AppRootContextRouteGuard component with a makeAppRootContextMiddleware factory that reads appRootDataContext and returns a 404 Response before loaders run. RouteErrorBoundary now renders FourOhFourPage for 404 responses so the layout is preserved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the render-time AuthorizationRequiredRouteGuard component with makeAuthorizationMiddleware, which returns 401 for unauthenticated users and 403 for users lacking the required abilities. RouteErrorBoundary now handles 401 by rendering a LoginRequired component (preserving the async OAuth spinner behavior) and 403 by rendering AuthorizationError. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the render-time LoginRequiredRouteGuard component with a loginRequiredMiddleware constant that returns 401 when no current user is present. RouteErrorBoundary already handles 401 with LoginRequired, so the OAuth spinner behavior is preserved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
v8_middleware: truefuture flag) with anappRootMiddlewarethat runs the AppRoot query once per navigation and stores the result inappRootDataContext, eliminating redundant fetchesEventPageGuard,EditEventGuard,AppRootContextRouteGuard,AuthorizationRequiredRouteGuard,LoginRequiredRouteGuard) to middleware that runs before loadersRouteErrorBoundaryto handle 401 (OAuth login spinner), 403 (authorization error), and 404 (FourOhFourPage) responses returned by middleware, preserving existing UX within the app layout/admin_events/:eventId/editwas inaccessible on single-event sitesTest plan
//admin_events/:eventId/editis accessible; on a multi-event site it redirects to/admin_events🤖 Generated with Claude Code