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
+7 -2
View File
@@ -702,9 +702,14 @@ function collectEntrypoints(
? import.meta.resolve(`${entrypointBase}/main_dev.ts`)
: import.meta.resolve(`${entrypointBase}/main.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 {
import.meta.resolve("@preact/signals");
entryPoints.signals = import.meta.resolve(`${entrypointBase}/signals.ts`);
@@ -713,7 +718,7 @@ function collectEntrypoints(
}
for (const island of islands) {
entryPoints[`island-${island.id}`] = island.url;
entryPoints[`island-${island.name}`] = island.url;
}
for (const plugin of plugins) {
-4
View File
@@ -26,7 +26,3 @@ export {
assertEquals,
assertThrows,
} 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;
const name = processedIsland.name;
const id = `${name}_${exportName}`.toLowerCase();
const name = processedIsland.name.toLowerCase();
const id = `${name}_${exportName.toLowerCase()}`;
islands.push({
id,
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
// reviver from the "main" script.
let islandRegistry = "";
const islandMapping: Record<string, string> = {};
const islandMapping: Record<string, { url: string; export: string }> = {};
if (renderState.encounteredIslands.size > 0) {
// Prepare the inline script that loads and revives the islands
for (const island of renderState.encounteredIslands) {
const url = addImport(`island-${island.id}.js`);
script +=
`import * as ${island.name}_${island.exportName} from "${url}";`;
const url = addImport(`island-${island.name}.js`);
script += island.exportName === "default"
? `import ${island.name}_${island.exportName} from "${url}";`
: `import { ${island.exportName} as ${island.name}_${island.exportName} } from "${url}";`;
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 =
`frsh-slot-${island.id}:${island.exportName}:${id}:children`;
const markerText = `frsh-slot-${island.id}:${id}:children`;
// @ts-ignore nonono
props.children = wrapWithMarker(
children,
@@ -354,9 +353,7 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
return wrapWithMarker(
child,
`frsh-${island.id}:${island.exportName}:${islandProps.length - 1}:${
vnode.key ?? ""
}`,
`frsh-${island.id}:${islandProps.length - 1}:${vnode.key ?? ""}`,
);
};
// deno-lint-ignore no-explicit-any
+1 -1
View File
@@ -1,6 +1,6 @@
import { PARTIAL_SEARCH_PARAM } from "../constants.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 & {
isPartial: boolean;