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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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();

0 commit comments

Comments
 (0)