React / foldkit-react-codegen

Diagnostics when compilation refuses a construct

When a view uses an unsupported construct, the CLI prints file:line:column - error CODE: message, writes no output, and exits with status 1:

  • FKREACT0001: h.submodel missing a literal { model, view, toParentMessage } object, or h.keyed with a computed tag name.
  • FKREACT0002: Unsupported attributes lacking a faithful React equivalent (OnMount, OnUnmount, native OnChange, InnerHTML, or unlisted attributes).
  • FKREACT0003: Non-literal attribute arrays, spreads inside attribute arrays, or attribute helpers built outside an element call.
  • FKREACT0004: Assigning or passing h to anything other than calling it or passing it directly to a helper view.
  • FKREACT0005: Click modifier options, non-literal Style objects, or computed Attribute names.
  • FKREACT0006: Lazy slots stored or invoked outside const slot = createLazy() and a direct slot(...) call.
  • FKREACT0007: Custom element specs that are not inline CustomElement.define({ tag, properties, events }) declarations or bound outside spec.withMessage(h).

Keep components needing these features in Foldkit and embed them with foldkit-react.

Semantic differences in React output

  • Lazy Message construction: Foldkit builds Message values during render; compiled handlers build them when the event fires (equivalent for pure constructors).
  • Direct calls without memo slots: Lazy slots compile to direct calls (wrap callers in React.memo if needed), slotId disappears, and unused Foldkit runtime imports are stripped.
  • List keys: React warns on unkeyed arrays; use h.keyed or h.Key in lists intended for React compilation.

CLI flags

Run foldkit-react-codegen <file-or-directory>... --out-dir <directory> with optional flags:

  • --root-dir <directory>: Base path for relative output structure under --out-dir (defaults to working directory).
  • --watch: Recompiles on changes, keeping the last valid build on diagnostics and ignoring its own output writes.
  • --source-map: Emits <output>.tsx.map with sourceMappingURL mapping JSX nodes back to Foldkit source lines.

Files without views copy through (preserving relative imports), unchanged byte output skips disk writes, and .d.ts / .test.ts files are ignored.