feat: allow passing JSX children to island + nested islands (#1285)

This commit is contained in:
Marvin Hagemeister
2023-06-15 10:08:48 +02:00
committed by GitHub
parent 372d0dfffb
commit ce0eda7654
24 changed files with 873 additions and 67 deletions
+15
View File
@@ -16,6 +16,7 @@
*
* The corresponding deserializer is in `src/runtime/deserializer.ts`.
*/
import { isValidElement, VNode } from "preact";
import { KEY } from "../runtime/deserializer.ts";
interface SerializeResult {
@@ -44,6 +45,13 @@ function isSignal(x: any): x is Signal {
);
}
// deno-lint-ignore no-explicit-any
function isVNode(x: any): x is VNode {
return x !== null && typeof x === "object" && "type" in x && "ref" in x &&
"__k" in x &&
isValidElement(x);
}
export function serialize(data: unknown): SerializeResult {
let requiresDeserializer = false;
let hasSignals = false;
@@ -108,6 +116,13 @@ export function serialize(data: unknown): SerializeResult {
referenceArr.push(currentPath);
}
return 0;
} else if (isVNode(value)) {
requiresDeserializer = true;
// No need to serialize JSX as we pick that up from
// the rendered HTML in the browser.
const res = null;
parentStack.push(res);
return res;
} else {
seen.set(value, currentPath);
}