fix: redirects with partials (#2053)

This commit is contained in:
Marvin Hagemeister
2023-11-21 11:35:08 +01:00
committed by GitHub
parent ba3fa2c895
commit 27adeb7b14
7 changed files with 79 additions and 1 deletions
+2 -1
View File
@@ -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);
+8
View File
@@ -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,
@@ -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 (
<Partial name="slot-1">
<p class="status-updated">Updated content</p>
</Partial>
);
}
@@ -0,0 +1,20 @@
import { Partial } from "$fresh/runtime.ts";
export default function SlotDemo() {
return (
<div>
<div class="output">
<Partial name="slot-1">
<p class="status-default">Default content</p>
</Partial>
</div>
<a
class="update-link"
href="/redirected/injected"
f-partial="/redirected/redirect"
>
update
</a>
</div>
);
}
@@ -0,0 +1,10 @@
import { defineRoute } from "$fresh/src/server/defines.ts";
export default defineRoute(() => {
return new Response("", {
status: 302,
headers: {
Location: "/redirected",
},
});
});
@@ -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,
});
};
+13
View File
@@ -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");
},
);
});