Skip to content

Validate inline code highlight metadata in CI - #8645

Merged
aurorascharff merged 2 commits into
reactjs:mainfrom
aurorascharff:codex/validate-code-highlights
Sep 8, 2026
Merged

Validate inline code highlight metadata in CI#8645
aurorascharff merged 2 commits into
reactjs:mainfrom
aurorascharff:codex/validate-code-highlights

Conversation

@aurorascharff

@aurorascharff aurorascharff commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Invalid inline code highlight metadata currently throws from CodeBlock at runtime, which can leave an otherwise valid documentation page showing a client-side application error. This happened after #8520 moved <form action={submitAction}> from line 23 to line 25 without updating its highlight metadata. The broken Server Functions page was reported in #8523 and fixed separately in #8531.

This PR extends the existing Markdown ESLint rule to validate inline code highlights before deployment. It checks that:

  • the metadata is valid JSON with the expected tuple structure;
  • the referenced line exists in the code block;
  • the highlighted text exists on that line; and
  • repeated text specifies a fromIndex.

The validator uses the normalized metadata produced by the Markdown parser, matching what MDX passes to CodeBlock and supporting highlights that contain escaped quotes. Regression fixtures cover valid metadata, missing text, and out-of-bounds lines. The local-rule tests now run as part of ci-check.

Testing

  • yarn test:eslint-local-rules
  • yarn eslint "src/content/**/*.md"
  • yarn ci-check

To verify the regression, I temporarily changed the Server Functions example's valid submitAction highlight from line 25 to line 24. ci-check failed with:

server-functions.md:115 — Could not find 'submitAction' on highlighted line 24

After restoring line 25, the complete ci-check passed.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@aurorascharff aurorascharff changed the title Validate inline code highlights in docs Validate inline code highlight metadata in CI Sep 8, 2026
@aurorascharff
aurorascharff marked this pull request as ready for review September 8, 2026 12:51

@eps1lon eps1lon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Immediate PTSD when thinking about how much time I spent getting these highlight tupples right.

@aurorascharff
aurorascharff merged commit 0006861 into reactjs:main Sep 8, 2026
7 checks passed
@aurorascharff
aurorascharff deleted the codex/validate-code-highlights branch September 8, 2026 13:02
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