feat: Use href instead of origin on Partial (#1870)

This commit is contained in:
Tiago Gimenes
2023-10-07 23:07:42 +02:00
committed by GitHub
parent 2bd3271883
commit 2df5921b59
4 changed files with 54 additions and 9 deletions
+3 -3
View File
@@ -948,7 +948,7 @@ document.addEventListener("click", async (e) => {
const partialUrl = new URL(
partial ? partial : nextUrl.href,
location.origin,
location.href,
);
await fetchPartials(partialUrl);
updateLinks(nextUrl);
@@ -979,7 +979,7 @@ document.addEventListener("click", async (e) => {
const partialUrl = new URL(
partial,
location.origin,
location.href,
);
await fetchPartials(partialUrl);
}
@@ -1042,7 +1042,7 @@ document.addEventListener("submit", async (e) => {
if (partial !== null) {
e.preventDefault();
const url = new URL(partial, location.origin);
const url = new URL(partial, location.href);
await fetchPartials(url);
}
}
+8 -6
View File
@@ -85,9 +85,10 @@ import * as $79 from "./routes/no_partial_response/index.tsx";
import * as $80 from "./routes/no_partial_response/injected.tsx";
import * as $81 from "./routes/no_partial_response/update.tsx";
import * as $82 from "./routes/partial_slot_inside_island.tsx";
import * as $83 from "./routes/scroll_restoration/index.tsx";
import * as $84 from "./routes/scroll_restoration/injected.tsx";
import * as $85 from "./routes/scroll_restoration/update.tsx";
import * as $83 from "./routes/relative_link/index.tsx";
import * as $84 from "./routes/scroll_restoration/index.tsx";
import * as $85 from "./routes/scroll_restoration/injected.tsx";
import * as $86 from "./routes/scroll_restoration/update.tsx";
import * as $$0 from "./islands/Counter.tsx";
import * as $$1 from "./islands/CounterA.tsx";
import * as $$2 from "./islands/CounterB.tsx";
@@ -188,9 +189,10 @@ const manifest = {
"./routes/no_partial_response/injected.tsx": $80,
"./routes/no_partial_response/update.tsx": $81,
"./routes/partial_slot_inside_island.tsx": $82,
"./routes/scroll_restoration/index.tsx": $83,
"./routes/scroll_restoration/injected.tsx": $84,
"./routes/scroll_restoration/update.tsx": $85,
"./routes/relative_link/index.tsx": $83,
"./routes/scroll_restoration/index.tsx": $84,
"./routes/scroll_restoration/injected.tsx": $85,
"./routes/scroll_restoration/update.tsx": $86,
},
islands: {
"./islands/Counter.tsx": $$0,
@@ -0,0 +1,30 @@
import { Partial } from "$fresh/runtime.ts";
import { defineRoute } from "$fresh/src/server/defines.ts";
import { Fader } from "../../islands/Fader.tsx";
export default defineRoute((req) => {
const url = new URL(req.url);
return (
<div f-client-nav>
<Partial name="body">
<Fader>
<p
class={url.searchParams.has("refresh")
? "status-refreshed"
: "status-initial"}
>
{url.searchParams.has("refresh")
? "Refreshed content"
: "Initial content"}
</p>
</Fader>
</Partial>
<p>
<button f-partial="?refresh">
refresh
</button>
</p>
</div>
);
});
+13
View File
@@ -1101,3 +1101,16 @@ Deno.test("applies f-partial on <button>", async () => {
},
);
});
Deno.test("supports relative links", async () => {
await withPageName(
"./tests/fixture_partials/main.ts",
async (page, address) => {
await page.goto(`${address}/relative_link`);
await page.waitForSelector(".status-initial");
await page.click("button");
await page.waitForSelector(".status-refreshed");
},
);
});