Repository navigation
fix(prettier): keep labeled statements and empty bodies when formatting .tsrx - #1452
Merged
Merged
Conversation
…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]>
trueadm
marked this pull request as ready for review
September 30, 2026 11:14
4 of 5 tasks
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]>
This was referenced Sep 30, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pnpm format:fileson a.tsrxfile deleted every labeled statement.@tsrx/prettier-plugin0.4.10 has noLabeledStatementprinter, 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@forbody containinglabel: { if (row !== 'label') break label; }lost the whole block.The same printer also drops empty statement bodies.
while (x);followed bycount++;becamewhile (x) count++;, which silently moves the next statement into the loop. Emptyelse;anddo;bodies produced invalid code.This PR carries a pnpm patch on the plugin until the repo upgrades it:
prettier-ignoreafter the label. Backport of fix(prettier): print labeled statements like Prettier (#278) tsrx-org/tsrx#322.if/else/for/for…in/for…of/while/doprint as;viaprintClause. Backport of the empty-body part of fix(prettier): keep empty bodies and lay out assigned values like Prettier (#254, #255, #256) tsrx-org/tsrx#283. Non-empty bodies print exactly as before.@tsrx/prettier-plugin has no printer for X (line:col)instead of writing a placeholder comment.The fallback had already damaged
packages/puck/src/components/SlotRender/index.tsrx:export * from './server'had become/* Unknown: ExportAllDeclaration */.RenderimportsSlotRenderandDropZoneimportsSlotRenderPurefrom that module, so every<Render>of a config with aslotfield 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
.tsrxfiles, 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 inpnpm-workspace.yamlwith a comment. It touches onlysrc/index.js.scripts/tsrx-prettier-plugin.test.mjs, added toci: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.tsrxcontains the@forlabeled-block repro, labeled loops, stacked and empty labels, and empty bodies.pnpm format:checkfails on it if the patch is lost.export *and added aslotfield to the render probe, plus a render-contract case asserting the slot's content renders.pnpm syncrefreshedlockfileSha256in the parity manifests and the evals manifest.Validation
pnpm format:checkpasses 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.pnpm ci:workflow:test: 282/282 pass.vitest --project puck: 6/6 pass.pnpm test:markers:checkandpnpm changeset:checkpass.prettier --checkflags the fixture with the unpatched plugin..ts/.tsx/.js/.tsrxfile (~17k) through the tsrx parser with the old and the patched plugin. Only 4 outputs change, all label cases in.ts/.jsfiles that the repo actually formats with Prettier's own printer. The patched label lines match Prettier's committed output..tsrxfiles: the patch introduces no AST changes.No changeset: the change is dev tooling plus the private
@octanejs/puck.Risk / follow-ups
@tsrx/prettier-pluginto ≥ 0.5 as its own reformat change and delete the patch.tsrx-tscrejects abreak labelthat targets a labeled block inside an@forbody ("Break statements are not allowed inside TSRX template for...of loops"). Octane's compiler accepts and runs it. This is an upstream@tsrx/corevalidation bug, tracked separately.packages/puckdoes not typecheck (its.tsrxtype modules never resolve) and is not inpnpm typecheck, which is why the missing export went unnoticed. Tracked separately.visx,dreiandtanstack-form.tsrxfiles still fail the formatter round-trip. That's pre-existing and the reason they are in.prettierignore.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith 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.tsrxformatting 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 intoci:workflow:test) plus a fixture that locks expected output and AST stability.Puck: Restores
export * from './server'inSlotRender/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 syncupdateslockfileSha256in 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.