Skip to content

web: migrate to React Router v7#2861

Merged
dgdavid merged 7 commits intoapi-v2from
react-router-v7
Nov 10, 2025
Merged

web: migrate to React Router v7#2861
dgdavid merged 7 commits intoapi-v2from
react-router-v7

Conversation

@dgdavid
Copy link
Copy Markdown
Contributor

@dgdavid dgdavid commented Nov 10, 2025

Problem

React Router v7 was released almost a year now (see https://reactrouter.com/changelog#v700), but it has not been updated in Agama yet. In addition to the obvious benefit of keeping dependencies up-to-date, updating it might help to address some limitations we have found with the v6 version, like 06d858c

Solution

Migrate React Router dependency to its latest version.

Testing

  • Adapted existing tests.

Notes

This migration has been straightforward, and as of now, Agama is using Data Mode (see https://reactrouter.com/start/modes). However, this could change in the future if we find advantages in switching to Declarative or Framework Mode. Before making any decisions, we’ll need to work on src/App.tsx along with the changes planned for the api-v2 branch that this PR is based on.

Documentation

By using react-router and react-router/dom imports as stated in
documentation https://reactrouter.com/upgrading/v6#upgrade-to-v7
By using the right imports/mocks
After migrating to React Router v7, the test suite fails with the
following error:

> ReferenceError: TextEncoder is not defined

This appears to be due to an unimplemented TextEncoder in jsdom. To
resolve this, we follow the same workaround as React Router, as outlined
in remix-run/react-router#12363 (comment)
It was introduced to work around React Router v6's issue of not encoding
parameters in the generatePath function. However, after migrating to v7,
tests began failing due to double encoding. This revealed that React
Router v7 already handles encoding parameters in generatePath. See
remix-run/react-router#13530

Thus, this commit reverts the changes made in
#2576
In TypeScript, TextEncoder and TextDecoder are global types when
targeting the DOM environment, causing conflicts when importing these
classes from Node’s util module. To avoid these conflicts, TextEncoder
and TextDecoder from util have been imported with different names
(NodeTextEncoder, NodeTextDecoder) and assigned to globalThis with
explicit type assertions.

* MDN
  - https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder
  - https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder

* StackOverflow
  - https://stackoverflow.com/a/77752064

* TypeScript types
  - https://github.com/microsoft/TypeScript/blob/efca03ffed10dccede4fbc8dd8a624374e5424d9/src/lib/dom.generated.d.ts#L32378
To fix an issue with React Router v7 types

> src/index.tsx:25:32 - error TS2307: Cannot find module 'react-router/dom' or its corresponding type declarations.
>  There are types at 'node_modules/react-router/dist/development/dom-export.d.mts',
>     but this result could not be resolved under your current 'moduleResolution' setting.
>     Consider updating to 'node16', 'nodenext', or 'bundler'.

As per TypeScript documentation, https://www.typescriptlang.org/tsconfig/#moduleResolution

> 'bundler' for use with bundlers. Like node16 and nodenext, this mode
>   supports package.json "imports" and "exports", but unlike the Node.js
>   resolution modes, bundler never requires file extensions on relative
>   paths in imports.
@dgdavid dgdavid requested review from ancorgs and imobachgs November 10, 2025 17:19
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 64.776% (-0.02%) from 64.798%
when pulling 2dcde83 on react-router-v7
into 0b9ab30 on api-v2.

Copy link
Copy Markdown
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

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

Reviewed commit per commit. Thanks!

@dgdavid dgdavid merged commit da86580 into api-v2 Nov 10, 2025
8 of 9 checks passed
@dgdavid dgdavid deleted the react-router-v7 branch November 10, 2025 21:43
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.

3 participants