Skip to content

Commit

Permalink
Support unstable_dataStrategy on staticHandler.queryRoute (#11515)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Apr 30, 2024
1 parent fdff9dd commit b579661
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-pumas-arrive.md
@@ -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
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
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

0 comments on commit b579661

Please sign in to comment.