Skip to content
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

Error using unstable_HistoryRouter with react-router-dom "^6.3.0", #8

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

Difenter
Copy link
Contributor

@Difenter Difenter commented Sep 5, 2024

Problem Description
We encountered a TypeScript error related to the history package version incompatibility with the React Router. Specifically:

Type 'BrowserHistory' is missing the following properties from type 'History': createURL, encodeLocation

This error occurs because we are using an old version of history (v5) with a newer version of React Router (v6.3+), which has an unstable API and uses a different internal history implementation.

Solution
Current Workaround:

To address this issue, we added // @ts-expect-error to suppress the TypeScript error for the unstable API:

ReactClient.createRoot(document.getElementById("root")).render(
  // @ts-expect-error
  <unstable_HistoryRouter history={history}>...</unstable_HistoryRouter>
);

Alternative Solutions:

a. Use the New History Implementation:

We can leverage the new history implementation compatible with React Router v6.3+, though it has some differences from v5 (e.g., no blocking, no back/forward - just go). Example usage:

import { createBrowserHistory } from "@remix-run/router";

const history = createBrowserHistory({ v5Compat: true });

b. Upgrade to the New Router Version:

Another option is to upgrade to the latest version of React Router. However, this would require significant changes to the codebase, as nearly all instances of the old router would need to be replaced with the new implementation.

Link: remix-run/react-router#9630

@Skelman50 Skelman50 self-requested a review September 5, 2024 12:20
@Difenter Difenter merged commit 270412e into development Sep 5, 2024
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.

2 participants