Skip to content

React-router-dom updated from v6.30.0 to v7.2.0 #3905

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

Conversation

hkumar1729
Copy link

@hkumar1729 hkumar1729 commented Apr 1, 2025

What kind of change does this PR introduce?
-> Upgrades React-router-dom from v6.30.0 to v7.2.0.

Issue Number:
#3771

Summary of changes
-> Upgraded react-router-dom from 6.30.0 to 7.2.0.
-> Verified that application is working as expected.

Does this PR introduce a breaking change?
No

Summary by CodeRabbit

  • Chores
    • Upgraded the routing library to its latest major version, paving the way for improved navigation and performance.
  • Tests
    • Extended the duration for event handling tests to ensure robust verification of dynamic behaviors.

Copy link
Contributor

coderabbitai bot commented Apr 1, 2025

Caution

Review failed

The head commit changed during the review from ac07920 to c966f72.

Walkthrough

The changes update the version of the react-router-dom dependency in the project’s package.json from ^6.27.0 to ^7.2.0, and modify a test case in the calendar component by adding a timeout parameter of 50000 milliseconds. These updates accommodate the new dependency version and ensure that asynchronous operations in the test have sufficient time to complete.

Changes

File(s) Change Summary
package.json Upgraded react-router-dom from ^6.27.0 to ^7.2.0.
src/components/.../YearlyEventCalender.spec.tsx Added a timeout parameter of 50000 ms to the test case for event expansion in the Calendar component.

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes
  • noman2002

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Apr 1, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
package.json (1)

138-138: 💡 Verification agent

🧩 Analysis chain

Update @types/react-router-dom to match the new version

The types package is still on v5.1.8 while you've upgraded react-router-dom to v7.2.0. This version mismatch could lead to typing errors.

Consider updating the types package to a compatible version:

-    "@types/react-router-dom": "^5.1.8",
+    "@types/react-router-dom": "^6.0.0",

Alternatively, check if the newer versions of react-router-dom include their own types and no longer require a separate @types package.


🌐 Web query:

Does react-router-dom v7 include its own TypeScript types or is @types/react-router-dom still needed?

💡 Result:

React Router DOM v7 includes its own TypeScript types, making the separate @types/react-router-dom package unnecessary. This continues the pattern established in v6, where the library's TypeScript support became first-class:

  • Built-in Type Definitions: Starting with v6, React Router DOM migrated to TypeScript, eliminating the need for external @types packages[5]. This carries forward in v7 via the unified react-router package[2][3][9].

  • Enhanced Type Safety: v7 introduces generated types for route parameters, loader/action data, and components through its typegen system[4][8]. This provides automatic type inference for:

    • Route path parameters (:id)
    • Search parameters
    • Loader/action inputs and outputs
    • Component props
  • Simplified Installation: The updated package structure consolidates types directly in react-router[2][3]:

    npm install react-router@latest

    No separate type installs are required[5][9].

For projects upgrading from v5 or earlier, you must remove any existing @types/react-router-dom installations to avoid conflicts:

npm uninstall @types/react-router-dom

The type improvements in v7 help catch common routing errors at compile time, like:

  • Mismatched route parameters
  • Invalid search param types
  • Incorrect loader/data consumption[4][8]

[2][4][5][9]

Citations:


Action Required: Remove the unnecessary dependency

React Router DOM v7 now includes built-in TypeScript types, so you no longer need a separate @types/react-router-dom package. Please remove the dependency from your package.json to avoid potential conflicts. For example, delete or comment out:

-    "@types/react-router-dom": "^5.1.8",

Also, run:

npm uninstall @types/react-router-dom

This will ensure that your project leverages the built-in type definitions from React Router DOM v7 without any redundant or conflicting types.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5bd18c7 and 6ea8912.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/components/EventCalender/Yearly/YearlyEventCalender.spec.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
package.json

[error] 1-1: Unauthorized change/delete detected for 'package.json'.

src/components/EventCalender/Yearly/YearlyEventCalender.spec.tsx

[warning] 1-1: Code style issues found in the above file. Run Prettier with --write to fix.

🔇 Additional comments (2)
package.json (2)

1-201: Address pipeline failure for package.json changes

There's a pipeline failure indicating "Unauthorized change/delete detected for 'package.json'". This might be related to project policies regarding dependency updates.

Check if there's a specific process for updating dependencies in this project, such as:

  1. Using a dedicated dependency update tool
  2. Getting approval from certain team members
  3. Following specific documentation procedures

You might need to discuss this with the team or review project documentation for the correct process.

