Extract key from props in h() for UElement, keep key in props for URoot

This commit is contained in:
2026-05-18 16:41:35 +00:00
parent 822ded6cf1
commit 614ee05364
2 changed files with 34 additions and 5 deletions

View File

@@ -3,18 +3,19 @@ import type { UNode, UElement, URoot, UType, UComponent, UniversalProps } from "
let _idCounter = 0;
export function h(type: UType, props?: UniversalProps | null, ...children: UNode[]): UElement | URoot {
const { key, ...restProps } = props ?? {};
const resolvedProps: UniversalProps = restProps;
const flatChildren = children.flat(Infinity as 1).filter((c: UNode) => c != null && c !== false) as UNode[];
if (type === "root") {
return {
type: "root",
props: resolvedProps,
props: { ...(props ?? {}) },
children: flatChildren,
} as URoot;
}
const { key, ...restProps } = props ?? {};
const resolvedProps: UniversalProps = restProps;
return {
type: type as string,
props: resolvedProps,