Skip to content

Commit b579661

Browse files
authored
Support unstable_dataStrategy on staticHandler.queryRoute (#11515)
1 parent fdff9dd commit b579661

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.changeset/clever-pumas-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Support `unstable_dataStrategy` on `staticHandler.queryRoute`

packages/router/__tests__/ssr-test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,5 +2628,18 @@ describe("ssr", () => {
26282628

26292629
/* eslint-enable jest/no-conditional-expect */
26302630
});
2631+
2632+
describe("router dataStrategy", () => {
2633+
it("should apply a custom data strategy", async () => {
2634+
let { queryRoute } = createStaticHandler(SSR_ROUTES);
2635+
let data;
2636+
2637+
data = await queryRoute(createRequest("/custom"), {
2638+
unstable_dataStrategy: urlDataStrategy,
2639+
});
2640+
expect(data).toBeInstanceOf(URLSearchParams);
2641+
expect((data as URLSearchParams).get("foo")).toBe("bar");
2642+
});
2643+
});
26312644
});
26322645
});

packages/router/router.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ export interface StaticHandler {
412412
): Promise<StaticHandlerContext | Response>;
413413
queryRoute(
414414
request: Request,
415-
opts?: { routeId?: string; requestContext?: unknown }
415+
opts?: {
416+
routeId?: string;
417+
requestContext?: unknown;
418+
unstable_dataStrategy?: DataStrategyFunction;
419+
}
416420
): Promise<any>;
417421
}
418422

@@ -3099,7 +3103,12 @@ export function createStaticHandler(
30993103
{
31003104
routeId,
31013105
requestContext,
3102-
}: { requestContext?: unknown; routeId?: string } = {}
3106+
unstable_dataStrategy,
3107+
}: {
3108+
requestContext?: unknown;
3109+
routeId?: string;
3110+
unstable_dataStrategy?: DataStrategyFunction;
3111+
} = {}
31033112
): Promise<any> {
31043113
let url = new URL(request.url);
31053114
let method = request.method;
@@ -3132,7 +3141,7 @@ export function createStaticHandler(
31323141
location,
31333142
matches,
31343143
requestContext,
3135-
null,
3144+
unstable_dataStrategy || null,
31363145
false,
31373146
match
31383147
);

0 commit comments

Comments
 (0)