Skip to content

Commit 111d9d5

Browse files
authored
rename RemixContext -> FrameworkContext (#11705)
1 parent dcd64b5 commit 111d9d5

File tree

12 files changed

+68
-55
lines changed

12 files changed

+68
-55
lines changed

.changeset/odd-beds-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": major
3+
---
4+
5+
renamed RemixContext to FrameworkContext

packages/react-router-dom/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export type {
212212
UNSAFE_RouteModules,
213213
UNSAFE_FutureConfig,
214214
UNSAFE_AssetsManifest,
215-
UNSAFE_RemixContextObject,
215+
UNSAFE_FrameworkContextObject,
216216
UNSAFE_EntryRoute,
217217
UNSAFE_RouteManifest,
218218
UNSAFE_SingleFetchRedirectResult,
@@ -231,7 +231,7 @@ export {
231231
UNSAFE_useRouteId,
232232
UNSAFE_useRoutesImpl,
233233
UNSAFE_ErrorResponseImpl,
234-
UNSAFE_RemixContext,
234+
UNSAFE_FrameworkContext as UNSAFE_RemixContext,
235235
UNSAFE_decodeViaTurboStream,
236236
UNSAFE_SingleFetchRedirectSymbol,
237237
} from "react-router";

packages/react-router/__tests__/dom/scroll-restoration-test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
ScrollRestoration,
1212
createBrowserRouter,
1313
} from "../../index";
14-
import type { RemixContextObject } from "../../lib/dom/ssr/entry";
14+
import type { FrameworkContextObject } from "../../lib/dom/ssr/entry";
1515
import { createMemoryRouter, redirect } from "react-router";
16-
import { RemixContext, Scripts } from "../../lib/dom/ssr/components";
16+
import { FrameworkContext, Scripts } from "../../lib/dom/ssr/components";
1717
import "@testing-library/jest-dom/extend-expect";
1818

1919
describe(`ScrollRestoration`, () => {
@@ -207,7 +207,7 @@ describe(`ScrollRestoration`, () => {
207207
window.scrollTo = scrollTo;
208208
});
209209

210-
let context: RemixContextObject = {
210+
let context: FrameworkContextObject = {
211211
future: {
212212
v3_fetcherPersist: false,
213213
v3_relativeSplatPath: false,
@@ -245,9 +245,9 @@ describe(`ScrollRestoration`, () => {
245245
]);
246246

247247
render(
248-
<RemixContext.Provider value={context}>
248+
<FrameworkContext.Provider value={context}>
249249
<RouterProvider router={router} />
250-
</RemixContext.Provider>
250+
</FrameworkContext.Provider>
251251
);
252252
let script = screen.getByTestId("scroll-script");
253253
expect(script instanceof HTMLScriptElement).toBe(true);
@@ -272,9 +272,9 @@ describe(`ScrollRestoration`, () => {
272272
},
273273
]);
274274
render(
275-
<RemixContext.Provider value={context}>
275+
<FrameworkContext.Provider value={context}>
276276
<RouterProvider router={router} />
277-
</RemixContext.Provider>
277+
</FrameworkContext.Provider>
278278
);
279279
let script = screen.getByTestId("scroll-script");
280280
expect(script).toHaveAttribute("nonce", "hello");
@@ -298,9 +298,9 @@ describe(`ScrollRestoration`, () => {
298298
]);
299299
router.state.restoreScrollPosition = 20;
300300
render(
301-
<RemixContext.Provider value={context}>
301+
<FrameworkContext.Provider value={context}>
302302
<RouterProvider router={router} />
303-
</RemixContext.Provider>
303+
</FrameworkContext.Provider>
304304
);
305305

306306
expect(scrollToMock).toHaveBeenCalledWith(0, 20);
@@ -322,9 +322,9 @@ describe(`ScrollRestoration`, () => {
322322
},
323323
]);
324324
render(
325-
<RemixContext.Provider value={context}>
325+
<FrameworkContext.Provider value={context}>
326326
<RouterProvider router={router} />
327-
</RemixContext.Provider>
327+
</FrameworkContext.Provider>
328328
);
329329
// Always called when using <ScrollRestoration />
330330
expect(scrollToMock).toHaveBeenCalledWith(0, 0);

packages/react-router/__tests__/dom/ssr/components-test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
RouterProvider,
1111
} from "../../../index";
1212
import { HydratedRouter } from "../../../lib/dom/ssr/browser";
13-
import { RemixContext } from "../../../lib/dom/ssr/components";
13+
import { FrameworkContext } from "../../../lib/dom/ssr/components";
1414
import invariant from "../../../lib/dom/ssr/invariant";
1515
import { ServerRouter } from "../../../lib/dom/ssr/server";
1616
import "@testing-library/jest-dom/extend-expect";
@@ -70,9 +70,9 @@ function itPrefetchesPageLinks<
7070
});
7171

7272
let { container, unmount } = render(
73-
<RemixContext.Provider value={context}>
73+
<FrameworkContext.Provider value={context}>
7474
<RouterProvider router={router} />
75-
</RemixContext.Provider>
75+
</FrameworkContext.Provider>
7676
);
7777

7878
fireEvent[event](container.firstChild);
@@ -122,9 +122,9 @@ function itPrefetchesPageLinks<
122122
});
123123

124124
let { container, unmount } = render(
125-
<RemixContext.Provider value={context}>
125+
<FrameworkContext.Provider value={context}>
126126
<RouterProvider router={router} />
127-
</RemixContext.Provider>
127+
</FrameworkContext.Provider>
128128
);
129129

130130
fireEvent[event](container.firstChild);

packages/react-router/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export {
493493
};
494494

495495
/** @internal */
496-
export { RemixContext as UNSAFE_RemixContext } from "./lib/dom/ssr/components";
496+
export { FrameworkContext as UNSAFE_FrameworkContext } from "./lib/dom/ssr/components";
497497

498498
/** @internal */
499499
export type { RouteModules as UNSAFE_RouteModules } from "./lib/dom/ssr/routeModules";
@@ -502,7 +502,7 @@ export type { RouteModules as UNSAFE_RouteModules } from "./lib/dom/ssr/routeMod
502502
export type {
503503
FutureConfig as UNSAFE_FutureConfig,
504504
AssetsManifest as UNSAFE_AssetsManifest,
505-
RemixContextObject as UNSAFE_RemixContextObject,
505+
FrameworkContextObject as UNSAFE_FrameworkContextObject,
506506
} from "./lib/dom/ssr/entry";
507507

508508
/** @internal */

packages/react-router/lib/dom/lib.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import {
5555
import type { PrefetchBehavior, ScriptsProps } from "./ssr/components";
5656
import {
5757
PrefetchPageLinks,
58-
RemixContext,
58+
FrameworkContext,
5959
mergeRefs,
6060
usePrefetchBehavior,
6161
} from "./ssr/components";
@@ -1544,7 +1544,7 @@ export function ScrollRestoration({
15441544
storageKey,
15451545
...props
15461546
}: ScrollRestorationProps) {
1547-
let remixContext = React.useContext(RemixContext);
1547+
let remixContext = React.useContext(FrameworkContext);
15481548
let { basename } = React.useContext(NavigationContext);
15491549
let location = useLocation();
15501550
let matches = useMatches();

packages/react-router/lib/dom/ssr/browser.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
decodeViaTurboStream,
1919
getSingleFetchDataStrategy,
2020
} from "./single-fetch";
21-
import { RemixContext } from "./components";
21+
import { FrameworkContext } from "./components";
2222
import { RemixErrorBoundary } from "./errorBoundaries";
2323

2424
type SSRInfo = {
@@ -246,7 +246,7 @@ export function HydratedRouter() {
246246
// This fragment is important to ensure we match the <ServerRouter> JSX
247247
// structure so that useId values hydrate correctly
248248
<>
249-
<RemixContext.Provider
249+
<FrameworkContext.Provider
250250
value={{
251251
manifest: ssrInfo.manifest,
252252
routeModules: ssrInfo.routeModules,
@@ -262,7 +262,7 @@ export function HydratedRouter() {
262262
future={{ v7_startTransition: true }}
263263
/>
264264
</RemixErrorBoundary>
265-
</RemixContext.Provider>
265+
</FrameworkContext.Provider>
266266
{/*
267267
This fragment is important to ensure we match the <ServerRouter> JSX
268268
structure so that useId values hydrate correctly

packages/react-router/lib/dom/ssr/components.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type RouterState,
1111
} from "../../router";
1212

13-
import type { RemixContextObject } from "./entry";
13+
import type { FrameworkContextObject } from "./entry";
1414
import invariant from "./invariant";
1515
import {
1616
getKeyedLinksForMatches,
@@ -53,16 +53,19 @@ function useDataRouterStateContext() {
5353
}
5454

5555
////////////////////////////////////////////////////////////////////////////////
56-
// RemixContext
56+
// FrameworkContext
5757

58-
export const RemixContext = React.createContext<RemixContextObject | undefined>(
59-
undefined
60-
);
61-
RemixContext.displayName = "Remix";
58+
export const FrameworkContext = React.createContext<
59+
FrameworkContextObject | undefined
60+
>(undefined);
61+
FrameworkContext.displayName = "FrameworkContext";
6262

63-
export function useRemixContext(): RemixContextObject {
64-
let context = React.useContext(RemixContext);
65-
invariant(context, "You must render this element inside a <Remix> element");
63+
export function useFrameworkContext(): FrameworkContextObject {
64+
let context = React.useContext(FrameworkContext);
65+
invariant(
66+
context,
67+
"You must render this element inside a <HydratedRouter> element"
68+
);
6669
return context;
6770
}
6871

@@ -91,7 +94,7 @@ export function usePrefetchBehavior<T extends HTMLAnchorElement>(
9194
prefetch: PrefetchBehavior,
9295
theirElementProps: PrefetchHandlers
9396
): [boolean, React.RefObject<T>, PrefetchHandlers] {
94-
let remixContext = React.useContext(RemixContext);
97+
let frameworkContext = React.useContext(FrameworkContext);
9598
let [maybePrefetch, setMaybePrefetch] = React.useState(false);
9699
let [shouldPrefetch, setShouldPrefetch] = React.useState(false);
97100
let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } =
@@ -139,8 +142,8 @@ export function usePrefetchBehavior<T extends HTMLAnchorElement>(
139142
setShouldPrefetch(false);
140143
};
141144

142-
// No prefetching if not using Remix-style SSR
143-
if (!remixContext) {
145+
// No prefetching if not using SSR
146+
if (!frameworkContext) {
144147
return [false, ref, {}];
145148
}
146149

@@ -219,7 +222,8 @@ function getActiveMatches(
219222
@category Components
220223
*/
221224
export function Links() {
222-
let { isSpaMode, manifest, routeModules, criticalCss } = useRemixContext();
225+
let { isSpaMode, manifest, routeModules, criticalCss } =
226+
useFrameworkContext();
223227
let { errors, matches: routerMatches } = useDataRouterStateContext();
224228

225229
let matches = getActiveMatches(routerMatches, errors, isSpaMode);
@@ -279,7 +283,7 @@ export function PrefetchPageLinks({
279283
}
280284

281285
function useKeyedPrefetchLinks(matches: AgnosticDataRouteMatch[]) {
282-
let { manifest, routeModules } = useRemixContext();
286+
let { manifest, routeModules } = useFrameworkContext();
283287

284288
let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React.useState<
285289
KeyedHtmlLinkDescriptor[]
@@ -312,7 +316,7 @@ function PrefetchPageLinksImpl({
312316
matches: AgnosticDataRouteMatch[];
313317
}) {
314318
let location = useLocation();
315-
let { manifest, routeModules } = useRemixContext();
319+
let { manifest, routeModules } = useFrameworkContext();
316320
let { matches } = useDataRouterStateContext();
317321

318322
let newMatchesForData = React.useMemo(
@@ -412,7 +416,7 @@ function PrefetchPageLinksImpl({
412416
@category Components
413417
*/
414418
export function Meta() {
415-
let { isSpaMode, routeModules } = useRemixContext();
419+
let { isSpaMode, routeModules } = useFrameworkContext();
416420
let {
417421
errors,
418422
matches: routerMatches,
@@ -545,7 +549,7 @@ function isValidMetaTag(tagName: unknown): tagName is "meta" | "link" {
545549
}
546550

547551
/**
548-
* Tracks whether Remix has finished hydrating or not, so scripts can be skipped
552+
* Tracks whether hydration is finished, so scripts can be skipped
549553
* during client-side updates.
550554
*/
551555
let isHydrated = false;
@@ -596,7 +600,7 @@ export type ScriptsProps = Omit<
596600
*/
597601
export function Scripts(props: ScriptsProps) {
598602
let { manifest, serverHandoffString, isSpaMode, renderMeta } =
599-
useRemixContext();
603+
useFrameworkContext();
600604
let { router, static: isStatic, staticContext } = useDataRouterContext();
601605
let { matches: routerMatches } = useDataRouterStateContext();
602606
let navigation = useNavigation();

packages/react-router/lib/dom/ssr/entry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type SerializedError = {
99
message: string;
1010
stack?: string;
1111
};
12-
export interface RemixContextObject {
12+
export interface FrameworkContextObject {
1313
manifest: AssetsManifest;
1414
routeModules: RouteModules;
1515
criticalCss?: string;
@@ -35,7 +35,7 @@ export interface RemixContextObject {
3535

3636
// Additional React-Router information needed at runtime, but not hydrated
3737
// through RemixContext
38-
export interface EntryContext extends RemixContextObject {
38+
export interface EntryContext extends FrameworkContextObject {
3939
staticHandlerContext: StaticHandlerContext;
4040
serverHandoffStream?: ReadableStream<Uint8Array>;
4141
}

packages/react-router/lib/dom/ssr/errorBoundaries.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from "react";
22

3-
import { Scripts, useRemixContext } from "./components";
3+
import { Scripts, useFrameworkContext } from "./components";
44
import type { Location } from "../../router/history";
55
import { isRouteErrorResponse } from "../../router/utils";
66

@@ -129,7 +129,7 @@ export function BoundaryShell({
129129
renderScripts?: boolean;
130130
children: React.ReactNode | React.ReactNode[];
131131
}) {
132-
let { routeModules } = useRemixContext();
132+
let { routeModules } = useFrameworkContext();
133133

134134
if (routeModules.root?.Layout) {
135135
return children;

packages/react-router/lib/dom/ssr/routes-test-stub.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ import type { LinksFunction, MetaFunction, RouteModules } from "./routeModules";
1414
import type { InitialEntry } from "../../router/history";
1515
import type { HydrationState } from "../../router/router";
1616
import { convertRoutesToDataRoutes } from "../../router/utils";
17-
import type { AssetsManifest, FutureConfig, RemixContextObject } from "./entry";
17+
import type {
18+
AssetsManifest,
19+
FutureConfig,
20+
FrameworkContextObject,
21+
} from "./entry";
1822
import { Outlet, createMemoryRouter } from "../../components";
1923
import type { EntryRoute } from "./routes";
20-
import { RemixContext } from "./components";
24+
import { FrameworkContext } from "./components";
2125
import { RouterProvider } from "../lib";
2226

2327
interface StubIndexRouteObject
@@ -97,7 +101,7 @@ export function createRoutesStub(
97101
future,
98102
}: RoutesTestStubProps) {
99103
let routerRef = React.useRef<ReturnType<typeof createMemoryRouter>>();
100-
let remixContextRef = React.useRef<RemixContextObject>();
104+
let remixContextRef = React.useRef<FrameworkContextObject>();
101105

102106
if (routerRef.current == null) {
103107
remixContextRef.current = {
@@ -133,9 +137,9 @@ export function createRoutesStub(
133137
}
134138

135139
return (
136-
<RemixContext.Provider value={remixContextRef.current}>
140+
<FrameworkContext.Provider value={remixContextRef.current}>
137141
<RouterProvider router={routerRef.current} />
138-
</RemixContext.Provider>
142+
</FrameworkContext.Provider>
139143
);
140144
};
141145
}

0 commit comments

Comments
 (0)