Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/clever-pumas-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Support `unstable_dataStrategy` on `staticHandler.queryRoute`
13 changes: 13 additions & 0 deletions packages/router/__tests__/ssr-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2628,5 +2628,18 @@ describe("ssr", () => {

/* eslint-enable jest/no-conditional-expect */
});

describe("router dataStrategy", () => {
it("should apply a custom data strategy", async () => {
let { queryRoute } = createStaticHandler(SSR_ROUTES);
let data;

data = await queryRoute(createRequest("/custom"), {
unstable_dataStrategy: urlDataStrategy,
});
expect(data).toBeInstanceOf(URLSearchParams);
expect((data as URLSearchParams).get("foo")).toBe("bar");
});
});
});
});
15 changes: 12 additions & 3 deletions packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ export interface StaticHandler {
): Promise<StaticHandlerContext | Response>;
queryRoute(
request: Request,
opts?: { routeId?: string; requestContext?: unknown }
opts?: {
routeId?: string;
requestContext?: unknown;
unstable_dataStrategy?: DataStrategyFunction;
}
): Promise<any>;
}

Expand Down Expand Up @@ -3099,7 +3103,12 @@ export function createStaticHandler(
{
routeId,
requestContext,
}: { requestContext?: unknown; routeId?: string } = {}
unstable_dataStrategy,
}: {
requestContext?: unknown;
routeId?: string;
unstable_dataStrategy?: DataStrategyFunction;
} = {}
): Promise<any> {
let url = new URL(request.url);
let method = request.method;
Expand Down Expand Up @@ -3132,7 +3141,7 @@ export function createStaticHandler(
location,
matches,
requestContext,
null,
unstable_dataStrategy || null,
false,
match
);
Expand Down