diff --git a/.changeset/dull-walls-drive.md b/.changeset/dull-walls-drive.md new file mode 100644 index 0000000000..2743ecc64f --- /dev/null +++ b/.changeset/dull-walls-drive.md @@ -0,0 +1,5 @@ +--- +"@react-router/dev": patch +--- + +Added react-router/dom to Vite optimizeDeps and resolve.dedupe arrays diff --git a/.changeset/shiny-horses-pump.md b/.changeset/shiny-horses-pump.md new file mode 100644 index 0000000000..3e7aa9aeb3 --- /dev/null +++ b/.changeset/shiny-horses-pump.md @@ -0,0 +1,5 @@ +--- +"react-router": patch +--- + +Removed cyclic dependency on react-router diff --git a/contributors.yml b/contributors.yml index 09cfbf1df5..069b92d2c0 100644 --- a/contributors.yml +++ b/contributors.yml @@ -217,6 +217,7 @@ - petersendidit - promet99 - pyitphyoaung +- redabacha - refusado - rimian - robbtraister diff --git a/packages/react-router-dev/vite/plugin.ts b/packages/react-router-dev/vite/plugin.ts index 2d87c13bfc..2fa32c2aff 100644 --- a/packages/react-router-dev/vite/plugin.ts +++ b/packages/react-router-dev/vite/plugin.ts @@ -831,6 +831,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => { // Pre-bundle router dependencies to avoid router duplicates. // Mismatching routers cause `Error: You must render this element inside a element`. "react-router", + "react-router/dom", // Check to avoid "Failed to resolve dependency: react-router-dom, present in 'optimizeDeps.include'" ...(hasDependency("react-router-dom") ? ["react-router-dom"] @@ -849,6 +850,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = (_config) => { // see description for `optimizeDeps.include` "react-router", + "react-router/dom", "react-router-dom", ], }, diff --git a/packages/react-router/__tests__/Route-test.tsx b/packages/react-router/__tests__/Route-test.tsx index ff5a98c8c9..013aa63ffe 100644 --- a/packages/react-router/__tests__/Route-test.tsx +++ b/packages/react-router/__tests__/Route-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route } from "react-router"; +import { MemoryRouter, Route, Routes } from "../index"; describe("A ", () => { it("renders its `element` prop", () => { diff --git a/packages/react-router/__tests__/Router-basename-test.tsx b/packages/react-router/__tests__/Router-basename-test.tsx index b840643cd7..e352adc3dc 100644 --- a/packages/react-router/__tests__/Router-basename-test.tsx +++ b/packages/react-router/__tests__/Router-basename-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route } from "react-router"; +import { MemoryRouter, Route, Routes } from "../index"; describe("", () => { let consoleWarn: jest.SpyInstance; diff --git a/packages/react-router/__tests__/Router-test.tsx b/packages/react-router/__tests__/Router-test.tsx index 9f7cddf4c5..9434b1b9e2 100644 --- a/packages/react-router/__tests__/Router-test.tsx +++ b/packages/react-router/__tests__/Router-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, useLocation } from "react-router"; +import { MemoryRouter, useLocation } from "../index"; describe("", () => { let consoleError: jest.SpyInstance; diff --git a/packages/react-router/__tests__/Routes-location-test.tsx b/packages/react-router/__tests__/Routes-location-test.tsx index b5aafe8c7a..5df948db29 100644 --- a/packages/react-router/__tests__/Routes-location-test.tsx +++ b/packages/react-router/__tests__/Routes-location-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Route, Routes, useParams } from "react-router"; +import { MemoryRouter, Route, Routes, useParams } from "../index"; describe(" with a location", () => { function Home() { diff --git a/packages/react-router/__tests__/Routes-test.tsx b/packages/react-router/__tests__/Routes-test.tsx index e45df9e520..7003a02c4c 100644 --- a/packages/react-router/__tests__/Routes-test.tsx +++ b/packages/react-router/__tests__/Routes-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route } from "react-router"; +import { MemoryRouter, Route, Routes } from "../index"; describe("", () => { let consoleWarn: jest.SpyInstance; diff --git a/packages/react-router/__tests__/absolute-path-matching-test.tsx b/packages/react-router/__tests__/absolute-path-matching-test.tsx index 9d64b69578..732d59dd79 100644 --- a/packages/react-router/__tests__/absolute-path-matching-test.tsx +++ b/packages/react-router/__tests__/absolute-path-matching-test.tsx @@ -1,5 +1,4 @@ -import type { RouteObject } from "react-router"; -import { matchRoutes } from "react-router"; +import { matchRoutes, type RouteObject } from "../index"; function pickPaths(routes: RouteObject[], pathname: string): string[] | null { let matches = matchRoutes(routes, pathname); diff --git a/packages/react-router/__tests__/createRoutesFromChildren-test.tsx b/packages/react-router/__tests__/createRoutesFromChildren-test.tsx index b3de9ad931..2f612267f9 100644 --- a/packages/react-router/__tests__/createRoutesFromChildren-test.tsx +++ b/packages/react-router/__tests__/createRoutesFromChildren-test.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import { Route, createRoutesFromChildren } from "react-router"; +import { Route, createRoutesFromChildren } from "../index"; describe("creating routes from JSX", () => { it("creates a route config of nested JavaScript objects", () => { diff --git a/packages/react-router/__tests__/data-memory-router-test.tsx b/packages/react-router/__tests__/data-memory-router-test.tsx index 67bb418f18..ade764f5c1 100644 --- a/packages/react-router/__tests__/data-memory-router-test.tsx +++ b/packages/react-router/__tests__/data-memory-router-test.tsx @@ -20,21 +20,19 @@ import { useActionData, useAsyncError, useAsyncValue, + useFetcher, useLoaderData, useLocation, useMatches, + useNavigate, useNavigation, + useRevalidator, useRouteError, useRouteLoaderData, -} from "react-router"; - -import { - useFetcher, - useNavigate, - useRevalidator, useSubmit, type ErrorResponse, } from "../index"; + import urlDataStrategy from "./router/utils/urlDataStrategy"; import { createDeferred } from "./router/utils/utils"; import MemoryNavigate from "./utils/MemoryNavigate"; diff --git a/packages/react-router/__tests__/data-router-no-dom-test.tsx b/packages/react-router/__tests__/data-router-no-dom-test.tsx index b8125c7cea..a3fd579981 100644 --- a/packages/react-router/__tests__/data-router-no-dom-test.tsx +++ b/packages/react-router/__tests__/data-router-no-dom-test.tsx @@ -4,9 +4,9 @@ import * as React from "react"; import renderer from "react-test-renderer"; -import { useFetcher } from "../lib/dom/lib"; -import { RouterProvider } from "../lib/dom-export/dom-router-provider"; import { createMemoryRouter } from "../lib/components"; +import { RouterProvider } from "../lib/dom-export/dom-router-provider"; +import { useFetcher } from "../lib/dom/lib"; import { useLoaderData, useNavigate } from "../lib/hooks"; describe("RouterProvider works when no DOM APIs are available", () => { diff --git a/packages/react-router/__tests__/descendant-routes-params-test.tsx b/packages/react-router/__tests__/descendant-routes-params-test.tsx index 45edec76f3..5f335110ea 100644 --- a/packages/react-router/__tests__/descendant-routes-params-test.tsx +++ b/packages/react-router/__tests__/descendant-routes-params-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, useParams } from "react-router"; +import { MemoryRouter, Route, Routes, useParams } from "../index"; describe("Descendant ", () => { it("receive all params from ancestor ", () => { diff --git a/packages/react-router/__tests__/descendant-routes-splat-matching-test.tsx b/packages/react-router/__tests__/descendant-routes-splat-matching-test.tsx index ef63eb1437..db4590500d 100644 --- a/packages/react-router/__tests__/descendant-routes-splat-matching-test.tsx +++ b/packages/react-router/__tests__/descendant-routes-splat-matching-test.tsx @@ -1,7 +1,13 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Outlet, Routes, Route, useParams } from "react-router"; -import type { InitialEntry } from "react-router"; +import { + MemoryRouter, + Outlet, + Route, + Routes, + useParams, + type InitialEntry, +} from "../index"; describe("Descendant splat matching", () => { describe("when the parent route path ends with /*", () => { diff --git a/packages/react-router/__tests__/descendant-routes-warning-test.tsx b/packages/react-router/__tests__/descendant-routes-warning-test.tsx index 52588870a2..f709868b0c 100644 --- a/packages/react-router/__tests__/descendant-routes-warning-test.tsx +++ b/packages/react-router/__tests__/descendant-routes-warning-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Outlet, Routes, Route } from "react-router"; +import { MemoryRouter, Outlet, Route, Routes } from "../index"; describe("Descendant ", () => { let consoleWarn: jest.SpyInstance; diff --git a/packages/react-router/__tests__/dom/data-browser-router-test.tsx b/packages/react-router/__tests__/dom/data-browser-router-test.tsx index 255d2b04b0..9caa1130b6 100644 --- a/packages/react-router/__tests__/dom/data-browser-router-test.tsx +++ b/packages/react-router/__tests__/dom/data-browser-router-test.tsx @@ -1,4 +1,3 @@ -import type { ErrorResponse, Fetcher, RouterState } from "react-router"; import "@testing-library/jest-dom"; import { act, @@ -9,7 +8,6 @@ import { } from "@testing-library/react"; import { JSDOM } from "jsdom"; import * as React from "react"; -import type { RouteObject } from "../../index"; import { Await, UNSAFE_DataRouterStateContext as DataRouterStateContext, @@ -35,10 +33,14 @@ import { useRouteError, useSearchParams, useSubmit, + type ErrorResponse, + type Fetcher, + type RouteObject, + type RouterState, } from "../../index"; -import getHtml from "../utils/getHtml"; import { createDeferred, tick } from "../router/utils/utils"; +import getHtml from "../utils/getHtml"; testDomRouter("", createBrowserRouter, (url) => getWindowImpl(url, false) diff --git a/packages/react-router/__tests__/dom/data-static-router-test.tsx b/packages/react-router/__tests__/dom/data-static-router-test.tsx index 9a738d1a90..54a16c2b0b 100644 --- a/packages/react-router/__tests__/dom/data-static-router-test.tsx +++ b/packages/react-router/__tests__/dom/data-static-router-test.tsx @@ -4,17 +4,17 @@ import * as React from "react"; import * as ReactDOMServer from "react-dom/server"; -import type { StaticHandlerContext } from "../../index"; import { Form, Link, Outlet, + StaticRouterProvider, + createStaticHandler, + createStaticRouter, useLoaderData, useLocation, useMatches, - createStaticHandler, - createStaticRouter, - StaticRouterProvider, + type StaticHandlerContext, } from "../../index"; beforeEach(() => { diff --git a/packages/react-router/__tests__/dom/partial-hydration-test.tsx b/packages/react-router/__tests__/dom/partial-hydration-test.tsx index 7f6c9e259d..fff11ba527 100644 --- a/packages/react-router/__tests__/dom/partial-hydration-test.tsx +++ b/packages/react-router/__tests__/dom/partial-hydration-test.tsx @@ -1,8 +1,7 @@ import "@testing-library/jest-dom"; import { act, render, screen, waitFor } from "@testing-library/react"; import * as React from "react"; -import type { LoaderFunction } from "react-router"; -import {} from "react-router"; +import { RouterProvider as ReactRouterDom_RouterProvider } from "../../dom-export"; import { Outlet, RouterProvider as ReactRouter_RouterProvider, @@ -11,11 +10,11 @@ import { createMemoryRouter, useLoaderData, useRouteError, + type LoaderFunction, } from "../../index"; -import { RouterProvider as ReactRouterDom_RouterProvider } from "../../dom-export"; -import getHtml from "../utils/getHtml"; import { createDeferred, tick } from "../router/utils/utils"; +import getHtml from "../utils/getHtml"; let didAssertMissingHydrateFallback = false; diff --git a/packages/react-router/__tests__/dom/scroll-restoration-test.tsx b/packages/react-router/__tests__/dom/scroll-restoration-test.tsx index 8576f535e1..5314f816de 100644 --- a/packages/react-router/__tests__/dom/scroll-restoration-test.tsx +++ b/packages/react-router/__tests__/dom/scroll-restoration-test.tsx @@ -1,20 +1,21 @@ +import "@testing-library/jest-dom"; +import "@testing-library/jest-dom/extend-expect"; +import { fireEvent, render, screen } from "@testing-library/react"; import { JSDOM } from "jsdom"; import * as React from "react"; -import { render, fireEvent, screen } from "@testing-library/react"; -import "@testing-library/jest-dom"; -import getHtml from "../utils/getHtml"; import { Link, Outlet, RouterProvider, ScrollRestoration, createBrowserRouter, + createMemoryRouter, + redirect, } from "../../index"; -import type { FrameworkContextObject } from "../../lib/dom/ssr/entry"; -import { createMemoryRouter, redirect } from "react-router"; import { FrameworkContext, Scripts } from "../../lib/dom/ssr/components"; -import "@testing-library/jest-dom/extend-expect"; +import type { FrameworkContextObject } from "../../lib/dom/ssr/entry"; +import getHtml from "../utils/getHtml"; describe(`ScrollRestoration`, () => { it("restores the scroll position for a page when re-visited", () => { diff --git a/packages/react-router/__tests__/dom/ssr/components-test.tsx b/packages/react-router/__tests__/dom/ssr/components-test.tsx index 952af47050..2344b1ba24 100644 --- a/packages/react-router/__tests__/dom/ssr/components-test.tsx +++ b/packages/react-router/__tests__/dom/ssr/components-test.tsx @@ -1,9 +1,10 @@ -import { createStaticHandler } from "react-router"; +import "@testing-library/jest-dom/extend-expect"; import { act, fireEvent, render } from "@testing-library/react"; import * as React from "react"; import { createMemoryRouter, + createStaticHandler, Link, NavLink, Outlet, @@ -13,7 +14,6 @@ import { HydratedRouter } from "../../../lib/dom-export/hydrated-router"; import { FrameworkContext } from "../../../lib/dom/ssr/components"; import invariant from "../../../lib/dom/ssr/invariant"; import { ServerRouter } from "../../../lib/dom/ssr/server"; -import "@testing-library/jest-dom/extend-expect"; const setIntentEvents = ["focus", "mouseEnter", "touchStart"] as const; type PrefetchEventHandlerProps = { diff --git a/packages/react-router/__tests__/generatePath-test.tsx b/packages/react-router/__tests__/generatePath-test.tsx index 70232f7d46..dcc9ce42f5 100644 --- a/packages/react-router/__tests__/generatePath-test.tsx +++ b/packages/react-router/__tests__/generatePath-test.tsx @@ -1,4 +1,4 @@ -import { generatePath } from "react-router"; +import { generatePath } from "../index"; describe("generatePath", () => { describe("with no params", () => { diff --git a/packages/react-router/__tests__/gh-issue-8127-test.tsx b/packages/react-router/__tests__/gh-issue-8127-test.tsx index 3a6d7f41f5..93a993ab48 100644 --- a/packages/react-router/__tests__/gh-issue-8127-test.tsx +++ b/packages/react-router/__tests__/gh-issue-8127-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route } from "../index"; +import { MemoryRouter, Route, Routes } from "../index"; describe("GH Issue #8127", () => { it("works", () => { diff --git a/packages/react-router/__tests__/gh-issue-8165-test.tsx b/packages/react-router/__tests__/gh-issue-8165-test.tsx index 73ec0a7d4c..dea7b0c991 100644 --- a/packages/react-router/__tests__/gh-issue-8165-test.tsx +++ b/packages/react-router/__tests__/gh-issue-8165-test.tsx @@ -2,11 +2,11 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; import { MemoryRouter, - Routes, + Navigate, Route, - useParams, + Routes, useNavigate, - Navigate, + useParams, } from "../index"; describe("GH Issue #8165", () => { diff --git a/packages/react-router/__tests__/greedy-matching-test.tsx b/packages/react-router/__tests__/greedy-matching-test.tsx index deed42a3e2..43c624e309 100644 --- a/packages/react-router/__tests__/greedy-matching-test.tsx +++ b/packages/react-router/__tests__/greedy-matching-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, Outlet } from "../index"; +import { MemoryRouter, Outlet, Route, Routes } from "../index"; describe("greedy matching", () => { let routes = ( diff --git a/packages/react-router/__tests__/index-routes-test.tsx b/packages/react-router/__tests__/index-routes-test.tsx index 60cd84b79e..f575006f55 100644 --- a/packages/react-router/__tests__/index-routes-test.tsx +++ b/packages/react-router/__tests__/index-routes-test.tsx @@ -1,4 +1,4 @@ -import { matchRoutes } from "react-router"; +import { matchRoutes } from "../index"; describe("index route matching", () => { it("throws when the index route has children", () => { diff --git a/packages/react-router/__tests__/layout-routes-test.tsx b/packages/react-router/__tests__/layout-routes-test.tsx index 49cf2109bd..6286edf49f 100644 --- a/packages/react-router/__tests__/layout-routes-test.tsx +++ b/packages/react-router/__tests__/layout-routes-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, Outlet } from "react-router"; +import { MemoryRouter, Outlet, Route, Routes } from "../index"; describe("A layout route", () => { it("does not match when none of its children do", () => { diff --git a/packages/react-router/__tests__/matchPath-test.tsx b/packages/react-router/__tests__/matchPath-test.tsx index 5d4a95b0aa..5dd60ee768 100644 --- a/packages/react-router/__tests__/matchPath-test.tsx +++ b/packages/react-router/__tests__/matchPath-test.tsx @@ -1,4 +1,4 @@ -import { matchPath } from "react-router"; +import { matchPath } from "../index"; describe("matchPath", () => { it("matches the root / URL", () => { diff --git a/packages/react-router/__tests__/matchRoutes-test.tsx b/packages/react-router/__tests__/matchRoutes-test.tsx index 71c4e472ac..867327707c 100644 --- a/packages/react-router/__tests__/matchRoutes-test.tsx +++ b/packages/react-router/__tests__/matchRoutes-test.tsx @@ -1,6 +1,5 @@ import * as React from "react"; -import type { RouteObject } from "react-router"; -import { matchRoutes } from "react-router"; +import { matchRoutes, type RouteObject } from "../index"; function pickPaths( routes: RouteObject[], diff --git a/packages/react-router/__tests__/navigate-test.tsx b/packages/react-router/__tests__/navigate-test.tsx index 6b95638227..a8043e3eaa 100644 --- a/packages/react-router/__tests__/navigate-test.tsx +++ b/packages/react-router/__tests__/navigate-test.tsx @@ -1,16 +1,16 @@ +import { render, screen, waitFor } from "@testing-library/react"; import * as React from "react"; import * as TestRenderer from "react-test-renderer"; import { MemoryRouter, Navigate, Outlet, - Routes, Route, RouterProvider, + Routes, createMemoryRouter, useLocation, -} from "react-router"; -import { render, screen, waitFor } from "@testing-library/react"; +} from "../index"; import getHtml from "../../react-router/__tests__/utils/getHtml"; diff --git a/packages/react-router/__tests__/params-decode-test.tsx b/packages/react-router/__tests__/params-decode-test.tsx index bf5ef43155..4f672c61a9 100644 --- a/packages/react-router/__tests__/params-decode-test.tsx +++ b/packages/react-router/__tests__/params-decode-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, useParams } from "react-router"; +import { MemoryRouter, Route, Routes, useParams } from "../index"; describe("Decoding params", () => { it("works", () => { diff --git a/packages/react-router/__tests__/path-matching-test.tsx b/packages/react-router/__tests__/path-matching-test.tsx index 5f00c2445b..2728733ce0 100644 --- a/packages/react-router/__tests__/path-matching-test.tsx +++ b/packages/react-router/__tests__/path-matching-test.tsx @@ -1,5 +1,4 @@ -import type { RouteObject } from "react-router"; -import { matchRoutes } from "react-router"; +import { matchRoutes, type RouteObject } from "../index"; function pickPaths(routes: RouteObject[], pathname: string): string[] | null { let matches = matchRoutes(routes, pathname); diff --git a/packages/react-router/__tests__/resolvePath-test.tsx b/packages/react-router/__tests__/resolvePath-test.tsx index 09a5a00ecf..49608531ba 100644 --- a/packages/react-router/__tests__/resolvePath-test.tsx +++ b/packages/react-router/__tests__/resolvePath-test.tsx @@ -1,4 +1,4 @@ -import { resolvePath } from "react-router"; +import { resolvePath } from "../index"; describe("resolvePath", () => { it('resolves absolute paths irrespective of the "from" pathname', () => { diff --git a/packages/react-router/__tests__/route-depth-order-matching-test.tsx b/packages/react-router/__tests__/route-depth-order-matching-test.tsx index d5f003850c..2d11c4d94c 100644 --- a/packages/react-router/__tests__/route-depth-order-matching-test.tsx +++ b/packages/react-router/__tests__/route-depth-order-matching-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Outlet, Routes, Route } from "react-router"; +import { MemoryRouter, Outlet, Route, Routes } from "../index"; describe("nested routes with no path", () => { it("matches them depth-first", () => { diff --git a/packages/react-router/__tests__/route-matching-test.tsx b/packages/react-router/__tests__/route-matching-test.tsx index 88e4241a07..d868a71bf2 100644 --- a/packages/react-router/__tests__/route-matching-test.tsx +++ b/packages/react-router/__tests__/route-matching-test.tsx @@ -1,14 +1,14 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import type { RouteObject } from "react-router"; import { MemoryRouter, Outlet, - Routes, Route, + Routes, useParams, useRoutes, -} from "react-router"; + type RouteObject, +} from "../index"; describe("route matching", () => { function describeRouteMatching(routes: React.ReactNode) { diff --git a/packages/react-router/__tests__/same-component-lifecycle-test.tsx b/packages/react-router/__tests__/same-component-lifecycle-test.tsx index be9852805f..705bc1acef 100644 --- a/packages/react-router/__tests__/same-component-lifecycle-test.tsx +++ b/packages/react-router/__tests__/same-component-lifecycle-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route } from "react-router"; +import { MemoryRouter, Route, Routes } from "../index"; describe("when the same component is mounted by two different routes", () => { it("mounts only once", () => { diff --git a/packages/react-router/__tests__/server-runtime/server-test.ts b/packages/react-router/__tests__/server-runtime/server-test.ts index ca5bd2f875..1c219acd2a 100644 --- a/packages/react-router/__tests__/server-runtime/server-test.ts +++ b/packages/react-router/__tests__/server-runtime/server-test.ts @@ -2,11 +2,11 @@ * @jest-environment node */ -import type { StaticHandlerContext } from "react-router"; +import type { StaticHandlerContext } from "../../index"; -import { createRequestHandler } from "../../lib/server-runtime/server"; -import { ServerMode } from "../../lib/server-runtime/mode"; import type { ServerBuild } from "../../lib/server-runtime/build"; +import { ServerMode } from "../../lib/server-runtime/mode"; +import { createRequestHandler } from "../../lib/server-runtime/server"; import { mockServerBuild } from "./utils"; function spyConsole() { diff --git a/packages/react-router/__tests__/use-revalidator-test.tsx b/packages/react-router/__tests__/use-revalidator-test.tsx index 192262d94d..00a9209b81 100644 --- a/packages/react-router/__tests__/use-revalidator-test.tsx +++ b/packages/react-router/__tests__/use-revalidator-test.tsx @@ -17,7 +17,7 @@ import { useNavigation, useRevalidator, useRouteError, -} from "react-router"; +} from "../index"; import MemoryNavigate from "./utils/MemoryNavigate"; import getHtml from "./utils/getHtml"; diff --git a/packages/react-router/__tests__/useHref-basename-test.tsx b/packages/react-router/__tests__/useHref-basename-test.tsx index 0b5bde505f..93ac00c128 100644 --- a/packages/react-router/__tests__/useHref-basename-test.tsx +++ b/packages/react-router/__tests__/useHref-basename-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, useHref } from "react-router"; +import { MemoryRouter, Route, Routes, useHref } from "../index"; function ShowHref({ to }: { to: string }) { return

{useHref(to)}

; diff --git a/packages/react-router/__tests__/useHref-test.tsx b/packages/react-router/__tests__/useHref-test.tsx index f3e2c4c173..666f34e847 100644 --- a/packages/react-router/__tests__/useHref-test.tsx +++ b/packages/react-router/__tests__/useHref-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, useHref } from "react-router"; +import { MemoryRouter, Route, Routes, useHref } from "../index"; function ShowHref({ to }: { to: string }) { return
{useHref(to)}
; diff --git a/packages/react-router/__tests__/useLocation-test.tsx b/packages/react-router/__tests__/useLocation-test.tsx index 121073a0d5..ac7df43e23 100644 --- a/packages/react-router/__tests__/useLocation-test.tsx +++ b/packages/react-router/__tests__/useLocation-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Routes, Route, useLocation } from "react-router"; +import { MemoryRouter, Route, Routes, useLocation } from "../index"; function ShowLocation() { let location = useLocation(); diff --git a/packages/react-router/__tests__/useMatch-test.tsx b/packages/react-router/__tests__/useMatch-test.tsx index f51219a055..5a56608d4b 100644 --- a/packages/react-router/__tests__/useMatch-test.tsx +++ b/packages/react-router/__tests__/useMatch-test.tsx @@ -1,7 +1,12 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import type { PathMatch } from "react-router"; -import { MemoryRouter, Routes, Route, useMatch } from "react-router"; +import { + MemoryRouter, + Route, + Routes, + useMatch, + type PathMatch, +} from "../index"; function ShowMatch({ pattern }: { pattern: string }) { return
{JSON.stringify(useMatch(pattern), null, 2)}
; diff --git a/packages/react-router/__tests__/useNavigate-test.tsx b/packages/react-router/__tests__/useNavigate-test.tsx index 66823db747..e62c24b4cf 100644 --- a/packages/react-router/__tests__/useNavigate-test.tsx +++ b/packages/react-router/__tests__/useNavigate-test.tsx @@ -1,17 +1,18 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import type { RelativeRoutingType, To } from "react-router"; import { - MemoryRouter, - Routes, - Route, - useNavigate, - useLocation, createMemoryRouter, createRoutesFromElements, + MemoryRouter, Outlet, + Route, RouterProvider, -} from "react-router"; + Routes, + useLocation, + useNavigate, + type RelativeRoutingType, + type To, +} from "../index"; describe("useNavigate", () => { it("navigates to the new location", async () => { diff --git a/packages/react-router/__tests__/useOutlet-test.tsx b/packages/react-router/__tests__/useOutlet-test.tsx index f283bd4874..ed77e7d9bd 100644 --- a/packages/react-router/__tests__/useOutlet-test.tsx +++ b/packages/react-router/__tests__/useOutlet-test.tsx @@ -2,11 +2,11 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; import { MemoryRouter, - Routes, Route, + Routes, useOutlet, useOutletContext, -} from "react-router"; +} from "../index"; describe("useOutlet", () => { describe("when there is no child route", () => { diff --git a/packages/react-router/__tests__/useParams-test.tsx b/packages/react-router/__tests__/useParams-test.tsx index 4b34daf16a..7e876f27ee 100644 --- a/packages/react-router/__tests__/useParams-test.tsx +++ b/packages/react-router/__tests__/useParams-test.tsx @@ -1,6 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import { MemoryRouter, Outlet, Routes, Route, useParams } from "react-router"; +import { MemoryRouter, Outlet, Route, Routes, useParams } from "../index"; function ShowParams() { return
{JSON.stringify(useParams())}
; diff --git a/packages/react-router/__tests__/useResolvedPath-test.tsx b/packages/react-router/__tests__/useResolvedPath-test.tsx index 7f183b4f7a..aafccc3bbe 100644 --- a/packages/react-router/__tests__/useResolvedPath-test.tsx +++ b/packages/react-router/__tests__/useResolvedPath-test.tsx @@ -1,14 +1,14 @@ +import { prettyDOM, render } from "@testing-library/react"; import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import type { Path } from "react-router"; import { MemoryRouter, - Routes, Route, - useResolvedPath, + Routes, useLocation, -} from "react-router"; -import { prettyDOM, render } from "@testing-library/react"; + useResolvedPath, + type Path, +} from "../index"; function ShowResolvedPath({ path }: { path: string | Path }) { return
{JSON.stringify(useResolvedPath(path))}
; diff --git a/packages/react-router/__tests__/useRoutes-test.tsx b/packages/react-router/__tests__/useRoutes-test.tsx index 91de38a632..90e69ce7ce 100644 --- a/packages/react-router/__tests__/useRoutes-test.tsx +++ b/packages/react-router/__tests__/useRoutes-test.tsx @@ -1,7 +1,6 @@ import * as React from "react"; import * as TestRenderer from "react-test-renderer"; -import type { RouteObject } from "react-router"; -import { MemoryRouter, useRoutes } from "react-router"; +import { MemoryRouter, useRoutes, type RouteObject } from "../index"; describe("useRoutes", () => { it("returns the matching element from a route config", () => { diff --git a/packages/react-router/lib/dom-export/dom-router-provider.tsx b/packages/react-router/lib/dom-export/dom-router-provider.tsx index 65c6fea424..8d31f63f55 100644 --- a/packages/react-router/lib/dom-export/dom-router-provider.tsx +++ b/packages/react-router/lib/dom-export/dom-router-provider.tsx @@ -1,8 +1,10 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; -import type { RouterProviderProps as BaseRouterProviderProps } from "react-router"; -import { RouterProvider as BaseRouterProvider } from "react-router"; +import { + RouterProvider as BaseRouterProvider, + type RouterProviderProps as BaseRouterProviderProps, +} from "react-router"; export { HydratedRouter } from "./hydrated-router"; diff --git a/packages/react-router/lib/dom-export/hydrated-router.tsx b/packages/react-router/lib/dom-export/hydrated-router.tsx index 295470be06..cfa13d941e 100644 --- a/packages/react-router/lib/dom-export/hydrated-router.tsx +++ b/packages/react-router/lib/dom-export/hydrated-router.tsx @@ -1,11 +1,5 @@ import * as React from "react"; -import type { - UNSAFE_AssetsManifest as AssetsManifest, - UNSAFE_RouteModules as RouteModules, - DataRouter, - HydrationState, -} from "react-router"; import { UNSAFE_invariant as invariant, UNSAFE_FrameworkContext as FrameworkContext, @@ -22,6 +16,10 @@ import { UNSAFE_mapRouteProperties as mapRouteProperties, UNSAFE_createClientRoutesWithHMRRevalidationOptOut as createClientRoutesWithHMRRevalidationOptOut, matchRoutes, + type UNSAFE_AssetsManifest as AssetsManifest, + type UNSAFE_RouteModules as RouteModules, + type DataRouter, + type HydrationState, } from "react-router"; import { RouterProvider } from "./dom-router-provider"; diff --git a/packages/react-router/package.json b/packages/react-router/package.json index 215eb32c85..9d8842ff83 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -42,7 +42,6 @@ "@types/cookie": "^0.6.0", "@web3-storage/multipart-parser": "^1.0.0", "cookie": "^0.6.0", - "react-router": "workspace:*", "set-cookie-parser": "^2.6.0", "source-map": "^0.7.3", "turbo-stream": "2.4.0" diff --git a/packages/react-router/rollup.config.js b/packages/react-router/rollup.config.js index cb776f2983..ea9e84eb0e 100644 --- a/packages/react-router/rollup.config.js +++ b/packages/react-router/rollup.config.js @@ -69,6 +69,9 @@ module.exports = function rollup() { format: "esm", sourcemap: !PRETTY, banner: createBanner("React Router", version), + paths: { + "react-router": "./index.mjs", + }, }, external: (id) => isBareModuleId(id), plugins: [ @@ -215,6 +218,9 @@ module.exports = function rollup() { format: "esm", sourcemap: !PRETTY, banner: createBanner("React Router", version), + paths: { + "react-router": "./react-router.development.js", + }, }, external: (id) => isBareModuleId(id), plugins: [ @@ -246,6 +252,9 @@ module.exports = function rollup() { format: "esm", sourcemap: !PRETTY, banner: createBanner("React Router", version), + paths: { + "react-router": "./react-router.production.min.js", + }, }, external: (id) => isBareModuleId(id), plugins: [ @@ -371,6 +380,9 @@ module.exports = function rollup() { react: "React", "react-router": "ReactRouter", }, + paths: { + "react-router": "./react-router.development.js", + }, name: "ReactRouterDOMExport", }, external: (id) => isBareModuleId(id), @@ -407,6 +419,9 @@ module.exports = function rollup() { react: "React", "react-router": "ReactRouter", }, + paths: { + "react-router": "./react-router.production.min.js", + }, name: "ReactRouterDomExport", }, external: (id) => isBareModuleId(id), diff --git a/packages/react-router/tsconfig.json b/packages/react-router/tsconfig.json index 9238ae0799..f547617a83 100644 --- a/packages/react-router/tsconfig.json +++ b/packages/react-router/tsconfig.json @@ -16,6 +16,10 @@ "skipLibCheck": true, "outDir": "dist", - "rootDir": "." + "rootDir": ".", + + "paths": { + "react-router": ["./index.ts"] + } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 318d5e6b4c..f73ce8eaaf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -559,9 +559,6 @@ importers: cookie: specifier: ^0.6.0 version: 0.6.0 - react-router: - specifier: workspace:* - version: 'link:' set-cookie-parser: specifier: ^2.6.0 version: 2.6.0 @@ -774,7 +771,7 @@ importers: version: 16.4.5 esbuild-register: specifier: ^3.3.2 - version: 3.5.0(esbuild@0.17.19) + version: 3.5.0(esbuild@0.19.12) execa: specifier: 5.1.1 version: 5.1.1 @@ -11696,10 +11693,10 @@ snapshots: is-date-object: 1.0.5 is-symbol: 1.0.4 - esbuild-register@3.5.0(esbuild@0.17.19): + esbuild-register@3.5.0(esbuild@0.19.12): dependencies: debug: 4.3.4 - esbuild: 0.17.19 + esbuild: 0.19.12 transitivePeerDependencies: - supports-color