feat: allow passing JSX children to island + nested islands (#1285)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user