From 2df5921b599421693a189bbfc72630fd6166c755 Mon Sep 17 00:00:00 2001 From: Tiago Gimenes Date: Sat, 7 Oct 2023 18:07:42 -0300 Subject: [PATCH] feat: Use href instead of origin on Partial (#1870) --- src/runtime/entrypoints/main.ts | 6 ++-- tests/fixture_partials/fresh.gen.ts | 14 +++++---- .../routes/relative_link/index.tsx | 30 +++++++++++++++++++ tests/partials_test.ts | 13 ++++++++ 4 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 tests/fixture_partials/routes/relative_link/index.tsx diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index 3109fc98..21e542c2 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -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); } } diff --git a/tests/fixture_partials/fresh.gen.ts b/tests/fixture_partials/fresh.gen.ts index 05b86a27..a5c60b92 100644 --- a/tests/fixture_partials/fresh.gen.ts +++ b/tests/fixture_partials/fresh.gen.ts @@ -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, diff --git a/tests/fixture_partials/routes/relative_link/index.tsx b/tests/fixture_partials/routes/relative_link/index.tsx new file mode 100644 index 00000000..81a428b9 --- /dev/null +++ b/tests/fixture_partials/routes/relative_link/index.tsx @@ -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 ( +
+ + +

+ {url.searchParams.has("refresh") + ? "Refreshed content" + : "Initial content"} +

+
+
+

+ +

+
+ ); +}); diff --git a/tests/partials_test.ts b/tests/partials_test.ts index 716aa97d..d42d3d51 100644 --- a/tests/partials_test.ts +++ b/tests/partials_test.ts @@ -1101,3 +1101,16 @@ Deno.test("applies f-partial on