feat: reduce number of island bundles (#2082)
This commit is contained in:
+2
-2
@@ -63,7 +63,7 @@ async function testBuild(
|
||||
|
||||
await t.step("check snapshot file", async () => {
|
||||
assert(
|
||||
Array.isArray(snapshot.files["island-counter_default.js"]),
|
||||
Array.isArray(snapshot.files["island-counter.js"]),
|
||||
"Island output file not found in snapshot",
|
||||
);
|
||||
assert(
|
||||
@@ -252,7 +252,7 @@ Deno.test("pass target options", async () => {
|
||||
|
||||
const { stdout, stderr } = getStdOutput(out);
|
||||
const txt = await Deno.readTextFile(
|
||||
path.join(fixture, "_fresh", "island-counter_default.js"),
|
||||
path.join(fixture, "_fresh", "island-counter.js"),
|
||||
);
|
||||
|
||||
assertNotMatch(
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.19.2",
|
||||
"preact/": "https://esm.sh/preact@10.19.2/",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.2.2",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.5.0"
|
||||
},
|
||||
"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,23 @@
|
||||
// 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 $index from "./routes/index.tsx";
|
||||
import * as $Multiple from "./islands/Multiple.tsx";
|
||||
import * as $MultipleDefault from "./islands/MultipleDefault.tsx";
|
||||
import * as $Single from "./islands/Single.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $index,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Multiple.tsx": $Multiple,
|
||||
"./islands/MultipleDefault.tsx": $MultipleDefault,
|
||||
"./islands/Single.tsx": $Single,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export function Multiple1() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<div class="island multiple1">
|
||||
<p>Multiple1 Island: {sig}</p>
|
||||
<button onClick={() => sig.value += 1}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Multiple2() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<div class="island multiple2">
|
||||
<p>Multiple2 Island: {sig}</p>
|
||||
<button onClick={() => sig.value += 1}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export default function MultipleDefault() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<div class="island multipledefault">
|
||||
<p>MultipleDefault Island: {sig}</p>
|
||||
<button onClick={() => sig.value += 1}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function MultipleDefault1() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<div class="island multipledefault1">
|
||||
<p>MultipleDefault1 Island: {sig}</p>
|
||||
<button onClick={() => sig.value += 1}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function MultipleDefault2() {
|
||||
const sig = useSignal(0);
|
||||
return (
|
||||
<div class="island multipledefault2">
|
||||
<p>MultipleDefault2 Island: {sig}</p>
|
||||
<button onClick={() => sig.value += 1}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { useSignal } from "@preact/signals";
|
||||
|
||||
export default function Single() {
|
||||
const sig = useSignal(0);
|
||||
|
||||
return (
|
||||
<div class="island single">
|
||||
<p>Single Island: {sig}</p>
|
||||
<button onClick={() => sig.value += 1}>update</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <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 manifest from "./fresh.gen.ts";
|
||||
|
||||
await start(manifest);
|
||||
@@ -0,0 +1,22 @@
|
||||
import Single from "../islands/Single.tsx";
|
||||
import { Multiple1, Multiple2 } from "../islands/Multiple.tsx";
|
||||
import MultipleDefault, {
|
||||
MultipleDefault1,
|
||||
MultipleDefault2,
|
||||
} from "../islands/MultipleDefault.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<h2>Single</h2>
|
||||
<Single />
|
||||
<h2>Multiple</h2>
|
||||
<Multiple1 />
|
||||
<Multiple2 />
|
||||
<h2>Multiple Default</h2>
|
||||
<MultipleDefault />
|
||||
<MultipleDefault1 />
|
||||
<MultipleDefault2 />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -116,22 +116,22 @@ import * as $relative_link_index from "./routes/relative_link/index.tsx";
|
||||
import * as $scroll_restoration_index from "./routes/scroll_restoration/index.tsx";
|
||||
import * as $scroll_restoration_injected from "./routes/scroll_restoration/injected.tsx";
|
||||
import * as $scroll_restoration_update from "./routes/scroll_restoration/update.tsx";
|
||||
import * as $$Counter from "./islands/Counter.tsx";
|
||||
import * as $$CounterA from "./islands/CounterA.tsx";
|
||||
import * as $$CounterB from "./islands/CounterB.tsx";
|
||||
import * as $$Fader from "./islands/Fader.tsx";
|
||||
import * as $$InvalidSlot from "./islands/InvalidSlot.tsx";
|
||||
import * as $$KeyExplorer from "./islands/KeyExplorer.tsx";
|
||||
import * as $$LazyLink from "./islands/LazyLink.tsx";
|
||||
import * as $$Logger from "./islands/Logger.tsx";
|
||||
import * as $$Other from "./islands/Other.tsx";
|
||||
import * as $$PartialTrigger from "./islands/PartialTrigger.tsx";
|
||||
import * as $$PassThrough from "./islands/PassThrough.tsx";
|
||||
import * as $$PropIsland from "./islands/PropIsland.tsx";
|
||||
import * as $$SignalProp from "./islands/SignalProp.tsx";
|
||||
import * as $$Spinner from "./islands/Spinner.tsx";
|
||||
import * as $$Stateful from "./islands/Stateful.tsx";
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import * as $CounterA from "./islands/CounterA.tsx";
|
||||
import * as $CounterB from "./islands/CounterB.tsx";
|
||||
import * as $Fader from "./islands/Fader.tsx";
|
||||
import * as $InvalidSlot from "./islands/InvalidSlot.tsx";
|
||||
import * as $KeyExplorer from "./islands/KeyExplorer.tsx";
|
||||
import * as $LazyLink from "./islands/LazyLink.tsx";
|
||||
import * as $Logger from "./islands/Logger.tsx";
|
||||
import * as $Other from "./islands/Other.tsx";
|
||||
import * as $PartialTrigger from "./islands/PartialTrigger.tsx";
|
||||
import * as $PassThrough from "./islands/PassThrough.tsx";
|
||||
import * as $PropIsland from "./islands/PropIsland.tsx";
|
||||
import * as $SignalProp from "./islands/SignalProp.tsx";
|
||||
import * as $Spinner from "./islands/Spinner.tsx";
|
||||
import * as $Stateful from "./islands/Stateful.tsx";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
@@ -262,21 +262,21 @@ const manifest = {
|
||||
"./routes/scroll_restoration/update.tsx": $scroll_restoration_update,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $$Counter,
|
||||
"./islands/CounterA.tsx": $$CounterA,
|
||||
"./islands/CounterB.tsx": $$CounterB,
|
||||
"./islands/Fader.tsx": $$Fader,
|
||||
"./islands/InvalidSlot.tsx": $$InvalidSlot,
|
||||
"./islands/KeyExplorer.tsx": $$KeyExplorer,
|
||||
"./islands/LazyLink.tsx": $$LazyLink,
|
||||
"./islands/Logger.tsx": $$Logger,
|
||||
"./islands/Other.tsx": $$Other,
|
||||
"./islands/PartialTrigger.tsx": $$PartialTrigger,
|
||||
"./islands/PassThrough.tsx": $$PassThrough,
|
||||
"./islands/PropIsland.tsx": $$PropIsland,
|
||||
"./islands/SignalProp.tsx": $$SignalProp,
|
||||
"./islands/Spinner.tsx": $$Spinner,
|
||||
"./islands/Stateful.tsx": $$Stateful,
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
"./islands/CounterA.tsx": $CounterA,
|
||||
"./islands/CounterB.tsx": $CounterB,
|
||||
"./islands/Fader.tsx": $Fader,
|
||||
"./islands/InvalidSlot.tsx": $InvalidSlot,
|
||||
"./islands/KeyExplorer.tsx": $KeyExplorer,
|
||||
"./islands/LazyLink.tsx": $LazyLink,
|
||||
"./islands/Logger.tsx": $Logger,
|
||||
"./islands/Other.tsx": $Other,
|
||||
"./islands/PartialTrigger.tsx": $PartialTrigger,
|
||||
"./islands/PassThrough.tsx": $PassThrough,
|
||||
"./islands/PropIsland.tsx": $PropIsland,
|
||||
"./islands/SignalProp.tsx": $SignalProp,
|
||||
"./islands/Spinner.tsx": $Spinner,
|
||||
"./islands/Stateful.tsx": $Stateful,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
} satisfies Manifest;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import * as $index from "./routes/index.tsx";
|
||||
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import * as $_app from "./routes/_app.tsx";
|
||||
import * as $index from "./routes/index.tsx";
|
||||
|
||||
import { Manifest } from "$fresh/server.ts";
|
||||
import { type Manifest } from "$fresh/server.ts";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
|
||||
+8
-3
@@ -38,6 +38,7 @@ Deno.test({
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
"init.ts",
|
||||
tmpDirName,
|
||||
],
|
||||
@@ -155,6 +156,7 @@ Deno.test({
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
"init.ts",
|
||||
tmpDirName,
|
||||
"--tailwind",
|
||||
@@ -245,7 +247,7 @@ Deno.test("fresh-init error(help)", async function (t) {
|
||||
"execute invalid init command (deno run -A init.ts)",
|
||||
async () => {
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "init.ts"],
|
||||
args: ["run", "-A", "--no-config", "init.ts"],
|
||||
stdin: "null",
|
||||
stderr: "piped",
|
||||
});
|
||||
@@ -261,7 +263,7 @@ Deno.test("fresh-init error(help)", async function (t) {
|
||||
"execute invalid init command (deno run -A init.ts -f)",
|
||||
async () => {
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "init.ts", "-f"],
|
||||
args: ["run", "-A", "--no-config", "init.ts", "-f"],
|
||||
});
|
||||
const { code, stderr } = await cliProcess.output();
|
||||
assertEquals(code, 1);
|
||||
@@ -275,7 +277,7 @@ Deno.test("fresh-init error(help)", async function (t) {
|
||||
"execute invalid init command (deno run -A init.ts --foo)",
|
||||
async () => {
|
||||
const cliProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "init.ts", "--foo"],
|
||||
args: ["run", "-A", "--no-config", "init.ts", "--foo"],
|
||||
});
|
||||
const { code, stderr } = await cliProcess.output();
|
||||
assertEquals(code, 1);
|
||||
@@ -295,6 +297,7 @@ Deno.test("fresh-init .", async function (t) {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
path.join(Deno.cwd(), "init.ts"),
|
||||
".",
|
||||
],
|
||||
@@ -322,6 +325,7 @@ Deno.test({
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
path.join(Deno.cwd(), "init.ts"),
|
||||
"subdirectory/subsubdirectory",
|
||||
],
|
||||
@@ -379,6 +383,7 @@ Deno.test({
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
"init.ts",
|
||||
tmpDirName,
|
||||
"--tailwind",
|
||||
|
||||
@@ -442,3 +442,39 @@ Deno.test("throws when passing non-jsx children to an island", async (t) => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("serves multiple islands in one file", async () => {
|
||||
await withPageName(
|
||||
"./tests/fixture_islands_multiple/dev.ts",
|
||||
async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "networkidle2" });
|
||||
|
||||
await page.click(".single button");
|
||||
await waitForText(page, ".single p", "Single Island: 1");
|
||||
|
||||
await page.click(".multiple1 button");
|
||||
await waitForText(page, ".multiple1 p", "Multiple1 Island: 1");
|
||||
await page.click(".multiple2 button");
|
||||
await waitForText(page, ".multiple2 p", "Multiple2 Island: 1");
|
||||
|
||||
await page.click(".multipledefault button");
|
||||
await waitForText(
|
||||
page,
|
||||
".multipledefault p",
|
||||
"MultipleDefault Island: 1",
|
||||
);
|
||||
await page.click(".multipledefault1 button");
|
||||
await waitForText(
|
||||
page,
|
||||
".multipledefault1 p",
|
||||
"MultipleDefault1 Island: 1",
|
||||
);
|
||||
await page.click(".multipledefault2 button");
|
||||
await waitForText(
|
||||
page,
|
||||
".multipledefault2 p",
|
||||
"MultipleDefault2 Island: 1",
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ Deno.test("/ page prerender", async () => {
|
||||
assertEquals(resp.headers.get("server"), "fresh test server");
|
||||
const body = await resp.text();
|
||||
assertStringIncludes(body, `<html lang="en">`);
|
||||
assertStringIncludes(body, "test_default.js");
|
||||
assertStringIncludes(body, "test.js");
|
||||
assertStringIncludes(body, "<p>Hello!</p>");
|
||||
assertStringIncludes(body, "<p>Viewing JIT render.</p>");
|
||||
assertStringIncludes(body, `>{"v":[[{"message":"Hello!"}],[]]}</script>`);
|
||||
|
||||
@@ -15,6 +15,7 @@ async function updateAndVerify(cwd: string | URL, expected: RegExp) {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
path.join(Deno.cwd(), "update.ts"),
|
||||
".",
|
||||
],
|
||||
@@ -40,6 +41,7 @@ async function initProject() {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
"--no-config",
|
||||
path.join(Deno.cwd(), "init.ts"),
|
||||
".",
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user