🧰 Tools
🪛 GitHub Actions: PR Workflow

[error] 1-1: Unauthorized change/delete detected for 'package.json'.


61-61:

❓ Verification inconclusive

Verify compatibility with React Router DOM v7

You've updated react-router-dom from v6 to v7, which is a major version upgrade. While the PR objectives suggest there are no breaking changes to the application, it's important to ensure full compatibility.


🌐 Web query:

What are the breaking changes in react-router-dom v7 compared to v6?

💡 Result:

React Router v7 introduces several breaking changes from v6, primarily focused on architectural improvements and API simplifications. Here are the key breaking changes to consider when upgrading:

Core Breaking Changes

  1. Package Structure Simplification

    • react-router-dom is deprecated in favor of a unified react-router package[1][10]
    • New imports pattern:
      // Before (v6)
      import { Link } from 'react-router-dom';
      
      // After (v7)
      import { Link } from 'react-router';
    • DOM-specific components now use deep imports:
      import { RouterProvider } from 'react-router/dom'; // For web apps[2]
  2. Minimum Version Requirements

    • Requires React 18+ and React DOM 18+[1][7]
    • Requires Node.js 20+[1][7]
  3. Data Handling Changes

    • Deprecated json() and defer() utilities in favor of raw objects:
      // Before (v6)
      import { json } from 'react-router-dom';
      return json(data);
      
      // After (v7)
      return data; // or Response.json()[2][8]
    • New fetcher persistence behavior (old behavior removed)[1][5]
  4. Navigation API Changes

    • useHistory() completely removed in favor of useNavigate()[3][7]
    • New navigation signature:
      // Before (v6)
      navigate('/path');
      
      // After (v7)
      navigate({
        to: '/path',
        preventScrollReset: true,
        relative: 'path'
      });[4]

Architectural Changes

  1. Data Router Becomes Default

    • Component-based routing (<BrowserRouter>) still works
    • New preferred pattern uses function-based route definitions:
      // v7 preferred approach
      const router = createBrowserRouter([
        {
          path: '/',
          element: <RootLayout />,
          loader: rootLoader,
          children: [
            { path: 'dashboard', element: <Dashboard /> }
          ]
        }
      ]);[3][4]
  2. Removed APIs

    • createBrowserHistory/createHashHistory (use createBrowserRouter instead)[7]
    • UNSAFE_DeferredData and related utilities[5][7]
    • fallbackElement prop (replaced by hydrateFallbackElement)[7]

Migration Essentials

  • Critical Path Changes:

    • Relative splat path handling (dashboard/* vs *) requires code updates if not using v6 future flags[1][8]
    • Error boundary handling now more granular with route-level errorElement[3]
    • Scroll restoration behavior improvements may require verification[5]
  • Type Safety Improvements:

    // v7 type-safe loader
    const loader = async ({ params }: LoaderFunctionArgs) => {
      const user = await getUser(params.userId);
      return { user }; // No more json() wrapper[4]
    };[4]

Most breaking changes can be mitigated by:

  1. Enabling all v6 future flags before upgrading[1][7]
  2. Using the official migration codemod for imports[10]
  3. Updating React/Node.js versions first[1][7]

The React Router team emphasizes these changes enable better SSR support, improved data handling, and a more sustainable architecture for future React updates[2][3][7]. While the surface-level API changes appear significant, most applications using v6 best practices can upgrade with minimal friction[1][8].

Citations:


React Router v7 Upgrade – Verify Compatibility

The package update to v7.2.0 introduces several breaking changes compared to v6. Please double-check that the changes have been fully integrated throughout the codebase:

  • Import Path Adjustments:
    Ensure that any DOM-specific components now follow the updated import patterns (e.g., importing from 'react-router' or deep imports from 'react-router/dom' if applicable) instead of the legacy pattern from 'react-router-dom'.

  • API and Hook Updates:
    Verify that obsolete APIs (such as useHistory) have been replaced by their v7 counterparts (e.g., useNavigate). Also, check that any deprecated data handling utilities (like json() or defer()) are updated per the new data handling specifications.

  • Environment Requirements:
    Confirm that the application satisfies the new minimum version prerequisites (React 18+ and Node.js 20+).

Given these changes, a thorough review of the routing-related code is recommended to ensure no legacy v6 patterns remain.

@hkumar1729 hkumar1729 closed this Apr 1, 2025
@hkumar1729 hkumar1729 deleted the chore/update-packages branch April 1, 2025 18:06
@hkumar1729 hkumar1729 restored the chore/update-packages branch April 2, 2025 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant