feat: allow passing JSX children to island + nested islands (#1285)
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"lock": false,
|
||||
"tasks": {
|
||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||
},
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.1.0",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -0,0 +1,34 @@
|
||||
// DO NOT EDIT. This file is generated by fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
import * as $1 from "./routes/island_in_island.tsx";
|
||||
import * as $2 from "./routes/island_jsx_child.tsx";
|
||||
import * as $3 from "./routes/island_jsx_children.tsx";
|
||||
import * as $4 from "./routes/island_jsx_island_jsx.tsx";
|
||||
import * as $5 from "./routes/island_jsx_text.tsx";
|
||||
import * as $6 from "./routes/island_nested_props.tsx";
|
||||
import * as $7 from "./routes/island_siblings.tsx";
|
||||
import * as $$0 from "./islands/Island.tsx";
|
||||
import * as $$1 from "./islands/IslandWithProps.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $0,
|
||||
"./routes/island_in_island.tsx": $1,
|
||||
"./routes/island_jsx_child.tsx": $2,
|
||||
"./routes/island_jsx_children.tsx": $3,
|
||||
"./routes/island_jsx_island_jsx.tsx": $4,
|
||||
"./routes/island_jsx_text.tsx": $5,
|
||||
"./routes/island_nested_props.tsx": $6,
|
||||
"./routes/island_siblings.tsx": $7,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Island.tsx": $$0,
|
||||
"./islands/IslandWithProps.tsx": $$1,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ComponentChildren } from "preact";
|
||||
|
||||
export default function Island(props: { children?: ComponentChildren }) {
|
||||
return (
|
||||
<div class="island">
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
export default function IslandWithProps(
|
||||
props: { foo: { bar: string } },
|
||||
) {
|
||||
const [showText, setShowText] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setShowText(true);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div class="island">
|
||||
<p>
|
||||
{showText ? props.foo.bar : "it doesn't work"}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import routes from "./fresh.gen.ts";
|
||||
|
||||
const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve");
|
||||
|
||||
await start(routes, { experimentalDenoServe });
|
||||
@@ -0,0 +1,15 @@
|
||||
// Simulate Deno Deploy environment
|
||||
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import "./polyfill_deno_deploy.ts";
|
||||
import { start } from "$fresh/server.ts";
|
||||
import routes from "./fresh.gen.ts";
|
||||
|
||||
const experimentalDenoServe = Deno.args.includes("--experimental-deno-serve");
|
||||
|
||||
await start(routes, { experimentalDenoServe });
|
||||
@@ -0,0 +1,5 @@
|
||||
// Simulate Deno Deploy environment
|
||||
|
||||
//@ts-ignore: Remove Deno.run for simulating deno deploy env
|
||||
// deno-lint-ignore no-deprecated-deno-api
|
||||
delete Deno.run;
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function Home() {
|
||||
return <div />;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
<Island>
|
||||
<p>it works</p>
|
||||
</Island>
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
<p>it works</p>
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
<p>it{" "}</p>
|
||||
<p>works</p>
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ComponentChildren } from "preact";
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
function Foo(props: { children?: ComponentChildren }) {
|
||||
return (
|
||||
<div class="server">
|
||||
{props.children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
<Foo>
|
||||
<Island>
|
||||
<Foo>
|
||||
<p>it works</p>
|
||||
</Foo>
|
||||
</Island>
|
||||
</Foo>
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
{"it"} {"works"}
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import IslandWithProps from "../islands/IslandWithProps.tsx";
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
<IslandWithProps foo={{ bar: "it works" }} />
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import Island from "../islands/Island.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div id="page">
|
||||
<Island>
|
||||
<p class="a">it works</p>
|
||||
</Island>
|
||||
<Island>
|
||||
<p class="b">it works</p>
|
||||
</Island>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -248,3 +248,183 @@ Deno.test({
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "pass single JSX child to island",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_jsx_child`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(".island", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "pass multiple JSX children to island",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_jsx_children`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(".island", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "pass multiple text JSX children to island",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_jsx_text`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(".island", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "render island in island",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_in_island`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .island p",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name:
|
||||
"render island with JSX children that render another island with JSX children",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_jsx_island_jsx`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .server .island .server p",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "render sibling islands",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_siblings`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .a",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
|
||||
const text2 = await page.$eval(
|
||||
".island + .island .b",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text2, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "serialize inner island props",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName(
|
||||
"./tests/fixture_island_nesting/main.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(`${address}/island_nested_props`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .island p",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user