Skip to content

fix(cli): make fragment anchor failures carry the repair - #457

Merged
Ducksss merged 2 commits into
devfrom
fix/actionable-fragment-errors
Aug 13, 2026
Merged

Ducksss merged 2 commits into
devfrom
fix/actionable-fragment-errors

Conversation

@Ducksss

@Ducksss Ducksss commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Closes #121.

The problem

When a consumer project's RenderBlocks.tsx or Pages/index.ts has drifted from the shape the text patcher expects, the install stops and the user has to finish the wiring by hand. That's the correct behavior — the CLI shouldn't guess at a shape it doesn't recognize. But the errors named the anchor and nothing else:

Unable to find insertion anchor "const blockComponents = {".
Unable to find the blockComponents object in RenderBlocks.tsx.
Unable to find the layout block list in Pages collection config.

So the user knows something is wrong and has no way to act on it without reading project.ts to work out which file was meant and what was supposed to go in it.

After

All four failure paths across the two files now report the file, what was missing, and the exact lines the install would have written:

Unable to wire src/blocks/RenderBlocks.tsx: the insertion anchor
"const blockComponents = {" is missing. The file was left unchanged.
Apply these edits by hand, then re-run this command:
  import { HeroBasicBlock } from '@/blocks/HeroBasic/Component'
  heroBasic: HeroBasicBlock,  <- inside the blockComponents object
Unable to wire src/collections/Pages/index.ts: the "layout" field's
blocks: [] list could not be read. The file was left unchanged.
Apply these edits by hand, then re-run this command:
  import { HeroBasic } from '@/blocks/HeroBasic/config'
  HeroBasic  <- added to the "layout" field's blocks: [] list

Two things worth calling out:

The path comes from hostFiles, not the canonical constant. A project on the payload-blocks-app target keeps its collection at src/collections/Pages.ts, and telling that user about src/collections/Pages/index.ts would send them to a file that doesn't exist. There's a test pinning this specifically.

insertLineBeforeAnchor takes the enriched message as an optional callback. localizeBlockConfigSource also uses that helper, but it patches a block config this CLI wrote itself — the shape is known and the bare anchor message is already precise there, so it keeps it. Only the consumer-file callers opt in.

This stays a text-anchor patcher; no AST rewrite, as the issue scopes.

Tests

The two failure cases the issue asks for already existed but only asserted a single regex. They now assert each fact separately — file, missing anchor, import line, entry — so the wording can change without pinning a paragraph. Added the two remaining failure paths and the resolved-path case:

  • payload-components-fragment.int.spec.ts — RenderBlocks anchor missing, RenderBlocks object unreadable, Pages anchor missing, Pages blocks list unreadable. Each also re-asserts the file is left untouched.
  • payload-components-target-detection.int.spec.ts — a drifted variant layout names src/collections/Pages.ts and not the canonical starter path.

captureRejection went into the shared payload-components-assertions.ts rather than being duplicated: rejects.toThrow matches one pattern per call, which is the wrong shape for an error asserted fact by fact.

The unsupported-project-shape error is untouched, and payload-components-target-detection.int.spec.ts:175 already pins that it lists every supported shape.

Verification

  • pnpm run test:int — 508 passed, 1 skipped, 44 files.
  • pnpm exec tsc --noEmit — clean.
  • pnpm lint — clean.
  • pnpm format:check — clean.

One note on the run: an earlier pass failed on blog-visual-system.int.spec.ts with a 15s timeout in the contact-sheet renderer. That test uses ~14s of its 15s budget in isolation, so it tips over under parallel load. I ran the full suite on clean origin/dev to attribute it and it passed there, then re-ran on this branch and it passed too — variance, not this change.

Regenerated asset

public/blog/how-renderblocks-works/figure-01-renderer-dispatch.svg embeds a live 11-line excerpt of applyRenderBlocksFragment as provenance evidence, anchored at const propertyLine. Adding the failure builder shifted those lines, so pnpm blog:visuals:figures regenerated it. The diff is 8 lines, confined to the evidence excerpt.

🤖 Generated with Claude Code

Copilot AI lite review requested due to automatic review settings August 9, 2026 14:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vercel

vercel Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
payload-components Ready Ready Preview Aug 11, 2026 2:39pm
payload-components-97bf Ready Ready Preview Aug 11, 2026 2:39pm

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Ducksss, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f3bf387e-a52f-425c-81be-ff99aa21a011

📥 Commits

Reviewing files that changed from the base of the PR and between 7138a07 and 55ed02c.

⛔ Files ignored due to path filters (1)
  • public/blog/how-renderblocks-works/figure-01-renderer-dispatch.svg is excluded by !**/*.svg
📒 Files selected for processing (4)
  • tests/int/payload-components-assertions.ts
  • tests/int/payload-components-fragment.int.spec.ts
  • tests/int/payload-components-target-detection.int.spec.ts
  • tools/payload-components/project.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Ducksss and others added 2 commits August 11, 2026 22:27
Closes #121.

When a consumer project's RenderBlocks.tsx or Pages/index.ts has drifted
from the shape the text patcher expects, the install stops and the user
has to finish the wiring by hand. The errors named the anchor and nothing
else, so doing that meant reading the CLI source to work out which file
was meant and what was supposed to go in it.

Both files' four failure paths now report the resolved host path, what
was missing, and the exact lines the install would have written. The path
comes from hostFiles rather than the canonical constant, so a non-starter
layout is told about its own file.

insertLineBeforeAnchor takes the enriched message as an optional
callback: localizeBlockConfigSource patches a file this CLI wrote itself,
where the bare anchor message is already precise, so it keeps it.

Regenerates the how-renderblocks-works blog figure, which embeds a live
11-line excerpt of applyRenderBlocksFragment as provenance evidence.

Co-Authored-By: Claude Opus 5 <[email protected]>
Review caught the repair listing the block import unconditionally. When a
file already carries the import but its blockComponents object or layout
blocks list is unreadable, the message told the user to add it again, so
pasting the repair produced a duplicate import — in the one message whose
whole purpose is being safe to paste.

Presence is decided against the source as it exists on disk, not the
in-memory patched copy: nothing is written when a fragment fails, so an
import this run would have inserted is still absent for the user.

Co-Authored-By: Claude Opus 5 <[email protected]>

This branch was successfully deployed

2 active deployments
Preview – payload-components — 55ed02c4 Deployed Aug 11, 2026 by vercel[bot]
Preview – payload-components-97bf — 55ed02c4 Deployed Aug 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants