feat(server): multiple island exports (#1397)

This commit is contained in:
Reed von Redwitz
2023-07-03 09:59:38 +02:00
committed by GitHub
parent 16be99e69b
commit a3f7c212f4
9 changed files with 166 additions and 70 deletions
+8 -5
View File
@@ -47,8 +47,11 @@ function isElementNode(node: Node): node is HTMLElement {
return node.nodeType === Node.ELEMENT_NODE;
}
// deno-lint-ignore no-explicit-any
export function revive(islands: Record<string, ComponentType>, props: any[]) {
export function revive(
islands: Record<string, Record<string, ComponentType>>,
// deno-lint-ignore no-explicit-any
props: any[],
) {
_walkInner(
islands,
props,
@@ -127,7 +130,7 @@ interface Marker {
* fashion over an HTMLElement's children list.
*/
function _walkInner(
islands: Record<string, ComponentType>,
islands: Record<string, Record<string, ComponentType>>,
// deno-lint-ignore no-explicit-any
props: any[],
markerStack: Marker[],
@@ -253,7 +256,7 @@ function _walkInner(
}
} else if (comment.startsWith("frsh")) {
// We're opening a new island
const [id, n] = comment.slice(5).split(":");
const [id, exportName, n] = comment.slice(5).split(":");
const islandProps = props[Number(n)];
markerStack.push({
@@ -262,7 +265,7 @@ function _walkInner(
text: comment,
kind: MarkerKind.Island,
});
const vnode = h(islands[id], islandProps);
const vnode = h(islands[id][exportName], islandProps);
vnodeStack.push(vnode);
}
} else if (isTextNode(sib)) {