fix: f-client-nav={false} not working inside island (#2677)

See https://github.com/denoland/fresh/issues/2658
This commit is contained in:
Marvin Hagemeister
2024-10-04 05:44:19 +02:00
committed by GitHub
parent ea3df041c1
commit 73b0398d24
3 changed files with 78 additions and 0 deletions
+65
View File
@@ -19,6 +19,7 @@ import { expect } from "@std/expect";
import { PartialInIsland } from "./fixtures_islands/PartialInIsland.tsx";
import { FakeServer } from "../src/test_utils.ts";
import { JsonIsland } from "./fixtures_islands/JsonIsland.tsx";
import { OptOutPartialLink } from "./fixtures_islands/OptOutPartialLink.tsx";
import * as path from "@std/path";
import { getBuildCache, setBuildCache } from "../src/app.ts";
import { retry } from "@std/async/retry";
@@ -33,11 +34,13 @@ function testApp<T>(): App<T> {
const selfCounter = getIsland("SelfCounter.tsx");
const partialInIsland = getIsland("PartialInIsland.tsx");
const jsonIsland = getIsland("JsonIsland.tsx");
const optOutPartialLink = getIsland("OptOutPartialLink.tsx");
const app = new App<T>()
.island(selfCounter, "SelfCounter", SelfCounter)
.island(partialInIsland, "PartialInIsland", PartialInIsland)
.island(jsonIsland, "JsonIsland", JsonIsland)
.island(optOutPartialLink, "OptOutPartialLink", OptOutPartialLink)
.use(staticFiles());
setBuildCache(app, getBuildCache(allIslandApp));
@@ -1394,6 +1397,68 @@ Deno.test({
sanitizeOps: false,
});
Deno.test({
name: "partials - opt out of partial navigation in island",
fn: async () => {
const app = testApp()
.get("/partial", (ctx) => {
return ctx.render(
<Doc>
<Partial name="foo">
<h1 class="fail">Fail</h1>
</Partial>
</Doc>,
);
})
.get("/foo", (ctx) =>
ctx.render(
<Doc>
<Partial name="foo">
<h1 class="done">done</h1>
<SelfCounter />
</Partial>
</Doc>,
))
.get("/", (ctx) => {
return ctx.render(
<Doc>
<div f-client-nav>
<div>
<OptOutPartialLink href="/foo" partial="/partial" />
</div>
<Partial name="foo">
<p class="init">init</p>
<SelfCounter />
</Partial>
</div>
</Doc>,
);
});
await withBrowserApp(app, async (page, address) => {
await retry(async () => {
await page.goto(address, { waitUntil: "load" });
await page.locator(".ready").wait();
await page.locator(".increment").click();
await waitForText(page, ".output", "1");
await Promise.all([
page.waitForNavigation(),
page.locator(".update").click(),
]);
await page.waitForSelector(".done");
const url = new URL(page.url!);
expect(url.pathname).toEqual("/foo");
await waitForText(page, ".output", "0");
});
});
},
sanitizeResources: false,
sanitizeOps: false,
});
Deno.test({
name: "partials - restore scroll position",
fn: async () => {