Skip to content

fix(prettier): keep labeled statements and empty bodies when formatting .tsrx - #1452

Merged
trueadm merged 3 commits into
mainfrom
claude/vigilant-mclaren-4635ce
Sep 30, 2026
Merged

trueadm merged 3 commits into
mainfrom
claude/vigilant-mclaren-4635ce

Conversation

@trueadm

@trueadm trueadm commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

pnpm format:files on a .tsrx file deleted every labeled statement. @tsrx/prettier-plugin 0.4.10 has no LabeledStatement printer, and its fallback logs "Unknown node type" and writes /* Unknown: LabeledStatement */ in place of the code, then still writes the file with exit code 0. For example, a @for body containing label: { if (row !== 'label') break label; } lost the whole block.

The same printer also drops empty statement bodies. while (x); followed by count++; became while (x) count++;, which silently moves the next statement into the loop. Empty else; and do; bodies produced invalid code.

This PR carries a pnpm patch on the plugin until the repo upgrades it:

The fallback had already damaged packages/puck/src/components/SlotRender/index.tsrx: export * from './server' had become /* Unknown: ExportAllDeclaration */. Render imports SlotRender and DropZone imports SlotRenderPure from that module, so every <Render> of a config with a slot field threw "Element type is invalid … got: undefined". This PR restores the line; it was the only placeholder in the repository.

Why a patch instead of an upgrade

Upstream already fixed all three problems: 0.4.12 has #322 and #283, and 0.5.x delegates to Prettier's estree printer, which throws on unknown nodes. However, formatting the repo with 0.5.2 would change 1,564 of 2,217 formatted .tsrx files, so that upgrade should be its own change. 0.5.2 formats the new fixture byte-identically, so the fixture won't churn when the patch is dropped.

Changes

  • patches/@[email protected], registered in pnpm-workspace.yaml with a comment. It touches only src/index.js.
  • scripts/tsrx-prettier-plugin.test.mjs, added to ci:workflow:test. It pins exact output under the repo's Prettier config, checks idempotence, compares the parsed AST before and after formatting, and checks that an unknown node type rejects.
  • scripts/fixtures/tsrx-prettier-statements.tsrx contains the @for labeled-block repro, labeled loops, stacked and empty labels, and empty bodies. pnpm format:check fails on it if the patch is lost.
  • Puck: restored the export * and added a slot field to the render probe, plus a render-contract case asserting the slot's content renders.
  • pnpm sync refreshed lockfileSha256 in the parity manifests and the evals manifest.

Validation

  • pnpm format:check passes repo-wide on the merged head.
  • pnpm typecheck: not run. The only typed source change is puck, which is not in the typecheck script; see follow-ups.
  • pnpm test: not run in full. The runtime change is limited to puck, whose Vitest project passes.
  • targeted tests:
    • pnpm ci:workflow:test: 282/282 pass.
    • vitest --project puck: 6/6 pass.
    • pnpm test:markers:check and pnpm changeset:check pass.
    • Pre-fix failures confirmed: the new node test fails 6/6 against unpatched 0.4.10 (loaded through a resolve hook). The puck slot case fails with "Element type is invalid" without the restored export. prettier --check flags the fixture with the unpatched plugin.
    • Corpus A/B: I formatted every tracked .ts/.tsx/.js/.tsrx file (~17k) through the tsrx parser with the old and the patched plugin. Only 4 outputs change, all label cases in .ts/.js files that the repo actually formats with Prettier's own printer. The patched label lines match Prettier's committed output.
    • AST round-trip on all 2,724 formatted .tsrx files: the patch introduces no AST changes.

No changeset: the change is dev tooling plus the private @octanejs/puck.

