Skip to content

Commit 19ba686

Browse files
authored
Stabilize unstable_dataStrategy (#11969)
1 parent b3b1e58 commit 19ba686

File tree

13 files changed

+56
-51
lines changed

13 files changed

+56
-51
lines changed

.changeset/violet-beds-swim.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": minor
3+
---
4+
5+
Stabilize `unstable_dataStrategy`

integration/defer-loader-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ test.describe("deferred loaders", () => {
2828
`,
2929

3030
"app/routes/redirect.tsx": js`
31-
import { unstable_data } from 'react-router';
31+
import { data } from 'react-router';
3232
export function loader() {
33-
return unstable_data(
33+
return data(
3434
{ food: "pizza" },
3535
{
3636
status: 301,

integration/single-fetch-test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const files = {
110110
`,
111111

112112
"app/routes/data-with-response.tsx": js`
113-
import { useActionData, useLoaderData, unstable_data as data } from "react-router";
113+
import { useActionData, useLoaderData, data } from "react-router";
114114
115115
export function headers ({ actionHeaders, loaderHeaders, errorHeaders }) {
116116
if ([...actionHeaders].length > 0) {
@@ -253,7 +253,7 @@ test.describe("single-fetch", () => {
253253
});
254254
});
255255

256-
test("loads proper data (via unstable_data) on single fetch loader requests", async () => {
256+
test("loads proper data (via data()) on single fetch loader requests", async () => {
257257
let fixture = await createFixture({
258258
files,
259259
});
@@ -280,7 +280,7 @@ test.describe("single-fetch", () => {
280280
});
281281
});
282282

283-
test("loads proper data (via unstable_data) on single fetch action requests", async () => {
283+
test("loads proper data (via data()) on single fetch action requests", async () => {
284284
let fixture = await createFixture({
285285
files,
286286
});
@@ -505,28 +505,28 @@ test.describe("single-fetch", () => {
505505
expect(urls).toEqual([]);
506506
});
507507

508-
test("does not revalidate on 4xx/5xx action responses (via unstable_data)", async ({
508+
test("does not revalidate on 4xx/5xx action responses (via data())", async ({
509509
page,
510510
}) => {
511511
let fixture = await createFixture({
512512
files: {
513513
...files,
514514
"app/routes/action.tsx": js`
515-
import { Form, Link, useActionData, useLoaderData, useNavigation, unstable_data } from 'react-router';
515+
import { Form, Link, useActionData, useLoaderData, useNavigation, data } from 'react-router';
516516
517517
export async function action({ request }) {
518518
let fd = await request.formData();
519519
if (fd.get('throw') === "5xx") {
520-
throw unstable_data("Thrown 500", { status: 500 });
520+
throw data("Thrown 500", { status: 500 });
521521
}
522522
if (fd.get('throw') === "4xx") {
523-
throw unstable_data("Thrown 400", { status: 400 });
523+
throw data("Thrown 400", { status: 400 });
524524
}
525525
if (fd.get('return') === "5xx") {
526-
return unstable_data("Returned 500", { status: 500 });
526+
return data("Returned 500", { status: 500 });
527527
}
528528
if (fd.get('return') === "4xx") {
529-
return unstable_data("Returned 400", { status: 400 });
529+
return data("Returned 400", { status: 400 });
530530
}
531531
return null;
532532
}

packages/react-router/__tests__/data-memory-router-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ describe("createMemoryRouter", () => {
32923292
/>
32933293
</Route>
32943294
),
3295-
{ initialEntries: ["/foo"], unstable_dataStrategy: urlDataStrategy }
3295+
{ initialEntries: ["/foo"], dataStrategy: urlDataStrategy }
32963296
);
32973297
let { container } = render(<RouterProvider router={router} />);
32983298

packages/react-router/__tests__/router/ssr-test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ describe("ssr", () => {
14031403
let { query } = createStaticHandler(SSR_ROUTES);
14041404

14051405
let context = await query(createRequest("/custom"), {
1406-
unstable_dataStrategy: urlDataStrategy,
1406+
dataStrategy: urlDataStrategy,
14071407
});
14081408
expect(context).toMatchObject({
14091409
actionData: null,
@@ -2251,7 +2251,7 @@ describe("ssr", () => {
22512251
let data;
22522252

22532253
data = await queryRoute(createRequest("/custom"), {
2254-
unstable_dataStrategy: urlDataStrategy,
2254+
dataStrategy: urlDataStrategy,
22552255
});
22562256
expect(data).toBeInstanceOf(URLSearchParams);
22572257
expect((data as URLSearchParams).get("foo")).toBe("bar");

packages/react-router/__tests__/router/utils/data-router-setup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export function setup({
339339
routes: enhanceRoutes(routes),
340340
hydrationData,
341341
window: testWindow,
342-
unstable_dataStrategy: dataStrategy,
342+
dataStrategy: dataStrategy,
343343
});
344344

345345
let fetcherData = getFetcherData(currentRouter);

packages/react-router/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export type {
2323
export type {
2424
ActionFunction,
2525
ActionFunctionArgs,
26-
DataStrategyFunction as unstable_DataStrategyFunction,
27-
DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs,
28-
DataStrategyMatch as unstable_DataStrategyMatch,
29-
DataStrategyResult as unstable_DataStrategyResult,
26+
DataStrategyFunction,
27+
DataStrategyFunctionArgs,
28+
DataStrategyMatch,
29+
DataStrategyResult,
3030
DataWithResponseInit as UNSAFE_DataWithResponseInit,
3131
ErrorResponse,
3232
FormEncType,
@@ -58,7 +58,7 @@ export {
5858
IDLE_BLOCKER,
5959
} from "./lib/router/router";
6060
export {
61-
data as unstable_data,
61+
data,
6262
generatePath,
6363
isRouteErrorResponse,
6464
json,

packages/react-router/lib/components.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function createMemoryRouter(
144144
hydrationData?: HydrationState;
145145
initialEntries?: InitialEntry[];
146146
initialIndex?: number;
147-
unstable_dataStrategy?: DataStrategyFunction;
147+
dataStrategy?: DataStrategyFunction;
148148
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
149149
}
150150
): RemixRouter {
@@ -158,7 +158,7 @@ export function createMemoryRouter(
158158
hydrationData: opts?.hydrationData,
159159
routes,
160160
mapRouteProperties,
161-
unstable_dataStrategy: opts?.unstable_dataStrategy,
161+
dataStrategy: opts?.dataStrategy,
162162
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
163163
}).initialize();
164164
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function createHydratedRouter(): RemixRouter {
169169
basename: ssrInfo.context.basename,
170170
hydrationData,
171171
mapRouteProperties,
172-
unstable_dataStrategy: getSingleFetchDataStrategy(
172+
dataStrategy: getSingleFetchDataStrategy(
173173
ssrInfo.manifest,
174174
ssrInfo.routeModules,
175175
() => router

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ interface DOMRouterOpts {
122122
basename?: string;
123123
future?: Partial<FutureConfig>;
124124
hydrationData?: HydrationState;
125-
unstable_dataStrategy?: DataStrategyFunction;
125+
dataStrategy?: DataStrategyFunction;
126126
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
127127
window?: Window;
128128
}
@@ -141,7 +141,7 @@ export function createBrowserRouter(
141141
hydrationData: opts?.hydrationData || parseHydrationData(),
142142
routes,
143143
mapRouteProperties,
144-
unstable_dataStrategy: opts?.unstable_dataStrategy,
144+
dataStrategy: opts?.dataStrategy,
145145
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
146146
window: opts?.window,
147147
}).initialize();
@@ -161,7 +161,7 @@ export function createHashRouter(
161161
hydrationData: opts?.hydrationData || parseHydrationData(),
162162
routes,
163163
mapRouteProperties,
164-
unstable_dataStrategy: opts?.unstable_dataStrategy,
164+
dataStrategy: opts?.dataStrategy,
165165
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
166166
window: opts?.window,
167167
}).initialize();

packages/react-router/lib/dom/ssr/single-fetch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ async function singleFetchActionStrategy(
184184
return { [actionMatch.route.id]: result };
185185
}
186186

187-
// For non-responses, proxy along the statusCode via unstable_data()
187+
// For non-responses, proxy along the statusCode via data()
188188
// (most notably for skipping action error revalidation)
189189
return {
190190
[actionMatch.route.id]: {

packages/react-router/lib/router/router.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ export interface RouterInit {
369369
future?: Partial<FutureConfig>;
370370
hydrationData?: HydrationState;
371371
window?: Window;
372+
dataStrategy?: DataStrategyFunction;
372373
patchRoutesOnNavigation?: AgnosticPatchRoutesOnNavigationFunction;
373-
unstable_dataStrategy?: DataStrategyFunction;
374374
}
375375

376376
/**
@@ -399,15 +399,15 @@ export interface StaticHandler {
399399
opts?: {
400400
requestContext?: unknown;
401401
skipLoaderErrorBubbling?: boolean;
402-
unstable_dataStrategy?: DataStrategyFunction;
402+
dataStrategy?: DataStrategyFunction;
403403
}
404404
): Promise<StaticHandlerContext | Response>;
405405
queryRoute(
406406
request: Request,
407407
opts?: {
408408
routeId?: string;
409409
requestContext?: unknown;
410-
unstable_dataStrategy?: DataStrategyFunction;
410+
dataStrategy?: DataStrategyFunction;
411411
}
412412
): Promise<any>;
413413
}
@@ -808,7 +808,7 @@ export function createRouter(init: RouterInit): Router {
808808
);
809809
let inFlightDataRoutes: AgnosticDataRouteObject[] | undefined;
810810
let basename = init.basename || "/";
811-
let dataStrategyImpl = init.unstable_dataStrategy || defaultDataStrategy;
811+
let dataStrategyImpl = init.dataStrategy || defaultDataStrategy;
812812
let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
813813

814814
// Config driven behavior flags
@@ -3410,11 +3410,11 @@ export function createStaticHandler(
34103410
{
34113411
requestContext,
34123412
skipLoaderErrorBubbling,
3413-
unstable_dataStrategy,
3413+
dataStrategy,
34143414
}: {
34153415
requestContext?: unknown;
34163416
skipLoaderErrorBubbling?: boolean;
3417-
unstable_dataStrategy?: DataStrategyFunction;
3417+
dataStrategy?: DataStrategyFunction;
34183418
} = {}
34193419
): Promise<StaticHandlerContext | Response> {
34203420
let url = new URL(request.url);
@@ -3464,7 +3464,7 @@ export function createStaticHandler(
34643464
location,
34653465
matches,
34663466
requestContext,
3467-
unstable_dataStrategy || null,
3467+
dataStrategy || null,
34683468
skipLoaderErrorBubbling === true,
34693469
null
34703470
);
@@ -3509,11 +3509,11 @@ export function createStaticHandler(
35093509
{
35103510
routeId,
35113511
requestContext,
3512-
unstable_dataStrategy,
3512+
dataStrategy,
35133513
}: {
35143514
requestContext?: unknown;
35153515
routeId?: string;
3516-
unstable_dataStrategy?: DataStrategyFunction;
3516+
dataStrategy?: DataStrategyFunction;
35173517
} = {}
35183518
): Promise<any> {
35193519
let url = new URL(request.url);
@@ -3547,7 +3547,7 @@ export function createStaticHandler(
35473547
location,
35483548
matches,
35493549
requestContext,
3550-
unstable_dataStrategy || null,
3550+
dataStrategy || null,
35513551
false,
35523552
match
35533553
);
@@ -3582,7 +3582,7 @@ export function createStaticHandler(
35823582
location: Location,
35833583
matches: AgnosticDataRouteMatch[],
35843584
requestContext: unknown,
3585-
unstable_dataStrategy: DataStrategyFunction | null,
3585+
dataStrategy: DataStrategyFunction | null,
35863586
skipLoaderErrorBubbling: boolean,
35873587
routeMatch: AgnosticDataRouteMatch | null
35883588
): Promise<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
@@ -3598,7 +3598,7 @@ export function createStaticHandler(
35983598
matches,
35993599
routeMatch || getTargetMatch(matches, location),
36003600
requestContext,
3601-
unstable_dataStrategy,
3601+
dataStrategy,
36023602
skipLoaderErrorBubbling,
36033603
routeMatch != null
36043604
);
@@ -3609,7 +3609,7 @@ export function createStaticHandler(
36093609
request,
36103610
matches,
36113611
requestContext,
3612-
unstable_dataStrategy,
3612+
dataStrategy,
36133613
skipLoaderErrorBubbling,
36143614
routeMatch
36153615
);
@@ -3644,7 +3644,7 @@ export function createStaticHandler(
36443644
matches: AgnosticDataRouteMatch[],
36453645
actionMatch: AgnosticDataRouteMatch,
36463646
requestContext: unknown,
3647-
unstable_dataStrategy: DataStrategyFunction | null,
3647+
dataStrategy: DataStrategyFunction | null,
36483648
skipLoaderErrorBubbling: boolean,
36493649
isRouteRequest: boolean
36503650
): Promise<Omit<StaticHandlerContext, "location" | "basename"> | Response> {
@@ -3671,7 +3671,7 @@ export function createStaticHandler(
36713671
matches,
36723672
isRouteRequest,
36733673
requestContext,
3674-
unstable_dataStrategy
3674+
dataStrategy
36753675
);
36763676
result = results[actionMatch.route.id];
36773677

@@ -3731,7 +3731,7 @@ export function createStaticHandler(
37313731
loaderRequest,
37323732
matches,
37333733
requestContext,
3734-
unstable_dataStrategy,
3734+
dataStrategy,
37353735
skipLoaderErrorBubbling,
37363736
null,
37373737
[boundaryMatch.route.id, result]
@@ -3756,7 +3756,7 @@ export function createStaticHandler(
37563756
loaderRequest,
37573757
matches,
37583758
requestContext,
3759-
unstable_dataStrategy,
3759+
dataStrategy,
37603760
skipLoaderErrorBubbling,
37613761
null
37623762
);
@@ -3778,7 +3778,7 @@ export function createStaticHandler(
37783778
request: Request,
37793779
matches: AgnosticDataRouteMatch[],
37803780
requestContext: unknown,
3781-
unstable_dataStrategy: DataStrategyFunction | null,
3781+
dataStrategy: DataStrategyFunction | null,
37823782
skipLoaderErrorBubbling: boolean,
37833783
routeMatch: AgnosticDataRouteMatch | null,
37843784
pendingActionResult?: PendingActionResult
@@ -3840,7 +3840,7 @@ export function createStaticHandler(
38403840
matches,
38413841
isRouteRequest,
38423842
requestContext,
3843-
unstable_dataStrategy
3843+
dataStrategy
38443844
);
38453845

38463846
if (request.signal.aborted) {
@@ -3880,10 +3880,10 @@ export function createStaticHandler(
38803880
matches: AgnosticDataRouteMatch[],
38813881
isRouteRequest: boolean,
38823882
requestContext: unknown,
3883-
unstable_dataStrategy: DataStrategyFunction | null
3883+
dataStrategy: DataStrategyFunction | null
38843884
): Promise<Record<string, DataResult>> {
38853885
let results = await callDataStrategyImpl(
3886-
unstable_dataStrategy || defaultDataStrategy,
3886+
dataStrategy || defaultDataStrategy,
38873887
type,
38883888
null,
38893889
request,
@@ -4867,7 +4867,7 @@ async function convertDataStrategyResultToDataResult(
48674867
};
48684868
}
48694869

4870-
// Convert thrown unstable_data() to ErrorResponse instances
4870+
// Convert thrown data() to ErrorResponse instances
48714871
result = new ErrorResponseImpl(
48724872
result.init?.status || 500,
48734873
undefined,

0 commit comments

Comments
 (0)