Skip to content

fix(CodeBlock): without a code string, CodeBlock names the prop and the fix in development - #12395

Closed
josephfarina wants to merge 2 commits into
mainfrom
josephfarina/rl28-codeblock-missing-code-error
Closed

josephfarina wants to merge 2 commits into
mainfrom
josephfarina/rl28-codeblock-missing-code-error

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #12386 (merged), which adds the shared devPropError helper. Review the commits above it.

User impact

A builder who writes <CodeBlock language="ts">const a = 1;</CodeBlock>, as with <pre>, gets Cannot read properties of undefined (reading 'split') from inside CodeBlock. The message names neither the component nor the prop.

Problem and solution fit

code is a required string; CodeBlock splits it into lines. In development, CodeBlock now checks the prop first and throws:

CodeBlock: code must be a string, for example . CodeBlock does not read children.

Expected behavior and authority

The prop's type in CodeBlockProps defines the expected value. The error uses Core's Component: message form from utils/devWarning.ts.

Smallest restoration

One inline process.env.NODE_ENV !== 'production' check that throws devPropError when code is not a string. A production bundle drops it.

Evidence

  • Reproduction before the change: <CodeBlock language="ts">const a = 1;</CodeBlock> throws Cannot read properties of undefined (reading 'split').
  • Result after the change: the same render throws the message above in development.
  • Representative unchanged path: in production the same render throws the same TypeError as before; minified esbuild production output: the CodeBlock bundle is byte-identical to the base.
  • Regression test or other mutation-sensitive proof: CodeBlock.missingCode.test.tsx (development message, production behavior, and the message is in a development bundle only).

Scope

Components: CodeBlock

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

CI=1 vitest run --project ui on the component's directory, tsc -p packages/core, eslint and prettier on the changed files.

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 17, 2026 7:13pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 17, 2026, 7:20 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 17, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending CI: CI has not run on this head yet.

In development, CodeBlock now names the code prop and the fix when code is not a string, and the production bundle is byte-identical to the base. The new test fails on the base and passes here, and I found no blocking issues. This pull request builds on #12386, which adds devPropError, so it lands after that one.

Claims and files checked

Review mode: full; reason: no-earlier-review

Claims:

  • The release note's patch [fix] entry for @astryxdesign/core: verified, the changeset check passes and no public API changes.
  • In development, a render without a code string throws an error that names code and shows the fix: verified, CodeBlock.tsx:1055-1061 and the "names the prop and the fix" test.
  • That error replaces a TypeError from inside the component, and production output is unchanged: verified, the new test receives Cannot read properties of undefined (reading 'split') on the base, and the minified production bundle is byte-identical.
  • The change builds on #12386 for devPropError, and only its top commit is under review: verified, the base branch is that pull request's head and the diff is one commit.
  • The example render throws that TypeError on the base, and the message names neither the component nor the prop: verified by the same test.
  • code is a required string that CodeBlock splits into lines: verified, CodeBlock.tsx:592 and :1086.
  • CodeBlock checks the prop first and throws the quoted message: verified, CodeBlock.tsx:1055 is the first statement and :1059 matches the quote.
  • The prop's type in CodeBlockProps defines the expected value: verified, code: string at CodeBlock.tsx:592.
  • The error uses Core's Component: message form: verified, devPropError formats through formatDevMessage in utils/devWarning.ts.
  • A single inline NODE_ENV check throws the error, and a production bundle drops it: verified, CodeBlock.tsx:1055 and the bundle check.
  • In production the same render throws the same TypeError as before: verified, the "keeps the production behavior" test passes on the base and here.
  • The minified production output is byte-identical to the base: verified, same size and hash.
  • The regression test covers the development message, the production behavior and a development-only message: verified, CodeBlock.missingCode.test.tsx:41-69, and two of its three tests fail on the base.
  • The scope is CodeBlock: verified, only CodeBlock files and their release note change.
  • The change restores one defect and carries no tagalongs: verified, it has one primary change.
  • It adds no public API, visual representation, default or interaction model: verified, the API surface comparison finds no rows and CodeBlock.d.ts is unchanged.
  • Public text carries no internal context: verified.
  • The listed tests, typecheck, lint and formatting pass: verified, the CodeBlock tests (186), the Core typecheck, eslint and prettier pass at this head.

Files:

  • .changeset/codeblock-missing-code-error.md: clear.
  • packages/core/src/CodeBlock/CodeBlock.tsx: clear.
  • packages/core/src/CodeBlock/CodeBlock.missingCode.test.tsx: clear.

Automated review (maintainer link)

@josephfarina
josephfarina changed the base branch from josephfarina/rl28-selector-options-error to main November 18, 2026 01:33
@josephfarina
josephfarina marked this pull request as ready for review November 18, 2026 02:36
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · e293fdb

Storybook · Sandbox · built from this PR's head

Current run: The current CI run concluded cancelled. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12680 perf(cli): a template's component line resolves its names in one pass, not one full lookup per name
  Author: Joey <[email protected]>
- #12180 fix(core): Calendar weekday names widen their column instead of overlapping
  Author: Joey <[email protected]>
- #12159 feat(cli): make an icon set inside your own app
  Author: Joey Farina <[email protected]>
- #12383 fix(Grid): a responsive column shrinks to a container narrower than minWidth
  Author: Joey Farina <[email protected]>
- #12374 [fix] Icon: a glyph given as name renders and warns, instead of crashing
  Author: Joey Farina <[email protected]>
- #12453 fix(charts): line, area and band default to straight segments
  Author: josephfarina <[email protected]>
- #12296 fix(core): a neutral Badge in a primary or destructive Button meets 4.5:1 on its fill
  Author: Joey Farina <[email protected]>
- #12395 fix(CodeBlock): without a code string, CodeBlock names the prop and the fix in development
  Author: Joey Farina <[email protected]>
- #12260 fix(cli): `astryx component Flex` names Stack first
  Author: Joey Farina <[email protected]>
- #12391 fix(core): a two-lane Toolbar wraps instead of squeezing its start lane
  Author: Joey Farina <[email protected]>
- #12427 fix(core): checkbox and radio marks keep their share of the box a theme sizes
  Author: josephfarina <[email protected]>
- #12725 [experimental] cli: with no icon set, experimental icon names the discover search where it lists packs
  Author: Joey Farina <[email protected]>
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12738.

@github-actions
github-actions Bot deleted the josephfarina/rl28-codeblock-missing-code-error branch November 19, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — e293fdbe Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant