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
@@ -0,0 +1,7 @@
export function OptOutPartialLink(props: { href: string; partial: string }) {
return (
<div f-client-nav={false}>
<a class="update" href={props.href} f-partial={props.partial}>link</a>
</div>
);
}
+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 () => {
+6
View File
@@ -26,6 +26,7 @@ import { Multiple1, Multiple2 } from "./fixtures_islands/Multiple.tsx";
import { Foo } from "./fixture_island_groups/routes/foo/(_islands)/Foo.tsx";
import { NodeProcess } from "./fixtures_islands/NodeProcess.tsx";
import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx";
import { OptOutPartialLink } from "./fixtures_islands/OptOutPartialLink.tsx";
export function getIsland(pathname: string) {
return path.join(
@@ -397,6 +398,11 @@ export const allIslandApp = new App()
.island(getIsland("SelfCounter.tsx"), "SelfCounter", SelfCounter)
.island(getIsland("NodeProcess.tsx"), "NodeProcess", NodeProcess)
.island(getIsland("FreshAttrs.tsx"), "FreshAttrs", FreshAttrs)
.island(
getIsland("OptOutPartialLink.tsx"),
"OptOutPartialLink",
OptOutPartialLink,
)
.island(
getIsland("../fixture_island_groups/routes/foo/(_islands)/Foo.tsx"),
"Foo",