@kudzujs/core 0.6.6 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/GOAL_B.md CHANGED
@@ -120,13 +120,9 @@ The real-Worker browser check uses real wall time and requires sustained generat
120
120
  ## Delivery Order
121
121
 
122
122
  1. **Worker compiler capability**: exact syntax, graph bundling, hashing, base rewriting, diagnostics, and zero-cost exclusion.
123
- 2. **Realtime vertical slice**: mock telemetry Worker, bounded buffer, downsampling, imperative chart, and route cleanup.
124
- 3. **Shared transport**: add a layout-owned mock connection only if multiple routes prove that one Worker per route is wasteful.
125
- 4. **Device workflows**: filters, commands, timeout/error handling, and stale response suppression.
126
- 5. **Alarm workflows**: active/history views and optimistic acknowledgement with rollback.
127
- 6. **Widget expansion**: add one gauge, table, map, or real chart engine at a time only when a fixture requires it.
123
+ 2. **Capability conformance fixture**: mock telemetry Worker, bounded buffer, downsampling, imperative DOM ownership, and route cleanup.
128
124
 
129
- Each phase starts with one failing fixture and ends with correctness, lifecycle, browser, size, and build measurements.
125
+ Further work belongs to the React migration roadmap and starts from a reduced compatibility fixture that fails. Kudzu does not implement device, alarm, transport, or widget product features.
130
126
 
131
127
  ## Performance Gates
132
128
 
package/README.md CHANGED
@@ -330,9 +330,21 @@ const rows = items.map(item => <ItemRow
330
330
  />)
331
331
  ```
332
332
 
333
- The original component remains reusable across multiple lists and ordinary JSX. No component function or component runtime is shipped to the browser. Kudzu emits initial items as static HTML, then adds, removes, updates, styles, conditional branches, and moves keyed elements directly. The map may appear directly in JSX or in one top-level immutable `const` rendered once as a JSX child. Existing keys move without remounting, preserving uncontrolled descendant state. Direct `item.<field>` reads use compact markers; derived item expressions compile to external ESM evaluators. Single-level item-local `&&` and ternary JSX conditions patch only their bounded branch and mount or unmount its handlers. Item-local handlers and effects receive the latest JSON-safe item for their key. Effects mount after a row is connected and clean up when it is removed. A direct primitive item dependency such as `[item.name]`, optionally mixed with state as `[version, item.name]`, reruns only rows whose selected value changed; the replacement setup receives the complete latest item. Unrelated fields and reorder do not rerun it, while a key change removes and mounts the row. The item remains stored once in shared list state; runtime descriptors carry a placeholder that the list runtime fills when mounting or updating the keyed root.
333
+ The map may also stay inside one same-file component that receives the local state array directly:
334
334
 
335
- Each item must be an ordinary plain object with a unique string or finite-number key; nested data may contain only JSON-safe arrays, ordinary plain objects, and primitive values. Null-prototype objects are rejected to preserve JSON round-trip parity. The current syntax requires a local-state `.map`, one identifier callback parameter, one intrinsic JSX root or top-level local or relative-imported row component, and `key={item.<field>}`. Row components accept destructured projected props, top-level single-`const` calculations and inline effects before one intrinsic return. Effect dependencies inside a row may be empty, direct primitive Kudzu state identifiers, or direct `item.<field>` properties whose selected values remain JSON-safe primitives. Whole-item, computed, nested, derived, `__proto__`, `prototype`, and `constructor` dependencies are rejected. A list alias may only be rendered once and cannot be read by other JavaScript. Derived expressions must be pure and synchronous: item reads, literals, operators, templates, approved read-only string/array methods, deterministic `Math` methods, and `String`/`Number`/`Boolean` conversion are supported. Component state, imported helpers used inside calculations, browser globals, Promise values, mutation, arbitrary calls, and prototype-sensitive properties are rejected. Package or namespace row imports, same-file exported rows, reusable aliases, prop spreads/defaults/rest, children, nested item conditions, lists, or component tags, refs, and `dangerouslySetInnerHTML` remain unsupported. Keyed rows must be placed inside an explicit `<tbody>`, `<thead>`, or `<tfoot>`.
335
+ ```tsx
336
+ function ItemList({ items }: { items: Item[] }) {
337
+ return <ul>{items.map(item => <li key={item.id}>{item.name}</li>)}</ul>
338
+ }
339
+
340
+ return <ItemList items={items} />
341
+ ```
342
+
343
+ The original row component remains reusable across multiple lists and ordinary JSX. State-backed list wrappers and row components are specialized to intrinsic JSX at build time; no component function or component runtime is shipped to the browser. Kudzu emits initial items as static HTML, then adds, removes, updates, styles, conditional branches, and moves keyed elements directly. The map may appear directly in JSX, in one top-level immutable `const` rendered once as a JSX child, or in one same-file synchronous wrapper receiving the state identifier as a direct prop. Existing keys move without remounting, preserving uncontrolled descendant state. Direct `item.<field>` reads use compact markers; derived item expressions compile to external ESM evaluators. Single-level item-local `&&` and ternary JSX conditions patch only their bounded branch and mount or unmount its handlers. Item-local handlers and effects receive the latest JSON-safe item for their key. Effects mount after a row is connected and clean up when it is removed. A direct primitive item dependency such as `[item.name]`, optionally mixed with state as `[version, item.name]`, reruns only rows whose selected value changed; the replacement setup receives the complete latest item. Unrelated fields and reorder do not rerun it, while a key change removes and mounts the row. The item remains stored once in shared list state; runtime descriptors carry a placeholder that the list runtime fills when mounting or updating the keyed root.
344
+
345
+ Each item must be an ordinary plain object with a unique string or finite-number key; nested data may contain only JSON-safe arrays, ordinary plain objects, and primitive values. Null-prototype objects are rejected to preserve JSON round-trip parity. The current syntax requires a local-state `.map`, one identifier callback parameter, one intrinsic JSX root or top-level local or relative-imported row component, and `key={item.<field>}`. State-backed list wrappers must be unexported same-file components with one destructured props parameter, an intrinsic return root, no effects, and direct local-state props at every call. Row components accept destructured projected props, top-level single-`const` calculations and inline effects before one intrinsic return. Effect dependencies inside a row may be empty, direct primitive Kudzu state identifiers, or direct `item.<field>` properties whose selected values remain JSON-safe primitives. Whole-item, computed, nested, derived, `__proto__`, `prototype`, and `constructor` dependencies are rejected. A list alias may only be rendered once and cannot be read by other JavaScript. Derived expressions must be pure and synchronous: item reads, literals, operators, templates, approved read-only string/array methods, deterministic `Math` methods, and `String`/`Number`/`Boolean` conversion are supported. Component state, imported helpers used inside calculations, browser globals, Promise values, mutation, arbitrary calls, and prototype-sensitive properties are rejected. Imported list wrappers, package or namespace row imports, same-file exported rows, reusable aliases, prop spreads/defaults/rest, children, nested item conditions, lists, or component tags, refs, and `dangerouslySetInnerHTML` remain unsupported. Keyed rows must be placed inside an explicit `<tbody>`, `<thead>`, or `<tfoot>`.
346
+
347
+ The focused wrapper fixture emits 1,393 B raw / 500 B gzip HTML and 10,719 B raw / 4,665 B gzip JavaScript across its route capabilities. After one warm-up, seven clean builds measured 314.1, 325.3, 322.3, 327.2, 336.1, 322.4, and 315.0 ms, with a 322.4 ms median.
336
348
 
337
349
  ## Effects
338
350
 
@@ -394,6 +406,8 @@ useEffect(() => {
394
406
 
395
407
  Kudzu resolves the path from the callback source, bundles the Worker and its relative TypeScript imports separately as content-hashed ESM under `assets/workers`, and rewrites the constructor to the base-prefixed same-origin asset URL. The Worker is fetched only when the effect mounts; it is not a capability script, preload, or window import. Unrendered effect handlers do not cause their Worker root to be emitted. This slice requires unshadowed global `Worker` and `URL`, exact `import.meta.url`, a relative `.worker.ts` string literal, and exactly `{ type: "module" }`. Worker graphs reject JSX, package runtime imports, TypeScript import-equals declarations, dynamic imports, `require()`, missing files, and paths outside `src`. Worker source cannot be imported or re-exported as an ordinary runtime module. Construction in event handlers, imported helpers, or imported keyed-row effects is rejected; move keyed-row Worker ownership to a directly compiled page or local component effect. Public or absolute JavaScript Workers remain ordinary browser code and are not transformed.
396
408
 
409
+ Route-owned browser requests use the same dependency-effect cleanup rather than a request runtime. Keep the effect callback synchronous, create an `AbortController` and timeout inside it, start the promise chain, and directly return cleanup that clears the timer and aborts the request. A command-only handler can update primitive command/revision state; the dependency effect then owns the request. Replacement or route disposal runs cleanup before the next setup and invalidates the old effect's setters. Applications must still check `response.ok`, distinguish timeout from other failures, and guard any imperative DOM writes themselves.
410
+
397
411
  A matched mount-fetch benchmark renders a title and two keyed rows from local JSON. With one warm-up and seven rotating clean builds, Kudzu shipped initial HTML, 3.4 KB initial JS gzip, 8.1 KB total output, and built in 374 ms. React CSR shipped no initial content, 59.3 KB initial JS gzip, 189.2 KB total output, and built in 992 ms. Hand-written ESM shipped 534 B initial JS gzip, 1.2 KB total output, and built in 210 ms. Fresh-profile Chrome medians to loaded data were 157.9 ms, 166.5 ms, and 153.4 ms respectively.
398
412
 
399
413
  A matched resize-listener cleanup fixture, measured with the same warm-up and seven rotating clean builds, shipped 1.2 KB JavaScript gzip and built in 402 ms with Kudzu. Svelte shipped 10.1 KB and built in 861 ms, Vue shipped 23.6 KB and built in 768 ms, and React shipped 59.1 KB and built in 1,058 ms. Kudzu and the 127 B hand-written Astro baseline emitted initial HTML; the CSR fixtures did not.
@@ -21,7 +21,7 @@ Exact relative `.worker.ts` constructors in inline effects are validated and bun
21
21
 
22
22
  Page `metadata` can emit description, canonical, favicon, manifest, Open Graph, and Twitter Card tags without a client runtime. Source CSS and global `kudzu.config` styles are emitted in document heads before `afterBuild()` runs; static stylesheet links in component JSX fail compilation instead of loading from the body.
23
23
 
24
- Direct JSON-safe primitive keyed-item dependencies subscribe each row record to its owning list commit and compare selected fields after `list-runtime.js` synchronously refreshes the row marker. Only changed rows rerun with the complete latest item; reorder compares equal, unrelated fields do nothing, and key changes remain remove plus mount. Builds without item dependencies emit no item reader or list-state subscription code.
24
+ Same-file components receiving a direct local-state array prop are specialized to intrinsic JSX before keyed-list analysis, so their component function is not retained in the browser. Direct JSON-safe primitive keyed-item dependencies subscribe each row record to its owning list commit and compare selected fields after `list-runtime.js` synchronously refreshes the row marker. Only changed rows rerun with the complete latest item; reorder compares equal, unrelated fields do nothing, and key changes remain remove plus mount. Builds without item dependencies emit no item reader or list-state subscription code.
25
25
 
26
26
  `kudzu.config` may opt one emitted shared-layout group into same-document navigation with legacy `navigation: { routes: ["/product", "/items/[id]"] }`, or multiple groups with `navigation: { groups: [{ routes: [...] }, { routes: [...] }] }`. The forms are mutually exclusive. Identities are globally unique emitted exact paths or `runtimeParams` patterns; each group uses one page-exported layout function identity. Runtime records securely match concrete pathnames under `base`, and their cache-safe parameter initializer runs before route DOM/effects mount on every transition. Each group receives a deterministic route-hashed asset specialized to only its records, pattern decoder, and effect/parameter lifecycle needs. Cross-group and ungrouped anchors remain native and are not prefetched; overlapping path domains across groups fail the build. Route effect entries export cache-safe layout and route mount functions: layout effects, including conditional/keyed DOM-owned effects, persist for the group session; route effects receive a fresh owner registry after each route insertion; and non-persisted page disposal cleans route before layout. Direct primitive state, runtime parameter, and keyed-item property dependencies and cleanup are supported. Fragment payloads and coordinated View Transitions are not implemented.
27
27
 
@@ -1701,8 +1701,36 @@ function createKudzuTransformer(nativeHandlers, effectHandlers, reactiveBindings
1701
1701
  }
1702
1702
  }
1703
1703
  }
1704
+ const fail = (node, message) => {
1705
+ throw sourceNodeError(node, sourceFile, message)
1706
+ }
1707
+ const componentSpecializations = new WeakMap()
1708
+ const specializedDeclarations = new WeakSet()
1709
+ const stateBackedComponentFunctions = new WeakSet()
1710
+ const stateBackedComponentRoots = []
1711
+ for (const [name, component] of components) {
1712
+ const calls = jsxTagUses(sourceFile, name)
1713
+ const stateBackedCalls = calls.filter(call => isStateBackedListComponentCall(call, component.function, settersByFunction.get(nearestFunction(call)) ?? new Map()))
1714
+ if (!stateBackedCalls.length) continue
1715
+ if (isExportedDeclaration(component.declaration)) fail(component.declaration, `State-backed list component ${name} cannot be exported`)
1716
+ if (identifierReferenceCount(sourceFile, name) !== calls.length) fail(component.declaration, `State-backed list component ${name} may only be referenced as JSX`)
1717
+ if (stateBackedCalls.length !== calls.length) fail(component.declaration, `State-backed list component ${name} must receive its mapped prop from local state at every call`)
1718
+ for (const call of stateBackedCalls) {
1719
+ const specialization = specializeComponentCall(call, component.function, sourceFile, factory, context, fail)
1720
+ if (specialization.effects.length) fail(call, "State-backed list components cannot declare effects")
1721
+ componentSpecializations.set(call, specialization)
1722
+ stateBackedComponentRoots.push(specialization.root)
1723
+ }
1724
+ specializedDeclarations.add(component.declaration)
1725
+ stateBackedComponentFunctions.add(component.function)
1726
+ }
1704
1727
  const rawRenderedLists = []
1705
1728
  const collectRenderedLists = node => {
1729
+ const specialization = componentSpecializations.get(node)
1730
+ if (specialization) {
1731
+ collectRenderedLists(specialization.root)
1732
+ return
1733
+ }
1706
1734
  if (ts.isJsxExpression(node) && node.initializer === undefined && node.expression && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent))) {
1707
1735
  const parts = listLocalUses.get(node) ?? keyedListParts(node.expression, settersForNode(node, settersByFunction))
1708
1736
  if (parts) rawRenderedLists.push({ node, parts })
@@ -1710,9 +1738,6 @@ function createKudzuTransformer(nativeHandlers, effectHandlers, reactiveBindings
1710
1738
  ts.forEachChild(node, collectRenderedLists)
1711
1739
  }
1712
1740
  collectRenderedLists(sourceFile)
1713
- const fail = (node, message) => {
1714
- throw sourceNodeError(node, sourceFile, message)
1715
- }
1716
1741
  const rejectUnsupportedRenderControl = node => {
1717
1742
  if (ts.isIfStatement(node) && containsRenderControl(node, jsxLocalsByFunction.get(nearestFunction(node)) ?? new Set())) {
1718
1743
  const setters = settersForNode(node, settersByFunction)
@@ -1727,8 +1752,6 @@ function createKudzuTransformer(nativeHandlers, effectHandlers, reactiveBindings
1727
1752
  const tag = jsxTagName(parts.root)
1728
1753
  return tag && ts.isIdentifier(tag) && tag.text[0] === tag.text[0].toUpperCase() ? [tag.text] : []
1729
1754
  }))
1730
- const componentSpecializations = new WeakMap()
1731
- const specializedDeclarations = new WeakSet()
1732
1755
  const keyedComponentCalls = new Set(rawRenderedLists.map(({ parts }) => parts.root))
1733
1756
  for (const name of listComponentNames) {
1734
1757
  let component = components.get(name)
@@ -1740,8 +1763,12 @@ function createKudzuTransformer(nativeHandlers, effectHandlers, reactiveBindings
1740
1763
  component = { function: resolveComponentExport(binding.target, imported, importedSource, sourceFiles), declaration: undefined }
1741
1764
  }
1742
1765
  if (local && isExportedDeclaration(component.declaration)) fail(component.declaration, `Keyed list component ${name} cannot be exported`)
1743
- const calls = jsxTagUses(sourceFile, name)
1744
- if (local && identifierReferenceCount(sourceFile, name) !== calls.length) fail(component.declaration, `Keyed list component ${name} may only be referenced as JSX`)
1766
+ const declaredCalls = jsxTagUses(sourceFile, name)
1767
+ if (local && identifierReferenceCount(sourceFile, name) !== declaredCalls.length) fail(component.declaration, `Keyed list component ${name} may only be referenced as JSX`)
1768
+ const calls = [
1769
+ ...declaredCalls.filter(call => !stateBackedComponentFunctions.has(nearestFunction(call))),
1770
+ ...stateBackedComponentRoots.flatMap(root => jsxTagUses(root, name))
1771
+ ]
1745
1772
  for (const call of calls) {
1746
1773
  const specialization = specializeComponentCall(call, component.function, sourceFile, factory, context, fail)
1747
1774
  if (specialization.effects.length && !keyedComponentCalls.has(call)) fail(call, "Effectful keyed row components may only be used directly as keyed map rows")
@@ -2143,6 +2170,36 @@ function keyedListParts(expression, setters) {
2143
2170
  return { state, callback, root, item: callback.parameters[0].name.text, keyField: field }
2144
2171
  }
2145
2172
 
2173
+ function isStateBackedListComponentCall(call, component, setters) {
2174
+ if (component.parameters.length !== 1 || !ts.isObjectBindingPattern(component.parameters[0].name)) return false
2175
+ const attributes = ts.isJsxElement(call) ? call.openingElement.attributes : call.attributes
2176
+ const stateNames = new Set(setters.values())
2177
+ const mappedProps = new Set()
2178
+ for (const element of component.parameters[0].name.elements) {
2179
+ if (!ts.isIdentifier(element.name)) continue
2180
+ const prop = (element.propertyName ?? element.name).getText()
2181
+ const attribute = attributes.properties.find(entry => ts.isJsxAttribute(entry) && entry.name.getText() === prop)
2182
+ const value = attribute?.initializer && ts.isJsxExpression(attribute.initializer) ? unwrapExpression(attribute.initializer.expression) : undefined
2183
+ if (value && ts.isIdentifier(value) && stateNames.has(value.text)) mappedProps.add(element.name.text)
2184
+ }
2185
+ if (!mappedProps.size) return false
2186
+ const returned = ts.isBlock(component.body)
2187
+ ? [...component.body.statements].reverse().find(ts.isReturnStatement)?.expression
2188
+ : component.body
2189
+ if (!returned || !containsJsx(returned)) return false
2190
+ let found = false
2191
+ const visit = node => {
2192
+ if (found || node !== returned && isFunctionLike(node)) return
2193
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map" && ts.isIdentifier(node.expression.expression) && mappedProps.has(node.expression.expression.text)) {
2194
+ found = true
2195
+ return
2196
+ }
2197
+ ts.forEachChild(node, visit)
2198
+ }
2199
+ visit(returned)
2200
+ return found
2201
+ }
2202
+
2146
2203
  function validateKeyedList(parts, sourceFile, listValues, listEventItems, listConditions) {
2147
2204
  const fail = (node, message) => {
2148
2205
  throw sourceNodeError(node, sourceFile, message)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kudzujs/core",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "HTML-first TSX framework with synchronous state semantics and no virtual DOM",
5
5
  "type": "module",
6
6
  "license": "MIT",