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
+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