-
Notifications
You must be signed in to change notification settings - Fork 18
👻 Upgrade react-router-dom #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
Reviewer's GuideThis PR upgrades react-router-dom to the next major version and refactors the routing setup by introducing a Lazy component that wraps each route in a Suspense boundary, replacing the previous global Suspense placement. Sequence diagram for route rendering with Lazy and SuspensesequenceDiagram
participant Browser
participant AppRoutes
participant Lazy
participant Suspense
participant Spinner
participant PageComponent
Browser->>AppRoutes: Navigates to a route
AppRoutes->>Lazy: Renders route element
Lazy->>Suspense: Wraps component with fallback
Suspense->>Spinner: Shows spinner while loading
Suspense-->>PageComponent: Loads page component
Spinner-->>Suspense: Spinner hidden after load
Suspense-->>Lazy: Renders loaded component
Lazy-->>AppRoutes: Returns rendered component
Class diagram for the new Lazy component and updated AppRoutesclassDiagram
class Lazy {
+component: React.ReactNode
+render(): React.ReactNode
}
class AppRoutes {
+render(): React.ReactNode
}
Lazy <.. AppRoutes: used by
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Rename the prop from
component
toelement
in the Lazy wrapper to align with React Router’selement
field and improve consistency. - Extract the Lazy helper into its own module to keep Routes.tsx focused on route definitions and reduce file bloat.
- Consider leveraging React Router v7’s built-in lazy route API (or createBrowserRouter) for code-splitting instead of manually wrapping every route with Suspense.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Rename the prop from `component` to `element` in the Lazy wrapper to align with React Router’s `element` field and improve consistency.
- Extract the Lazy helper into its own module to keep Routes.tsx focused on route definitions and reduce file bloat.
- Consider leveraging React Router v7’s built-in lazy route API (or createBrowserRouter) for code-splitting instead of manually wrapping every route with Suspense.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #656 +/- ##
==========================================
+ Coverage 57.28% 58.30% +1.02%
==========================================
Files 146 146
Lines 2430 2432 +2
Branches 552 552
==========================================
+ Hits 1392 1418 +26
+ Misses 833 809 -24
Partials 205 205 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# Conflicts: # package-lock.json
# Conflicts: # client/src/app/Routes.tsx
Signed-off-by: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com>
Upgrading react-router-dom to the next major version
It is not documented but in order for React.Suspense to work, it needs to be defined in the definition of the router itself thought the "element" field.
This PR adds a component "Lazy" that wraps each router component, without it, the Spinner that is rendered before each page is loaded in the browser, it's not rendered.
The docs from https://reactrouter.com/upgrading/v6#v7_starttransition helped a to diagnose the upgrade path.
Summary by Sourcery
Upgrade to react-router-dom v7 and implement per-route lazy loading by introducing a Lazy wrapper for Suspense fallbacks
Enhancements:
Build: