feat: reduce number of island bundles (#2082)

This commit is contained in:
Marvin Hagemeister
2023-11-28 17:23:27 +01:00
committed by GitHub
parent ef26451dc6
commit 325850719a
33 changed files with 302 additions and 142 deletions
+10 -43
View File
@@ -1,4 +1,7 @@
import { isIdentifierChar, isIdentifierStart } from "$fresh/src/server/deps.ts"; import {
isIdentifierChar,
isIdentifierStart,
} from "../server/init_safe_deps.ts";
import { extname, join, normalize } from "./deps.ts"; import { extname, join, normalize } from "./deps.ts";
/** /**
@@ -72,18 +75,12 @@ export async function generate(directory: string, manifest: Manifest) {
normalizedRoutes.set(specifier, identifier); normalizedRoutes.set(specifier, identifier);
} }
type islandManifest = { const normalizedIslands: { specifier: string; identifier: string }[] = [];
specifier: string;
identifier: string;
importLine: string;
};
const normalizedIslands: islandManifest[] = [];
for (let i = 0; i < islands.length; i++) { for (let i = 0; i < islands.length; i++) {
const file = islands[i]; const file = islands[i];
const specifier = toImportSpecifier(file); const specifier = toImportSpecifier(file);
const identifier = specifierToIdentifier(specifier, used); const identifier = specifierToIdentifier(specifier, used);
const importLine = await islandImportLine(specifier, identifier, directory); normalizedIslands.push({ specifier, identifier });
normalizedIslands.push({ specifier, identifier, importLine });
} }
const output = `// DO NOT EDIT. This file is generated by Fresh. const output = `// DO NOT EDIT. This file is generated by Fresh.
@@ -99,11 +96,11 @@ ${
} }
${ ${
normalizedIslands.map(({ specifier, identifier }) => normalizedIslands.map(({ specifier, identifier }) =>
`import * as $$${identifier} from "${specifier}";` `import * as $${identifier} from "${specifier}";`
) )
.join("\n") .join("\n")
} }
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
@@ -116,8 +113,8 @@ const manifest = {
}, },
islands: { islands: {
${ ${
normalizedIslands.map(({ specifier, importLine }) => normalizedIslands.map(({ specifier, identifier }) =>
`${JSON.stringify(`${specifier}`)}: ${importLine},` `${JSON.stringify(`${specifier}`)}: $${identifier},`
) )
.join("\n ") .join("\n ")
} }
@@ -153,33 +150,3 @@ export default manifest;
"color: blue; font-weight: bold", "color: blue; font-weight: bold",
); );
} }
async function islandImportLine(
specifier: string,
identifier: string,
directory: string,
): Promise<string> {
const moduleURL = new URL(`file://${directory}/${specifier}`);
const module = await import(moduleURL.href);
const entries = Object.entries(module);
const allExportsAreComponents = entries.every(
([, exportedEntity]) => typeof exportedEntity === "function",
);
// if all exports are components, we can use the simple, existing form
if (allExportsAreComponents) {
return `$$${identifier}`;
}
// if not all exports are components, list the component exports explicitly
const componentExports = entries
.filter(([, exportedEntity]) => typeof exportedEntity === "function")
.map(([exportName]) => exportName);
const exportsString = componentExports
.map((exp) => `${exp}: $$${identifier}.${exp}`)
.join(", ");
return `{ ${exportsString} }`;
}
+10 -9
View File
@@ -82,7 +82,7 @@ function isElementNode(node: Node): node is HTMLElement {
return node.nodeType === Node.ELEMENT_NODE && !("_frshRootFrag" in node); return node.nodeType === Node.ELEMENT_NODE && !("_frshRootFrag" in node);
} }
type IslandRegistry = Record<string, Record<string, ComponentType>>; type IslandRegistry = Record<string, ComponentType>;
export function revive( export function revive(
islands: IslandRegistry, islands: IslandRegistry,
@@ -212,7 +212,7 @@ function hideMarker(marker: Marker) {
* the client. This function checks for that * the client. This function checks for that
*/ */
function addChildrenFromTemplate( function addChildrenFromTemplate(
islands: Record<string, Record<string, ComponentType>>, islands: IslandRegistry,
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
props: any[], props: any[],
markerStack: Marker[], markerStack: Marker[],
@@ -220,11 +220,11 @@ function addChildrenFromTemplate(
comment: string, comment: string,
result: RenderRequest[], result: RenderRequest[],
) { ) {
const [id, exportName, n] = comment.slice("/frsh-".length).split( const [id, n] = comment.slice("/frsh-".length).split(
":", ":",
); );
const sel = `#frsh-slot-${id}-${exportName}-${n}-children`; const sel = `#frsh-slot-${id}-${n}-children`;
const template = document.querySelector(sel) as const template = document.querySelector(sel) as
| HTMLTemplateElement | HTMLTemplateElement
| null; | null;
@@ -280,7 +280,7 @@ function addChildrenFromTemplate(
* fashion over an HTMLElement's children list. * fashion over an HTMLElement's children list.
*/ */
function _walkInner( function _walkInner(
islands: Record<string, Record<string, ComponentType>>, islands: IslandRegistry,
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
props: any[], props: any[],
markerStack: Marker[], markerStack: Marker[],
@@ -437,7 +437,7 @@ function _walkInner(
} }
} else if (comment.startsWith("frsh")) { } else if (comment.startsWith("frsh")) {
// We're opening a new island // We're opening a new island
const [id, exportName, n, key] = comment.slice(5).split(":"); const [id, n, key] = comment.slice(5).split(":");
const islandProps = props[Number(n)]; const islandProps = props[Number(n)];
markerStack.push({ markerStack.push({
@@ -447,7 +447,7 @@ function _walkInner(
kind: MarkerKind.Island, kind: MarkerKind.Island,
}); });
const vnode = h(islands[id][exportName], islandProps) as VNode; const vnode = h(islands[id], islandProps) as VNode;
if (key) vnode.key = key; if (key) vnode.key = key;
vnodeStack.push(vnode); vnodeStack.push(vnode);
} }
@@ -654,7 +654,7 @@ export async function applyPartials(res: Response): Promise<void> {
const islands: IslandRegistry = {}; const islands: IslandRegistry = {};
const dataRaw = doc.getElementById("__FRSH_PARTIAL_DATA")!; const dataRaw = doc.getElementById("__FRSH_PARTIAL_DATA")!;
let data: { let data: {
islands: Record<string, string>; islands: Record<string, { export: string; url: string }>;
signals: string | null; signals: string | null;
deserializer: string | null; deserializer: string | null;
} | null = null; } | null = null;
@@ -663,7 +663,8 @@ export async function applyPartials(res: Response): Promise<void> {
promises.push( promises.push(
...Array.from(Object.entries(data!.islands)).map(async (entry) => { ...Array.from(Object.entries(data!.islands)).map(async (entry) => {
islands[entry[0]] = await import(`${entry[1]}`); const mod = await import(`${entry[1].url}`);
islands[entry[0]] = mod[entry[1].export];
}), }),
); );
} }
+7 -2
View File
@@ -702,9 +702,14 @@ function collectEntrypoints(
? import.meta.resolve(`${entrypointBase}/main_dev.ts`) ? import.meta.resolve(`${entrypointBase}/main_dev.ts`)
: import.meta.resolve(`${entrypointBase}/main.ts`), : import.meta.resolve(`${entrypointBase}/main.ts`),
deserializer: import.meta.resolve(`${entrypointBase}/deserializer.ts`), deserializer: import.meta.resolve(`${entrypointBase}/deserializer.ts`),
fresh_dev_client: import.meta.resolve(`${entrypointBase}/client.ts`),
}; };
if (dev) {
entryPoints.fresh_dev_client = import.meta.resolve(
`${entrypointBase}/client.ts`,
);
}
try { try {
import.meta.resolve("@preact/signals"); import.meta.resolve("@preact/signals");
entryPoints.signals = import.meta.resolve(`${entrypointBase}/signals.ts`); entryPoints.signals = import.meta.resolve(`${entrypointBase}/signals.ts`);
@@ -713,7 +718,7 @@ function collectEntrypoints(
} }
for (const island of islands) { for (const island of islands) {
entryPoints[`island-${island.id}`] = island.url; entryPoints[`island-${island.name}`] = island.url;
} }
for (const plugin of plugins) { for (const plugin of plugins) {
-4
View File
@@ -26,7 +26,3 @@ export {
assertEquals, assertEquals,
assertThrows, assertThrows,
} from "https://deno.land/std@0.205.0/assert/mod.ts"; } from "https://deno.land/std@0.205.0/assert/mod.ts";
export {
isIdentifierChar,
isIdentifierStart,
} from "https://esm.sh/@babel/helper-validator-identifier@7.22.20";
+2 -2
View File
@@ -289,8 +289,8 @@ export async function extractRoutes(
) )
) { ) {
if (typeof exportedFunction !== "function") continue; if (typeof exportedFunction !== "function") continue;
const name = processedIsland.name; const name = processedIsland.name.toLowerCase();
const id = `${name}_${exportName}`.toLowerCase(); const id = `${name}_${exportName.toLowerCase()}`;
islands.push({ islands.push({
id, id,
name, name,
+9
View File
@@ -0,0 +1,9 @@
// This file includes dependencies that are safe to use even
// when the user has no `deno.json` in their project folder.
// This commonly occurs when the user is bootstrapping a new
// project.
export {
isIdentifierChar,
isIdentifierStart,
} from "https://esm.sh/@babel/helper-validator-identifier@7.22.20";
+9 -5
View File
@@ -131,15 +131,19 @@ export function renderFreshTags(
// Finally, it loads all island scripts and hydrates the islands using the // Finally, it loads all island scripts and hydrates the islands using the
// reviver from the "main" script. // reviver from the "main" script.
let islandRegistry = ""; let islandRegistry = "";
const islandMapping: Record<string, string> = {}; const islandMapping: Record<string, { url: string; export: string }> = {};
if (renderState.encounteredIslands.size > 0) { if (renderState.encounteredIslands.size > 0) {
// Prepare the inline script that loads and revives the islands // Prepare the inline script that loads and revives the islands
for (const island of renderState.encounteredIslands) { for (const island of renderState.encounteredIslands) {
const url = addImport(`island-${island.id}.js`); const url = addImport(`island-${island.name}.js`);
script += script += island.exportName === "default"
`import * as ${island.name}_${island.exportName} from "${url}";`; ? `import ${island.name}_${island.exportName} from "${url}";`
: `import { ${island.exportName} as ${island.name}_${island.exportName} } from "${url}";`;
islandRegistry += `${island.id}:${island.name}_${island.exportName},`; islandRegistry += `${island.id}:${island.name}_${island.exportName},`;
islandMapping[island.id] = url; islandMapping[island.id] = {
export: island.exportName,
url,
};
} }
} }
+2 -5
View File
@@ -331,8 +331,7 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
); );
} }
const markerText = const markerText = `frsh-slot-${island.id}:${id}:children`;
`frsh-slot-${island.id}:${island.exportName}:${id}:children`;
// @ts-ignore nonono // @ts-ignore nonono
props.children = wrapWithMarker( props.children = wrapWithMarker(
children, children,
@@ -354,9 +353,7 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
return wrapWithMarker( return wrapWithMarker(
child, child,
`frsh-${island.id}:${island.exportName}:${islandProps.length - 1}:${ `frsh-${island.id}:${islandProps.length - 1}:${vnode.key ?? ""}`,
vnode.key ?? ""
}`,
); );
}; };
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
+1 -1
View File
@@ -1,6 +1,6 @@
import { PARTIAL_SEARCH_PARAM } from "../constants.ts"; import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
import { BaseRoute, ErrorHandlerContext, ServeHandlerInfo } from "./types.ts"; import { BaseRoute, ErrorHandlerContext, ServeHandlerInfo } from "./types.ts";
import { isIdentifierChar, isIdentifierStart } from "./deps.ts"; import { isIdentifierChar, isIdentifierStart } from "./init_safe_deps.ts";
type HandlerContext<T = unknown> = T & ServeHandlerInfo & { type HandlerContext<T = unknown> = T & ServeHandlerInfo & {
isPartial: boolean; isPartial: boolean;
+2 -2
View File
@@ -63,7 +63,7 @@ async function testBuild(
await t.step("check snapshot file", async () => { await t.step("check snapshot file", async () => {
assert( assert(
Array.isArray(snapshot.files["island-counter_default.js"]), Array.isArray(snapshot.files["island-counter.js"]),
"Island output file not found in snapshot", "Island output file not found in snapshot",
); );
assert( assert(
@@ -252,7 +252,7 @@ Deno.test("pass target options", async () => {
const { stdout, stderr } = getStdOutput(out); const { stdout, stderr } = getStdOutput(out);
const txt = await Deno.readTextFile( const txt = await Deno.readTextFile(
path.join(fixture, "_fresh", "island-counter_default.js"), path.join(fixture, "_fresh", "island-counter.js"),
); );
assertNotMatch( assertNotMatch(
+3 -3
View File
@@ -3,15 +3,15 @@
// This file is automatically updated during development when running `dev.ts`. // This file is automatically updated during development when running `dev.ts`.
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
"./routes/index.tsx": $index, "./routes/index.tsx": $index,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
+3 -3
View File
@@ -3,15 +3,15 @@
// This file is automatically updated during development when running `dev.ts`. // This file is automatically updated during development when running `dev.ts`.
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
"./routes/index.tsx": $index, "./routes/index.tsx": $index,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
@@ -3,15 +3,15 @@
// This file is automatically updated during development when running `dev.ts`. // This file is automatically updated during development when running `dev.ts`.
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
"./routes/index.tsx": $index, "./routes/index.tsx": $index,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
@@ -3,15 +3,15 @@
// This file is automatically updated during development when running `dev.ts`. // This file is automatically updated during development when running `dev.ts`.
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
"./routes/index.tsx": $index, "./routes/index.tsx": $index,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
+3 -3
View File
@@ -3,15 +3,15 @@
// This file is automatically updated during development when running `dev.ts`. // This file is automatically updated during development when running `dev.ts`.
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
"./routes/index.tsx": $index, "./routes/index.tsx": $index,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
+3 -3
View File
@@ -3,15 +3,15 @@
// This file is automatically updated during development when running `dev.ts`. // This file is automatically updated during development when running `dev.ts`.
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
"./routes/index.tsx": $index, "./routes/index.tsx": $index,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
+1 -1
View File
@@ -4,7 +4,7 @@
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
+14
View File
@@ -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"
}
}
+5
View File
@@ -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>
);
}
+10
View File
@@ -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>
);
}
+31 -31
View File
@@ -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_index from "./routes/scroll_restoration/index.tsx";
import * as $scroll_restoration_injected from "./routes/scroll_restoration/injected.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 $scroll_restoration_update from "./routes/scroll_restoration/update.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import * as $$CounterA from "./islands/CounterA.tsx"; import * as $CounterA from "./islands/CounterA.tsx";
import * as $$CounterB from "./islands/CounterB.tsx"; import * as $CounterB from "./islands/CounterB.tsx";
import * as $$Fader from "./islands/Fader.tsx"; import * as $Fader from "./islands/Fader.tsx";
import * as $$InvalidSlot from "./islands/InvalidSlot.tsx"; import * as $InvalidSlot from "./islands/InvalidSlot.tsx";
import * as $$KeyExplorer from "./islands/KeyExplorer.tsx"; import * as $KeyExplorer from "./islands/KeyExplorer.tsx";
import * as $$LazyLink from "./islands/LazyLink.tsx"; import * as $LazyLink from "./islands/LazyLink.tsx";
import * as $$Logger from "./islands/Logger.tsx"; import * as $Logger from "./islands/Logger.tsx";
import * as $$Other from "./islands/Other.tsx"; import * as $Other from "./islands/Other.tsx";
import * as $$PartialTrigger from "./islands/PartialTrigger.tsx"; import * as $PartialTrigger from "./islands/PartialTrigger.tsx";
import * as $$PassThrough from "./islands/PassThrough.tsx"; import * as $PassThrough from "./islands/PassThrough.tsx";
import * as $$PropIsland from "./islands/PropIsland.tsx"; import * as $PropIsland from "./islands/PropIsland.tsx";
import * as $$SignalProp from "./islands/SignalProp.tsx"; import * as $SignalProp from "./islands/SignalProp.tsx";
import * as $$Spinner from "./islands/Spinner.tsx"; import * as $Spinner from "./islands/Spinner.tsx";
import * as $$Stateful from "./islands/Stateful.tsx"; import * as $Stateful from "./islands/Stateful.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
@@ -262,21 +262,21 @@ const manifest = {
"./routes/scroll_restoration/update.tsx": $scroll_restoration_update, "./routes/scroll_restoration/update.tsx": $scroll_restoration_update,
}, },
islands: { islands: {
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
"./islands/CounterA.tsx": $$CounterA, "./islands/CounterA.tsx": $CounterA,
"./islands/CounterB.tsx": $$CounterB, "./islands/CounterB.tsx": $CounterB,
"./islands/Fader.tsx": $$Fader, "./islands/Fader.tsx": $Fader,
"./islands/InvalidSlot.tsx": $$InvalidSlot, "./islands/InvalidSlot.tsx": $InvalidSlot,
"./islands/KeyExplorer.tsx": $$KeyExplorer, "./islands/KeyExplorer.tsx": $KeyExplorer,
"./islands/LazyLink.tsx": $$LazyLink, "./islands/LazyLink.tsx": $LazyLink,
"./islands/Logger.tsx": $$Logger, "./islands/Logger.tsx": $Logger,
"./islands/Other.tsx": $$Other, "./islands/Other.tsx": $Other,
"./islands/PartialTrigger.tsx": $$PartialTrigger, "./islands/PartialTrigger.tsx": $PartialTrigger,
"./islands/PassThrough.tsx": $$PassThrough, "./islands/PassThrough.tsx": $PassThrough,
"./islands/PropIsland.tsx": $$PropIsland, "./islands/PropIsland.tsx": $PropIsland,
"./islands/SignalProp.tsx": $$SignalProp, "./islands/SignalProp.tsx": $SignalProp,
"./islands/Spinner.tsx": $$Spinner, "./islands/Spinner.tsx": $Spinner,
"./islands/Stateful.tsx": $$Stateful, "./islands/Stateful.tsx": $Stateful,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;
+1 -1
View File
@@ -4,7 +4,7 @@
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
+1 -1
View File
@@ -5,7 +5,7 @@
import * as $_app from "./routes/_app.tsx"; import * as $_app from "./routes/_app.tsx";
import * as $index from "./routes/index.tsx"; import * as $index from "./routes/index.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
+8 -3
View File
@@ -38,6 +38,7 @@ Deno.test({
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
"init.ts", "init.ts",
tmpDirName, tmpDirName,
], ],
@@ -155,6 +156,7 @@ Deno.test({
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
"init.ts", "init.ts",
tmpDirName, tmpDirName,
"--tailwind", "--tailwind",
@@ -245,7 +247,7 @@ Deno.test("fresh-init error(help)", async function (t) {
"execute invalid init command (deno run -A init.ts)", "execute invalid init command (deno run -A init.ts)",
async () => { async () => {
const cliProcess = new Deno.Command(Deno.execPath(), { const cliProcess = new Deno.Command(Deno.execPath(), {
args: ["run", "-A", "init.ts"], args: ["run", "-A", "--no-config", "init.ts"],
stdin: "null", stdin: "null",
stderr: "piped", 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)", "execute invalid init command (deno run -A init.ts -f)",
async () => { async () => {
const cliProcess = new Deno.Command(Deno.execPath(), { 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(); const { code, stderr } = await cliProcess.output();
assertEquals(code, 1); 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)", "execute invalid init command (deno run -A init.ts --foo)",
async () => { async () => {
const cliProcess = new Deno.Command(Deno.execPath(), { 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(); const { code, stderr } = await cliProcess.output();
assertEquals(code, 1); assertEquals(code, 1);
@@ -295,6 +297,7 @@ Deno.test("fresh-init .", async function (t) {
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
path.join(Deno.cwd(), "init.ts"), path.join(Deno.cwd(), "init.ts"),
".", ".",
], ],
@@ -322,6 +325,7 @@ Deno.test({
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
path.join(Deno.cwd(), "init.ts"), path.join(Deno.cwd(), "init.ts"),
"subdirectory/subsubdirectory", "subdirectory/subsubdirectory",
], ],
@@ -379,6 +383,7 @@ Deno.test({
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
"init.ts", "init.ts",
tmpDirName, tmpDirName,
"--tailwind", "--tailwind",
+36
View File
@@ -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
View File
@@ -33,7 +33,7 @@ Deno.test("/ page prerender", async () => {
assertEquals(resp.headers.get("server"), "fresh test server"); assertEquals(resp.headers.get("server"), "fresh test server");
const body = await resp.text(); const body = await resp.text();
assertStringIncludes(body, `<html lang="en">`); assertStringIncludes(body, `<html lang="en">`);
assertStringIncludes(body, "test_default.js"); assertStringIncludes(body, "test.js");
assertStringIncludes(body, "<p>Hello!</p>"); assertStringIncludes(body, "<p>Hello!</p>");
assertStringIncludes(body, "<p>Viewing JIT render.</p>"); assertStringIncludes(body, "<p>Viewing JIT render.</p>");
assertStringIncludes(body, `>{"v":[[{"message":"Hello!"}],[]]}</script>`); assertStringIncludes(body, `>{"v":[[{"message":"Hello!"}],[]]}</script>`);
+2
View File
@@ -15,6 +15,7 @@ async function updateAndVerify(cwd: string | URL, expected: RegExp) {
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
path.join(Deno.cwd(), "update.ts"), path.join(Deno.cwd(), "update.ts"),
".", ".",
], ],
@@ -40,6 +41,7 @@ async function initProject() {
args: [ args: [
"run", "run",
"-A", "-A",
"--no-config",
path.join(Deno.cwd(), "init.ts"), path.join(Deno.cwd(), "init.ts"),
".", ".",
], ],
+13 -13
View File
@@ -13,13 +13,13 @@ import * as $index from "./routes/index.tsx";
import * as $raw from "./routes/raw.ts"; import * as $raw from "./routes/raw.ts";
import * as $showcase from "./routes/showcase.tsx"; import * as $showcase from "./routes/showcase.tsx";
import * as $update from "./routes/update.tsx"; import * as $update from "./routes/update.tsx";
import * as $$ComponentGallery from "./islands/ComponentGallery.tsx"; import * as $ComponentGallery from "./islands/ComponentGallery.tsx";
import * as $$CopyArea from "./islands/CopyArea.tsx"; import * as $CopyArea from "./islands/CopyArea.tsx";
import * as $$Counter from "./islands/Counter.tsx"; import * as $Counter from "./islands/Counter.tsx";
import * as $$LemonDrop from "./islands/LemonDrop.tsx"; import * as $LemonDrop from "./islands/LemonDrop.tsx";
import * as $$SearchButton from "./islands/SearchButton.tsx"; import * as $SearchButton from "./islands/SearchButton.tsx";
import * as $$VersionSelect from "./islands/VersionSelect.tsx"; import * as $VersionSelect from "./islands/VersionSelect.tsx";
import { Manifest } from "$fresh/server.ts"; import { type Manifest } from "$fresh/server.ts";
const manifest = { const manifest = {
routes: { routes: {
@@ -36,12 +36,12 @@ const manifest = {
"./routes/update.tsx": $update, "./routes/update.tsx": $update,
}, },
islands: { islands: {
"./islands/ComponentGallery.tsx": $$ComponentGallery, "./islands/ComponentGallery.tsx": $ComponentGallery,
"./islands/CopyArea.tsx": $$CopyArea, "./islands/CopyArea.tsx": $CopyArea,
"./islands/Counter.tsx": $$Counter, "./islands/Counter.tsx": $Counter,
"./islands/LemonDrop.tsx": $$LemonDrop, "./islands/LemonDrop.tsx": $LemonDrop,
"./islands/SearchButton.tsx": $$SearchButton, "./islands/SearchButton.tsx": $SearchButton,
"./islands/VersionSelect.tsx": $$VersionSelect, "./islands/VersionSelect.tsx": $VersionSelect,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
} satisfies Manifest; } satisfies Manifest;