Skip to content

Cleanup imports/exports in consolidated react-router package #11840

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

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .changeset/gold-suns-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
"react-router": major
---

Imports/Exports cleanup

- Removed the following exports that were previously public API from `@remix-run/router`
- types
- `AgnosticDataIndexRouteObject`
- `AgnosticDataNonIndexRouteObject`
- `AgnosticDataRouteMatch`
- `AgnosticDataRouteObject`
- `AgnosticIndexRouteObject`
- `AgnosticNonIndexRouteObject`
- `AgnosticRouteMatch`
- `AgnosticRouteObject`
- `TrackedPromise`
- `unstable_AgnosticPatchRoutesOnMissFunction`
- `Action` -> exported as `NavigationType` via `react-router`
- `Router` exported as `RemixRouter` to differentiate from RR's `<Router>`
- API
- `getToPathname` (`@private`)
- `joinPaths` (`@private`)
- `normalizePathname` (`@private`)
- `resolveTo` (`@private`)
- `stripBasename` (`@private`)
- `createBrowserHistory` -> in favor of `createBrowserRouter`
- `createHashHistory` -> in favor of `createHashRouter`
- `createMemoryHistory` -> in favor of `createMemoryRouter`
- `createRouter`
- `createStaticHandler` -> in favor of wrapper `createStaticHandler` in RR Dom
- `getStaticContextFromError`
- Removed the following exports that were previously public API from `react-router`
- `Hash`
- `Pathname`
- `Search`
1 change: 0 additions & 1 deletion packages/react-router-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ export async function resolveReactRouterConfig({
basename,
buildDirectory: userBuildDirectory,
buildEnd,
future: userFuture,
ignoredRouteFiles,
routes: userRoutesFunction,
prerender: prerenderConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dev/config/flatRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export function getRouteSegments(routeId: string): [string[], string[]] {
rawRouteSegment += char;
break;
}
if (!routeSegment && char == paramPrefixChar) {
if (!routeSegment && char === paramPrefixChar) {
if (index === routeId.length) {
routeSegment += "*";
rawRouteSegment += char;
Expand Down
233 changes: 2 additions & 231 deletions packages/react-router-dom/index.ts
Original file line number Diff line number Diff line change
@@ -1,231 +1,2 @@
let alreadyWarned = false;

if (!alreadyWarned && typeof console !== "undefined") {
alreadyWarned = true;
console.warn(
"The `react-router-dom` package is deprecated in v7, you can change all " +
"of your imports to load directly from the `react-router` package."
);
}

export type {
ActionFunction,
ActionFunctionArgs,
AwaitProps,
DataRouteMatch,
DataRouteObject,
unstable_DataStrategyFunction,
unstable_DataStrategyFunctionArgs,
unstable_DataStrategyMatch,
ErrorResponse,
Fetcher,
Hash,
IndexRouteObject,
IndexRouteProps,
JsonFunction,
LayoutRouteProps,
LazyRouteFunction,
LoaderFunction,
LoaderFunctionArgs,
Location,
MemoryRouterProps,
NavigateFunction,
NavigateOptions,
NavigateProps,
Navigation,
Navigator,
NonIndexRouteObject,
OutletProps,
ParamParseKey,
Params,
Path,
PathMatch,
PathParam,
PathPattern,
PathRouteProps,
Pathname,
RedirectFunction,
RelativeRoutingType,
RouteMatch,
RouteObject,
RouteProps,
RouterProps,
RouterProviderProps,
RoutesProps,
Search,
ShouldRevalidateFunction,
ShouldRevalidateFunctionArgs,
To,
UIMatch,
Blocker,
BlockerFunction,
unstable_HandlerResult,
AgnosticDataIndexRouteObject,
AgnosticDataNonIndexRouteObject,
AgnosticDataRouteMatch,
AgnosticDataRouteObject,
AgnosticIndexRouteObject,
AgnosticNonIndexRouteObject,
AgnosticRouteMatch,
AgnosticRouteObject,
HydrationState,
InitialEntry,
StaticHandler,
TrackedPromise,
FormEncType,
FormMethod,
GetScrollRestorationKeyFunction,
StaticHandlerContext,
BrowserRouterProps,
HashRouterProps,
HistoryRouterProps,
LinkProps,
NavLinkProps,
FetcherFormProps,
FormProps,
ScrollRestorationProps,
SetURLSearchParams,
SubmitFunction,
FetcherSubmitFunction,
FetcherWithComponents,
ParamKeyValuePair,
SubmitOptions,
URLSearchParamsInit,
StaticRouterProps,
StaticRouterProviderProps,
HtmlLinkDescriptor,
ClientActionFunction,
ClientActionFunctionArgs,
ClientLoaderFunction,
ClientLoaderFunctionArgs,
MetaArgs,
MetaDescriptor,
MetaFunction,
ServerRouterProps,
RoutesTestStubProps,
} from "react-router";

export {
Await,
MemoryRouter,
Navigate,
NavigationType,
Outlet,
Route,
Router,
RouterProvider,
Routes,
createMemoryRouter,
createPath,
createRoutesFromChildren,
createRoutesFromChildren as createRoutesFromElements,
generatePath,
isRouteErrorResponse,
json,
matchPath,
matchRoutes,
parsePath,
redirect,
redirectDocument,
renderMatches,
resolvePath,
useBlocker,
useActionData,
useAsyncError,
useAsyncValue,
useHref,
useInRouterContext,
useLoaderData,
useLocation,
useMatch,
useMatches,
useNavigate,
useNavigation,
useNavigationType,
useOutlet,
useOutletContext,
useParams,
useResolvedPath,
useRevalidator,
useRouteError,
useRouteLoaderData,
useRoutes,
getStaticContextFromError,
stripBasename,
UNSAFE_convertRoutesToDataRoutes,
createBrowserRouter,
createHashRouter,
BrowserRouter,
HashRouter,
Link,
UNSAFE_ViewTransitionContext,
UNSAFE_FetchersContext,
unstable_HistoryRouter,
NavLink,
Form,
ScrollRestoration,
useLinkClickHandler,
useSearchParams,
useSubmit,
useFormAction,
useFetcher,
useFetchers,
UNSAFE_useScrollRestoration,
useBeforeUnload,
unstable_usePrompt,
unstable_useViewTransitionState,
createSearchParams,
createStaticHandler,
createStaticRouter,
StaticRouter,
StaticRouterProvider,
HydratedRouter,
Meta,
Links,
Scripts,
PrefetchPageLinks,
ServerRouter,
createRoutesStub,
} from "react-router";

///////////////////////////////////////////////////////////////////////////////
// DANGER! PLEASE READ ME!
// We provide these exports as an escape hatch in the event that you need any
// routing data that we don't provide an explicit API for. With that said, we
// want to cover your use case if we can, so if you feel the need to use these
// we want to hear from you. Let us know what you're building and we'll do our
// best to make sure we can support you!
//
// We consider these exports an implementation detail and do not guarantee
// against any breaking changes, regardless of the semver release. Use with
// extreme caution and only if you understand the consequences. Godspeed.
///////////////////////////////////////////////////////////////////////////////

/** @internal */
export type {
UNSAFE_RouteModules,
UNSAFE_FutureConfig,
UNSAFE_AssetsManifest,
UNSAFE_FrameworkContextObject,
UNSAFE_EntryRoute,
UNSAFE_RouteManifest,
UNSAFE_SingleFetchRedirectResult,
UNSAFE_SingleFetchResult,
UNSAFE_SingleFetchResults,
} from "react-router";

/** @internal */
export {
UNSAFE_DataRouterContext,
UNSAFE_DataRouterStateContext,
UNSAFE_LocationContext,
UNSAFE_NavigationContext,
UNSAFE_RouteContext,
UNSAFE_mapRouteProperties,
UNSAFE_useRouteId,
UNSAFE_useRoutesImpl,
UNSAFE_ErrorResponseImpl,
UNSAFE_FrameworkContext as UNSAFE_RemixContext,
UNSAFE_decodeViaTurboStream,
UNSAFE_SingleFetchRedirectSymbol,
} from "react-router";
export type * from "react-router";
export * from "react-router";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't export individually - just export everything from react-router

6 changes: 4 additions & 2 deletions packages/react-router/__tests__/router/browser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import { JSDOM } from "jsdom";

import type { BrowserHistory } from "../../lib/router";
import { createBrowserHistory } from "../../lib/router";
import {
type BrowserHistory,
createBrowserHistory,
} from "../../lib/router/history";
Comment on lines +5 to +8
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All router imports come from the source files, no more lib/router/index.ts barrel file to re-export


import InitialLocationDefaultKey from "./TestSequences/InitialLocationDefaultKey";
import Listen from "./TestSequences/Listen";
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/__tests__/router/create-path-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPath } from "../../lib/router";
import { createPath } from "../../lib/router/history";

describe("createPath", () => {
describe("given only a pathname", () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/react-router/__tests__/router/data-strategy-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
unstable_DataStrategyFunction as DataStrategyFunction,
unstable_DataStrategyMatch as DataStrategyMatch,
} from "../../lib/router";
import { json } from "../../lib/router";
DataStrategyFunction,
DataStrategyMatch,
} from "../../lib/router/utils";
import { json } from "../../lib/router/utils";
import { createDeferred, setup } from "./utils/data-router-setup";
import { createFormData, tick } from "./utils/utils";

Expand Down
8 changes: 4 additions & 4 deletions packages/react-router/__tests__/router/fetchers-test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable jest/valid-title */
import type { HydrationState } from "../../lib/router";
import type { HydrationState } from "../../lib/router/router";
import { createMemoryHistory } from "../../lib/router/history";
import {
createMemoryHistory,
createRouter,
IDLE_FETCHER,
IDLE_NAVIGATION,
UNSAFE_ErrorResponseImpl as ErrorResponseImpl,
} from "../../lib/router";
} from "../../lib/router/router";
import { ErrorResponseImpl } from "../../lib/router/utils";

import {
cleanup,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/router/hash-base-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSDOM } from "jsdom";

import type { HashHistory } from "../../lib/router";
import { createHashHistory } from "../../lib/router";
import type { HashHistory } from "../../lib/router/history";
import { createHashHistory } from "../../lib/router/history";

describe("a hash history on a page with a <base> tag", () => {
let history: HashHistory;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/router/hash-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import { JSDOM } from "jsdom";

import type { HashHistory } from "../../lib/router";
import { createHashHistory } from "../../lib/router";
import type { HashHistory } from "../../lib/router/history";
import { createHashHistory } from "../../lib/router/history";

import Listen from "./TestSequences/Listen";
import InitialLocationDefaultKey from "./TestSequences/InitialLocationDefaultKey";
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/router/interruptions-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jest/valid-title */
import type { HydrationState } from "../../lib/router";
import { IDLE_NAVIGATION } from "../../lib/router";
import type { HydrationState } from "../../lib/router/router";
import { IDLE_NAVIGATION } from "../../lib/router/router";
import { cleanup, setup } from "./utils/data-router-setup";
import { createFormData } from "./utils/utils";

Expand Down
6 changes: 4 additions & 2 deletions packages/react-router/__tests__/router/lazy-discovery-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { AgnosticDataRouteObject, Router } from "../../lib/router/index";
import { createMemoryHistory, createRouter } from "../../lib/router/index";
import type { Router } from "../../lib/router/router";
import type { AgnosticDataRouteObject } from "../../lib/router/utils";
import { createMemoryHistory } from "../../lib/router/history";
import { createRouter } from "../../lib/router/router";
import { ErrorResponseImpl } from "../../lib/router/utils";
import { getFetcherData } from "./utils/data-router-setup";
import { createDeferred, createFormData, tick } from "./utils/utils";
Expand Down
9 changes: 3 additions & 6 deletions packages/react-router/__tests__/router/lazy-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
createMemoryHistory,
createRouter,
createStaticHandler,
json,
} from "../../lib/router";
import { createMemoryHistory } from "../../lib/router/history";
import { createRouter, createStaticHandler } from "../../lib/router/router";
import { json } from "../../lib/router/utils";

import type { TestRouteObject } from "./utils/data-router-setup";
import { cleanup, createDeferred, setup } from "./utils/data-router-setup";
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/__tests__/router/memory-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable jest/expect-expect */

import type { MemoryHistory } from "../../lib/router";
import { createMemoryHistory } from "../../lib/router";
import type { MemoryHistory } from "../../lib/router/history";
import { createMemoryHistory } from "../../lib/router/history";

import Listen from "./TestSequences/Listen";
import InitialLocationHasKey from "./TestSequences/InitialLocationHasKey";
Expand Down
Loading