fix: falsy f-* attributes not preserved inside island (#2498)
Fixes https://github.com/denoland/fresh/issues/2359
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
import { useEffect } from "preact/hooks";
|
||||
|
||||
export interface FreshAttrs {
|
||||
id?: string;
|
||||
}
|
||||
|
||||
export function FreshAttrs(props: FreshAttrs) {
|
||||
const active = useSignal(false);
|
||||
useEffect(() => {
|
||||
active.value = true;
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div id={props.id} class={active.value ? "ready" : ""}>
|
||||
<h1>Fresh attrs</h1>
|
||||
<div class="f-client-nav-true" f-client-nav={true}>f-client-nav=true</div>
|
||||
<div class="f-client-nav-false" f-client-nav={false}>
|
||||
f-client-nav=false
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import * as path from "@std/path";
|
||||
import { setBuildCache } from "../src/app.ts";
|
||||
import { getBuildCache } from "../src/app.ts";
|
||||
import type { FreshConfig } from "../src/config.ts";
|
||||
import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx";
|
||||
|
||||
await buildProd(allIslandApp);
|
||||
|
||||
@@ -601,6 +602,36 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "islands - preserve f-* attributes",
|
||||
fn: async () => {
|
||||
const freshAttrs = getIsland("FreshAttrs.tsx");
|
||||
|
||||
const app = testApp()
|
||||
.use(staticFiles())
|
||||
.island(freshAttrs, "FreshAttrs", FreshAttrs)
|
||||
.get("/", (ctx) =>
|
||||
ctx.render(
|
||||
<Doc>
|
||||
<FreshAttrs />
|
||||
</Doc>,
|
||||
));
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "load" });
|
||||
await page.locator(".ready").wait();
|
||||
|
||||
const truthy = await page.locator<HTMLDivElement>(".f-client-nav-true")
|
||||
.evaluate((el) => el.getAttribute("f-client-nav"));
|
||||
const falsy = await page.locator<HTMLDivElement>(".f-client-nav-false")
|
||||
.evaluate((el) => el.getAttribute("f-client-nav"));
|
||||
|
||||
expect(truthy).toEqual("true");
|
||||
expect(falsy).toEqual("false");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "fsRoutes - load islands from group folder",
|
||||
fn: async () => {
|
||||
|
||||
@@ -25,6 +25,7 @@ import { SelfCounter } from "./fixtures_islands/SelfCounter.tsx";
|
||||
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";
|
||||
|
||||
export function getIsland(pathname: string) {
|
||||
return path.join(
|
||||
@@ -378,6 +379,7 @@ export const allIslandApp = new App()
|
||||
.island(getIsland("PassThrough.tsx"), "PassThrough", PassThrough)
|
||||
.island(getIsland("SelfCounter.tsx"), "SelfCounter", SelfCounter)
|
||||
.island(getIsland("NodeProcess.tsx"), "NodeProcess", NodeProcess)
|
||||
.island(getIsland("FreshAttrs.tsx"), "FreshAttrs", FreshAttrs)
|
||||
.island(
|
||||
getIsland("../fixture_island_groups/routes/foo/(_islands)/Foo.tsx"),
|
||||
"Foo",
|
||||
|
||||
Reference in New Issue
Block a user