Risk / follow-ups

  • Upgrade @tsrx/prettier-plugin to ≥ 0.5 as its own reformat change and delete the patch.
  • tsrx-tsc rejects a break label that targets a labeled block inside an @for body ("Break statements are not allowed inside TSRX template for...of loops"). Octane's compiler accepts and runs it. This is an upstream @tsrx/core validation bug, tracked separately.
  • packages/puck does not typecheck (its .tsrx type modules never resolve) and is not in pnpm typecheck, which is why the missing export went unnoticed. Tracked separately.
  • The ignored visx, drei and tanstack-form .tsrx files still fail the formatter round-trip. That's pre-existing and the reason they are in .prettierignore.

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

Low Risk
Risk is low: dev-tooling patch, CI tests, and a small puck export/render fix; no auth, security, or core runtime compiler changes in the diff shown.

Overview
Adds a pnpm patch on @tsrx/[email protected] so .tsrx formatting no longer strips labeled statements, collapses empty loop/branch bodies into the next statement, or silently replaces unknown nodes with placeholder comments. Unknown AST nodes now fail formatting with an explicit error instead of writing /* Unknown: … */.

CI gains scripts/tsrx-prettier-plugin.test.mjs (wired into ci:workflow:test) plus a fixture that locks expected output and AST stability.

Puck: Restores export * from './server' in SlotRender/index.tsrx (previously destroyed by the bad formatter), which fixes invalid <Render> for configs with slot fields. Adds a conformance case that nested slot content renders.

Housekeeping: pnpm sync updates lockfileSha256 in react-parity audit manifests and the evals train manifest after lockfile changes.

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

trueadm and others added 2 commits September 30, 2026 12:10
…ng .tsrx

@tsrx/prettier-plugin 0.4.10 had no LabeledStatement printer. Its fallback
logged "Unknown node type" and wrote `/* Unknown: LabeledStatement */` in
place of the statement, and `pnpm format:files` still wrote the file. It also
printed an empty statement body as nothing, so `while (x);` followed by a
statement made that statement the loop body.

Patch the plugin (patches/@[email protected]) with a
backport of tsrx-org/tsrx#322 (labeled statements, including comments around
the colon and prettier-ignore) and the empty-body part of tsrx-org/tsrx#283
(`printClause` for if/else/for/for-in/for-of/while/do bodies). A node type
with no printer now throws instead of emitting a placeholder. Upstream fixed
all three in 0.4.12 and 0.5.x, but 0.5.2 would reformat 1,564 of 2,217
.tsrx files, so the upgrade stays a separate change.

The same fallback had already deleted `export * from './server'` from puck's
SlotRender module, so every `<Render>` of a slot field threw "Element type is
invalid". Restore it and cover slot rendering in the puck render contract.

scripts/tsrx-prettier-plugin.test.mjs (in ci:workflow:test) pins the output,
checks idempotence, compares the AST before and after formatting, and checks
the unknown-node throw; scripts/fixtures/tsrx-prettier-statements.tsrx makes
`pnpm format:check` fail if the patch is lost.

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
@github-actions
github-actions Bot marked this pull request as draft September 30, 2026 11:13
@trueadm
trueadm marked this pull request as ready for review September 30, 2026 11:14
@trueadm
trueadm merged commit 573acf9 into main Sep 30, 2026
28 checks passed
@trueadm
trueadm deleted the claude/vigilant-mclaren-4635ce branch September 30, 2026 11:29
trueadm added a commit that referenced this pull request Sep 30, 2026
Drop main's @tsrx/prettier-plugin 0.4.10 patch (#1452): this branch is on
0.5.2, which has the labeled-statement and empty-body printers upstream.
Keep its formatter test, with 0.5.2's output: `do; while (a--);` takes
Prettier's own two-line layout, and an unknown node type still throws, now
from Prettier's visitor keys.

Format the fixtures main added or changed with the new formatter; each
compiles to the same output apart from position-derived ids. Regenerated
lockfile hashes follow this branch's lockfile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm added a commit that referenced this pull request Sep 30, 2026
* fix(puck): typecheck the binding and fix the defects it hid

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]>

* test(octane): drop puck from the manual hook-slot registry

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]>

---------

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