Skip to content

fix(puck): typecheck the binding and fix the defects it hid - #1461

Merged
trueadm merged 4 commits into
mainfrom
fix/puck-typecheck
Sep 30, 2026
Merged

trueadm merged 4 commits into
mainfrom
fix/puck-typecheck

Conversation

@trueadm

@trueadm trueadm commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

packages/puck now typechecks under tsrx-tsc and runs in the root typecheck lane. The errors that lane reported were real runtime defects in the binding, so this PR fixes them at the source. It also fixes the hook-slot setup that stopped the editor from rendering stored content, so the fixes can be tested end to end.

The typecheck lane

  • packages/puck/tsconfig.json uses the Octane volar compiler ("tsrx": { "compiler": "octane/compiler/volar" }, as jotai does) and allowImportingTsExtensions.
  • TypeScript never tries .tsrx for an extensionless specifier. So every import … from './Config' (really Config.tsrx) failed, and every name re-exported through one (Config, Render, …) was reported as missing. That in turn left the probe fixtures' render(props) as implicit any. The imports now spell out the .tsrx path, as the rest of the repo does. scripts/port-upstream.mjs applies the same rewrite after porting (scripts/tsrx-specifiers.mjs), so a re-port keeps it. I ran the updated script against upstream v0.20.2 and it produces the same specifiers and pragmas.
  • tsrx-tsc --noEmit -p packages/puck/tsconfig.json is added to the root typecheck script. scripts/typecheck-coverage.json moves puck from privateExceptions to requiredProjects.
  • The fixtures' render props are now typed through Config<{ HeadingBlock: Props }>. For example, props.titel reports Property 'titel' does not exist on type 'WithId<WithPuckProps<{ title: string }>>'. No annotations or any were added.
  • @types/flat, @types/object-hash and @types/uuid are added to dependencies, because the package ships source (as visx and markdown do).

Runtime defects the lane exposed

  • Missing exports. fix(prettier): keep labeled statements and empty bodies when formatting .tsrx #1452 restored SlotRender's export * from './server', which a formatter bug had deleted; this PR spells it ./server.tsrx so the lane resolves it. AutoField/fields/index.tsrx was empty since the port landed; it now re-exports upstream's six field modules. Before this, every built-in field type (text, number, select, …) threw Field type for … did not exist.
  • forwardRef shim. It returned render itself, so Octane called it with props alone and the second ref argument was always undefined. Refs passed to DropZone or to a slot never reached the element. The shim now calls render(props, props.ref ?? null), the same approach as aria's compat shim.
  • Shim exports. react-shim did not export useTransition (imported by DraggableComponent, so the editor crashed on any stored component) or isValidElement (imported by ExternalInput). It now re-exports JSX/Octane from octane/jsx-runtime instead of declaring a namespace that conflicted with the import.
  • Context.Consumer. The editor preview used <autoFrameContext.Consumer>, which Octane contexts do not have. It now reads the frame document with useContext.
  • @dnd-kit 0.5 migrations. The binding runs on catalog 0.5.0, but upstream targets 0.1.18:
    • Sensor activation constraints are now PointerActivationConstraints instances. The old { delay, distance } object made every pointerdown throw object is not iterable.
    • DragDropEvents is now DragDropEventHandlers.
    • Clone feedback is configured through Feedback.configure.
  • Octane typing adaptations. useRef<X | null>(null) sites, native event targets (e.currentTarget for select/radio change), and missing FC/ComponentType type imports.
  • Test helper in src. Upstream's jest-only reducer/actions/__helpers__ was shipped in src. It is removed, and the port script skips it.

Editor hook slots
"hookSlots": { "manual": ["src"] } told the compiler that puck hand-forwards hook slots, which it does not. On top of that, puck's plain .ts hooks import Octane's hooks through react-shim rather than octane, so the .ts slotting pass never claimed them. Every hook inside one custom hook therefore shared a single cell. For example, useContentIdsWithPreview read its preview state as the id list and crashed with contentIdsWithPreview.map is not a function, and the run logged dozens of "dependency array must keep the same length" warnings. This was the README's "full <Puck> editor mount" known difference. The fix has two parts, and both are required:

  • the manual declaration is removed;
  • .ts modules that call hooks get the /** @jsxImportSource octane */ ownership pragma, the same convention as base-ui's 129 such modules. The port script adds it.

Validation

tests/conformance/adaptation.test.ts covers the contracts above. Each test fails with its fix reverted:

Contract Fails without
DropZone ref reaches its element (Render and editor) the forwardRef shim fix
Editor renders stored components useTransition export; hook-slot fix
Editor preview renders inside its iframe useContext in place of Consumer; hook-slot fix
Pointer interaction on an editor component / sortable array item does not throw dnd-kit 0.5 sensor constraints (object is not iterable)
Select and radio fields render and report native change fields barrel
External field lists fetched rows isValidElement export

jsdom never loads an iframe's srcdoc. The iframe test therefore fills the frame document from the srcdoc attribute, as a browser would, and everything past that point runs the real AutoFrame path.

