From 30ed82017f0b5bae071e899a59efa6fe39f7fe1d Mon Sep 17 00:00:00 2001 From: Seva Zaikov Date: Thu, 16 Jul 2026 13:55:27 -0700 Subject: [PATCH 1/2] fix tests to pick up TS files --- tsconfig.json | 1 + vitest.config.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tsconfig.json b/tsconfig.json index 8637c35..38ae496 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "lib": ["DOM", "DOM.Iterable", "ESNext"], "types": ["vitest/globals", "@testing-library/jest-dom"], "moduleResolution": "bundler", + "noEmit": true, "skipLibCheck": true } } diff --git a/vitest.config.ts b/vitest.config.ts index aa88aca..dc675a6 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,6 +1,9 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ + resolve: { + extensions: [".ts", ".tsx", ".mjs", ".js", ".mts", ".jsx", ".json"], + }, test: { environment: "jsdom", globals: true, From 83e059d3379f5efb711a462463e7b814ee91b5ad Mon Sep 17 00:00:00 2001 From: Seva Zaikov Date: Thu, 16 Jul 2026 13:56:05 -0700 Subject: [PATCH 2/2] fix nested children being lost with siblings --- integration-tests/fragment.test.ts | 28 ++++++++++++++++++++++++++++ src/create-element/parse-children.ts | 23 ++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/integration-tests/fragment.test.ts b/integration-tests/fragment.test.ts index 6c0651c..c8c6362 100644 --- a/integration-tests/fragment.test.ts +++ b/integration-tests/fragment.test.ts @@ -2,6 +2,7 @@ import { screen } from "@testing-library/dom"; import userEvent from "@testing-library/user-event"; import { attachComponent, createElement, Fragment, createState } from "../src"; +import type { VelesChildren } from "../src/types"; describe("", () => { let cleanup: Function | undefined; @@ -11,6 +12,33 @@ describe("", () => { cleanup = undefined; }); + test("flattens child arrays passed through a wrapper component", () => { + const visible$ = createState(false); + + function Wrapper({ children }: { children?: VelesChildren }) { + return createElement(Fragment, { + children: [children, visible$.render(() => null)] as unknown as VelesChildren, + }); + } + + function App() { + return createElement(Wrapper, { + children: [ + createElement("span", { "data-testid": "first-child", children: "First" }), + createElement("span", { "data-testid": "second-child", children: "Second" }), + ], + }); + } + + cleanup = attachComponent({ + htmlElement: document.body, + component: createElement(App), + }); + + expect(screen.getByTestId("first-child").textContent).toBe("First"); + expect(screen.getByTestId("second-child").textContent).toBe("Second"); + }); + test("supports components rendering correctly", () => { function App() { return createElement("div", { diff --git a/src/create-element/parse-children.ts b/src/create-element/parse-children.ts index 2b47dc1..b36d558 100644 --- a/src/create-element/parse-children.ts +++ b/src/create-element/parse-children.ts @@ -7,6 +7,27 @@ import type { VelesElementProps, } from "../types"; +type ParsedChild = + | string + | number + | VelesElement + | VelesComponentObject + | VelesStringElement + | undefined + | null; + +function flattenChildren(children: unknown): ParsedChild[] { + const flattenedChildren: ParsedChild[] = []; + + function append(child: unknown) { + if (Array.isArray(child)) child.forEach(append); + else flattenedChildren.push(child as ParsedChild); + } + + append(children); + return flattenedChildren; +} + function parseChildren({ children, htmlElement, @@ -27,7 +48,7 @@ function parseChildren({ // when they are executed let lastInsertedNode: null | HTMLElement | Text | VelesComponentObject = null; - (Array.isArray(children) ? children : [children]).forEach((childComponent) => { + flattenChildren(children).forEach((childComponent) => { if (typeof childComponent === "string") { const textNode = createTextElement(childComponent); htmlElement.append(textNode.html);