fix: redirects with partials (#2053)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
};
|
||||
@@ -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");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user