Risk / follow-ups

  • Dropping manual means the compiler now slots puck's .ts modules. Only modules that call hooks carry the pragma.
  • Sortable clone feedback (Feedback.configure({ feedback: 'clone' })) is type-checked, but no jsdom test drives an actual drag.
  • The formatter drops parentheses around an as operand in .tsrx ('name' in (e.target as Element) becomes 'name' in e.target as Element). AutoField's onBlur is written with a local target so it is not affected; the formatter fix is tracked separately.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes hook slotting, ref forwarding, and drag-and-drop in the Puck editor path; medium scope but covered by targeted conformance tests.

Overview
Puck is wired into the root typecheck lane and the defects that check surfaced are fixed so the full editor can run on Octane.

The port pipeline now rewrites extensionless imports to .tsrx, adds @jsxImportSource octane on plain .ts modules that call hooks (replacing the incorrect hookSlots.manual entry), and updates react-shim (forwardRef forwarding refs, useTransition, isValidElement, context types). Source fixes include the missing AutoField fields barrel, @dnd-kit 0.5 API migrations, and native change handlers using e.currentTarget.

React-parity audit files and the user-apps-v1 eval manifest refresh lockfileSha256 / overlayLockfileHash after the lockfile move. The Octane manual hook-slot registry test drops puck and documents pragma-based auto-slotting.

Reviewed by Cursor Bugbot for commit b5091c5. Bugbot is set up for automated code reviews on this repo. Configure here.

trueadm and others added 2 commits September 30, 2026 12:57
packages/puck never typechecked: under tsrx-tsc every extensionless import of
a `.tsrx` module failed to resolve, so each name re-exported through one was
missing and the probe fixtures' render props fell back to implicit any. It was
also a recorded private exception in scripts/typecheck-coverage.json and absent
from the root `typecheck` script, so CI never saw any of it. A working check
would have reported at once the `export * from './server'` that a formatter
bug had deleted from SlotRender (restored in #1452).

Make the lane real:

- tsconfig uses the octane volar compiler (`"tsrx": { "compiler":
  "octane/compiler/volar" }`) and allowImportingTsExtensions.
- Imports of `.tsrx` modules spell out the `.tsrx` path. The port script
  now does this after porting (scripts/tsrx-specifiers.mjs), so a re-port
  keeps it.
- `tsrx-tsc --noEmit -p packages/puck/tsconfig.json` joins the root
  `typecheck` script, and puck moves from `privateExceptions` to
  `requiredProjects` in the coverage manifest.
- @types/flat, @types/object-hash and @types/uuid are dependencies, since
  the package ships source.

The errors were real runtime defects, fixed at the source:

- The AutoField fields barrel, which was empty, re-exports upstream's six
  field modules. Every built-in field type threw "Field type for … did not
  exist." SlotRender's restored re-export (#1452) names `./server.tsrx`.
- The react-shim `forwardRef` returned `render` itself, so Octane called it
  with props alone and every forwarded ref (DropZone, SlotRender) was lost.
  It now passes `props.ref` as the second argument.
- react-shim did not export `useTransition` or `isValidElement`, which
  DraggableComponent and ExternalInput import. It re-exports `JSX` and
  `Octane` from octane/jsx-runtime instead of declaring a conflicting
  namespace.
- The editor preview used `<autoFrameContext.Consumer>`, which Octane
  contexts do not have. It reads the frame document with `useContext`.
- @dnd-kit 0.5 migrations: sensor activation constraints are constraint
  instances (the old `{ delay, distance }` object made every pointerdown
  throw "object is not iterable"), `DragDropEvents` is
  `DragDropEventHandlers`, and clone feedback is configured through the
  Feedback plugin.
- `useRef(null)` sites, native event targets, missing `FC`/`ComponentType`
  type imports, and the jest-only `reducer/actions/__helpers__` test helper
  (now skipped by the port script) are adapted.

The editor could not render stored content at all: `"hookSlots": { "manual":
["src"] }` told the compiler that puck hand-forwards hook slots, which it does
not, and its plain `.ts` hooks import Octane's hooks through react-shim rather
than `octane`, so the compiler never slotted them. Every hook in one custom hook
shared a single cell, and `useContentIdsWithPreview` read the preview state as
its id list. Drop the manual declaration, and give `.ts` modules that call hooks
the `/** @jsxImportSource octane */` ownership pragma (the port script adds
it).

tests/conformance/adaptation.test.ts covers DropZone refs under Render and in
the editor, the editor rendering stored content and its iframe preview, pointer
interactions on editor components and sortable array items, the select/radio
fields' native change, and an external field listing fetched rows. Each test
fails with its fix reverted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 30, 2026
@trueadm
trueadm marked this pull request as ready for review September 30, 2026 12:05
trueadm and others added 2 commits September 30, 2026 13:22
Puck no longer declares `hookSlots.manual`: its plain .ts hooks carry the
@jsxImportSource pragma and are auto-slotted, so the registry of
hand-slot-forwarding packages no longer lists it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit 17e81fe into main Sep 30, 2026
28 checks passed
@trueadm
trueadm deleted the fix/puck-typecheck branch September 30, 2026 12:42
trueadm added a commit that referenced this pull request Sep 30, 2026
Resolve the parity manifests hunk by hunk, keeping main's other pins, and
regenerate their lockfile hashes. Take main's puck sources from #1461 and
format them with @tsrx/prettier-plugin 0.5; each compiles to the same
output. Keep main's deletion of puck's reducer __helpers__ module.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant