diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index c18b2950..8c5d7724 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -550,7 +550,8 @@ function _walkInner( const partialErrorMessage = `Unable to process partial response.`; -async function fetchPartials(url: URL, init?: RequestInit) { +async function fetchPartials(url: URL, init: RequestInit = {}) { + init.redirect = "follow"; url.searchParams.set(PARTIAL_SEARCH_PARAM, "true"); const res = await fetch(url, init); await applyPartials(res); diff --git a/tests/fixture_partials/fresh.gen.ts b/tests/fixture_partials/fresh.gen.ts index 82abfd95..6a7c7a51 100644 --- a/tests/fixture_partials/fresh.gen.ts +++ b/tests/fixture_partials/fresh.gen.ts @@ -106,6 +106,10 @@ import * as $no_partial_response_index from "./routes/no_partial_response/index. import * as $no_partial_response_injected from "./routes/no_partial_response/injected.tsx"; import * as $no_partial_response_update from "./routes/no_partial_response/update.tsx"; import * as $partial_slot_inside_island from "./routes/partial_slot_inside_island.tsx"; +import * as $redirected_handler from "./routes/redirected/handler.tsx"; +import * as $redirected_index from "./routes/redirected/index.tsx"; +import * as $redirected_injected from "./routes/redirected/injected.tsx"; +import * as $redirected_redirect from "./routes/redirected/redirect.tsx"; import * as $relative_link_index from "./routes/relative_link/index.tsx"; import * as $scroll_restoration_index from "./routes/scroll_restoration/index.tsx"; import * as $scroll_restoration_injected from "./routes/scroll_restoration/injected.tsx"; @@ -244,6 +248,10 @@ const manifest = { "./routes/no_partial_response/injected.tsx": $no_partial_response_injected, "./routes/no_partial_response/update.tsx": $no_partial_response_update, "./routes/partial_slot_inside_island.tsx": $partial_slot_inside_island, + "./routes/redirected/handler.tsx": $redirected_handler, + "./routes/redirected/index.tsx": $redirected_index, + "./routes/redirected/injected.tsx": $redirected_injected, + "./routes/redirected/redirect.tsx": $redirected_redirect, "./routes/relative_link/index.tsx": $relative_link_index, "./routes/scroll_restoration/index.tsx": $scroll_restoration_index, "./routes/scroll_restoration/injected.tsx": $scroll_restoration_injected, diff --git a/tests/fixture_partials/routes/redirected/handler.tsx b/tests/fixture_partials/routes/redirected/handler.tsx new file mode 100644 index 00000000..d4eeb604 --- /dev/null +++ b/tests/fixture_partials/routes/redirected/handler.tsx @@ -0,0 +1,15 @@ +import { RouteConfig } from "$fresh/server.ts"; +import { Partial } from "$fresh/runtime.ts"; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default function Home() { + return ( + +

Updated content

+
+ ); +} diff --git a/tests/fixture_partials/routes/redirected/index.tsx b/tests/fixture_partials/routes/redirected/index.tsx new file mode 100644 index 00000000..e28f36aa --- /dev/null +++ b/tests/fixture_partials/routes/redirected/index.tsx @@ -0,0 +1,20 @@ +import { Partial } from "$fresh/runtime.ts"; + +export default function SlotDemo() { + return ( +
+
+ +

Default content

+
+
+ + update + +
+ ); +} diff --git a/tests/fixture_partials/routes/redirected/injected.tsx b/tests/fixture_partials/routes/redirected/injected.tsx new file mode 100644 index 00000000..43db45a9 --- /dev/null +++ b/tests/fixture_partials/routes/redirected/injected.tsx @@ -0,0 +1,10 @@ +import { defineRoute } from "$fresh/src/server/defines.ts"; + +export default defineRoute(() => { + return new Response("", { + status: 302, + headers: { + Location: "/redirected", + }, + }); +}); diff --git a/tests/fixture_partials/routes/redirected/redirect.tsx b/tests/fixture_partials/routes/redirected/redirect.tsx new file mode 100644 index 00000000..dae94d28 --- /dev/null +++ b/tests/fixture_partials/routes/redirected/redirect.tsx @@ -0,0 +1,11 @@ +import { Handler } from "$fresh/server.ts"; + +export const handler: Handler = (req) => { + return new Response(null, { + headers: { + ...req.headers, + Location: "/redirected/handler", + }, + status: 307, + }); +}; diff --git a/tests/partials_test.ts b/tests/partials_test.ts index 3962c72b..63ae50b2 100644 --- a/tests/partials_test.ts +++ b/tests/partials_test.ts @@ -1496,3 +1496,16 @@ Deno.test("partials visit to async page", async () => { }, ); }); + +Deno.test("partials with redirects", async () => { + await withPageName( + "./tests/fixture_partials/main.ts", + async (page, address) => { + await page.goto(`${address}/redirected`); + await page.waitForSelector(".output"); + + await page.click(".update-link"); + await page.waitForSelector(".status-updated"); + }, + ); +});