Skip to content

docs(spec): CodeBlock native language set by use, plus importable language modules under one provider - #8286

Merged
cixzhang merged 6 commits into
mainfrom
codeblock-languages-spec
Oct 24, 2026
Merged

cixzhang merged 6 commits into
mainfrom
codeblock-languages-spec

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Readers of C, C++, SQL, Rust, Kotlin, Swift and Go snippets see them highlighted with no setup, and products that need GraphQL, Java, Thrift, Objective-C, TOML, PowerShell, Ruby, Lua or Dockerfile turn them on once for every code block, Markdown fence and rich-text block; today all of these render as plain text. The built-in set grows to the languages that cover about 97% of fences within a 4,608-byte budget, and the rest are importable modules that one scoped provider turns on.

  • Behavior: Where this sits: system tree and spec flow (illustrative)
  • Behavior: Accessibility (illustrative)
  • API: Built-in languages, and modules for the rest (illustrative)
  • Visual: What you see: six built-in and two module languages (illustrative)
  • Visual: Why these are built in: coverage against size (illustrative)

Built-in languages, and modules for the rest

-<CodeBlock language="thrift" code={idl} />  // plain text today
+<CodeLanguageProvider languages={[thrift]}>
+  <CodeBlock language="thrift" code={idl} />  // highlighted
+</CodeLanguageProvider>

Records: spec:AST-061, component:CodeBlock. The records are the source of truth.

Exact decision needed

Which languages does CodeBlock highlight natively, how does a product turn on the rest, and what may each cost in bundle size?

Existing authority searched

  • component:CodeBlock (current): the language concept ("built-in identifier, custom-tokenizer identifier, or plaintext/unknown"), FR1, AV1 (syntax paint), PR1 (tokenization). No record lists the built-in set or caps its size.
  • component:Markdown (current): fences pass their leading word characters to CodeBlock (FR29), so cpp and objc fences gain highlighting with no change, while c++ reads as c and objective-c as objective.
  • spec:AST-061 (current): RichText colours editable code with the same tokenizer, so read and edit stay alike.
  • Open pull requests touching the tokenizer or CodeBlock languages: none.

Decision

See FR12, FR13, PR4 and DEC-4 in the CodeBlock record. The native set is today's 11 families plus C/C++, SQL, Rust, Kotlin, Swift, and Go, within 4,608 bytes gzipped. GraphQL, Java, Thrift, Objective-C, TOML, PowerShell, Ruby, Lua, and Dockerfile are importable modules from @astryxdesign/core/CodeBlock/languages. A CodeLanguageProvider turns them on for CodeBlock, Markdown fences, and RichText code blocks alike, and each module adds at most 512 bytes.

Rejected alternatives

Recorded as one line each in DEC-4.

Claim scope and non-goals

  • No change to the tokenizer prop, labels, or copy; no public grammar format.
  • No language grammar quality bar beyond comments, strings, numbers, and keywords.

Evidence and implementation relationship

Evidence:

  • Fence counts. Fences that name a language were counted across a large engineering Markdown corpus. Today's 11 families cover 72.9% of them. Adding C/C++, SQL, Rust, Kotlin, Swift, and Go reaches about 97%. The remaining nine families cover about 3%.
  • Prototype sizes. On the prototype, the tokenizer goes from 3.19 KB to 4.20 KB minified and gzipped for the native set. Each further family costs 40–250 bytes.

The implementation follows approval.

Writing rubric results

  • R1 narration: none. FR12, PR4 and DEC-4 are in the present tense.
  • R2 research in the record: none. The size measurement is in this description, and the record keeps only the cap.
  • R3 evidence naming a change: none.
  • R4 rejected alternatives over one line or outside a decision: two, both in DEC-4, one line each.
  • R5 pull request or issue references remaining: none added.
  • R6 ruled open questions still listing options: none.

Scope

  • This PR contains specification records only.
  • It records observable behavior and preserves equivalent internal implementations.
  • Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract.
  • Verification states the evidence layer and failure signal without prescribing CI job/workflow topology.
  • It records one intentional durable decision, not a rescue for a separable tagalong.
  • The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision.
  • Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them.
  • Public text and artifacts contain no internal Meta context.

Validation

  • pnpm check:knowledge
  • Prettier
  • git diff --check

…KB tokenizer budget (FR12, PR4, DEC-4)

C, C++, Objective-C, Rust, Go, Java, Kotlin, Swift, SQL, GraphQL, Thrift,
TOML, Ruby, Dockerfile, PowerShell, and Lua join the built-in identifiers,
each painting at least comments, strings, numbers, and keywords from the
syntax theme. The built-in tokenizer stays within 6 KB minified and gzipped
and loads nothing at run time; the tokenizer prop stays the extension point.
@vercel

vercel Bot commented Oct 24, 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 Oct 24, 2026 10:32pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 24, 2026, 11:30 PM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 24, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current change has no visual or preview-producing scope. Visual checks are not applicable; preview links are not shown.

The exact-head preview is not available yet.


Generated by PR Enrichment workflow | View current CI run

@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.

This spec change can't be approved yet. FR12, PR4 and DEC-4 add new requirements to the CodeBlock record (16 new built-in language groups with their aliases, and a 6 KB minified-and-gzipped tokenizer budget), and an engineering owner needs to record that decision by commenting /approve-spec <full head SHA> on this pull request; the author, as an engineering owner, may do so. Please fix these first, so the approval lands on the corrected head:

  • PR4 and DEC-4 say a block paints in its first render, but the unchanged PR1 sends code of 2,000 or more characters through the async tokenizer, so scope that clause to shorter blocks.
  • Lines 48 and 60 still name FR11 as the only default change; add FR12 beside it.
  • The FR12 compatibility bullet should say that the exported tokenize functions, and the RichText code blocks that use them, change too.
  • As written, the FR12/PR4 verification row cannot pass for json or html; require the token kinds each language has, and pin "6 KB" to a byte count.

[Automated review]

- **PR1 — Tokenization.** Short code may tokenize synchronously; long built-in code yields through the async tokenizer and cancels stale work when code or language changes.
- **PR2 — Highlight lifetime.** Range-mode highlighting removes ranges and visibility listeners when its rendered token set changes or unmounts.
- **PR3 — Large line sets.** Large blocks may chunk line rendering and use content visibility, without losing source order or line identity.
- **PR4 — Built-in language budget.** The built-in tokenizer, every FR12 grammar included, stays within 6 KB minified and gzipped, ships with CodeBlock, and loads no grammar at run time, so a block paints in its first render.

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.

PR4's "so a block paints in its first render" contradicts PR1 on line 140. Code of 2,000 or more characters yields to the async tokenizer, so it paints plain on its first render (useTokenLines in CodeBlock.tsx, SYNC_TOKENIZE_THRESHOLD = 2000 in tokenizer.ts). Suggest scoping it, for example: "so short code paints in its first render (PR1), and no block waits on the network".


**Decider:** `cixzhang`, `2026-10-24`

A reader of a C++, Rust, Go, Java, Kotlin, Swift, SQL, GraphQL, Thrift, TOML, Ruby, Dockerfile, PowerShell, or Lua snippet sees it highlighted like the languages CodeBlock already knows, in the block's first render, with no product setup. The grammars are compact pattern sets that share builders across the C-like family, so every family costs every consumer little; the whole tokenizer is held to 6 KB minified and gzipped, and a language that does not fit the budget is not built in. The `tokenizer` prop stays the one extension point for anything else. Rejected: loading grammars on demand (a block would paint plain and then recolour, and its first render would wait on the network); a global language registry (shared mutable state across React roots and a second extension API beside `tokenizer`).

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.

Same scope issue as PR4: "in the block's first render" holds only for short code, which PR1 lets tokenize synchronously (under 2,000 characters in the shipped code). Longer blocks already paint plain and then recolour, which is the cost this decision cites against loading grammars on demand.

| Behavior | CodeBlock renders a read-only code surface, applies syntax highlighting when available, preserves the source string for copy, and exposes optional line, header, copy, caller-control, theme, and disclosure behavior without editing the content; no control covers the code, and a one-line block with no header (no title, language label hidden) reads as one row (FR11). |
| End-user impact | Readers can inspect and copy code, understand optional line emphasis, and operate long or collapsible examples with keyboard and assistive technology. Readers of a block with no header never have code under a control, at the cost of the controls' column width, and a one-line command whose label is hidden reads as one row with its controls beside it; product actions sit beside Copy instead of outside the block. Readers of C, C++, Objective-C, Rust, Go, Java, Kotlin, Swift, SQL, GraphQL, Thrift, TOML, Ruby, Dockerfile, PowerShell, and Lua snippets see them highlighted instead of plain (FR12). |
| Builder impact | Builders choose the released display axes without an additional migration or opt-in; the diff layer is one more opt-in axis, `endContent` (FR10) is one optional slot for their own controls, and five defaulted syntax-theme slots mean no syntax theme has to change for it. |
| Compatibility/readiness | The released `CodeBlock` API remains stable and its defaults hold except for the visible headerless layout in Compatibility below (FR11); FR10 (`endContent`, additive) and FR11 are current and await implementation; FR12 (built-in languages) and PR4 (their budget) are current and await implementation; FR9 (the diff layer) is current and shipped; Markdown's default path for `diff` fences follows it (`component:Markdown` FR29). |

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.

This row, and line 60 ("Released default preserved: yes, except the visible headerless layout (FR11, below)"), still name FR11 as the only default exception, while line 64 adds a second visible default change for FR12. Suggest "except the visible headerless layout (FR11) and the newly built-in languages (FR12)" in both places.

- Compatibility class: compatible; no prop, export, type, default, target, or ref migration is required
- Controlled/uncontrolled behavior: collapse state remains component-owned, starts expanded when applicable, and returns to expanded when its control disappears
- Visible default change (FR11), not breaking: a block with no header shows its controls in their own column beside the code instead of over it, so its code ends that much earlier, a block sized to its content (`fit-content`) grows by the column's width, and a one-line block reads as one row. A block with a title or a visible language label keeps its header at every line count. Markdown fences with no language take it through the default code path (`component:Markdown`). No prop, type, or target migration follows from it.
- Visible default change (FR12), not breaking: blocks and Markdown fences in the newly built-in languages are highlighted instead of plain; text, copy output, labels, and a custom `tokenizer` are unchanged, and the built-in tokenizer grows within the PR4 budget.

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.

This reaches further than blocks and fences. tokenize, tokenizeAsync and tokenizeStreaming are exported from @astryxdesign/core/CodeBlock, and RichText code blocks and the Lab editors call them, so they also return tokens for the 16 new identifier groups. Worth naming here.

| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
| FR1, PR1–PR3 | `tokenizer.test.ts`; `highlightRanges.test.ts`; CodeBlock focused tests and built Storybook | short/long, built-in/custom, ranges/spans, empty lines | Text changes, stale tokens paint, ranges leak, source order changes, or long work stops yielding/canceling. | `audit:CodeBlock/behavior` |
| FR12, PR4 | `tokenizer.test.ts` (one representative snippet per built-in family and alias: comment, string, number, keyword tokens; an unknown identifier yields no tokens); a size check over the minified, gzipped tokenizer module | every FR12 identifier and alias, an unknown identifier, an empty string | A listed identifier renders without tokens, an alias paints differently from its family, source text changes, or the module exceeds 6 KB minified and gzipped. | `audit:CodeBlock/behavior` |

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.

As written, this row cannot pass for json (no comment syntax; true/false/null are typed constant) or for html/xml/svg (no number pattern). Suggest "the comment, string, number, and keyword tokens each language has", and pin "6 KB" to a byte count (6,000 or 6,144) so the size check has one threshold.

…de; compatibility and evidence follow

PR4 and DEC-4 claim first-render paint for short code only, as PR1 sends
long code through the async tokenizer. Compatibility names FR12 beside FR11
and the exported tokenize functions RichText uses. FR12 and its evidence ask
for the token kinds each language has, and the budget is 6,144 bytes.
cixzhang added a commit that referenced this pull request Oct 24, 2026
… have a budget (#8271)

## Exact decision needed

How much a component change may add to what every product downloads, and how a pull request shows that cost.

## Existing authority searched

- `spec:AST-080` FR1, FR2, DEC-3: each package ships one whole stylesheet, so CSS any component adds reaches every product.
- `architecture:component-style-authoring` INV1–INV5: no size outcome.
- `architecture:react-component-runtime` INV5 (acquire optional resources only while enabled) and INV8 (reuse shared owners): no byte budget.
- `spec:AST-036` FR22–FR23: the only numeric budgets, for the Markdown parser only.
- No current record requires a size report or sets a per-component JavaScript or CSS budget.
- Search terms: size, bundle, budget, gzip, stylesheet, CSS delta, lazy, value table, constants table, touch-only. Overlapping open pull requests: #8277 (the size-report fix this record governs), #8052 (touch presentation spec citing a shared value table), #8053 (the touch constants table, which the value-table rule covers), #7358 (per-component English catalog slices; catalogs stay with `architecture:internationalization` INV15), #8286 (a component-local tokenizer byte budget, unaffected).

## Decision

- `spec:AST-080` FR8 / DEC-4: every pull request that changes styled modules reports, base against head, each changed package stylesheet's gzip size and each changed component's gzip CSS delta. A feature that runs only on a coarse pointer and adds more than 1 KB gzip of CSS to one component is flagged and justified; the CSS stays in the package stylesheet.
- `architecture:component-style-authoring` INV6: every pull request that changes a component reports the gzip JavaScript its import pulls in, transitive modules included, and its CSS delta, base against head. Touch-only work over 2 KB gzip JavaScript or 1 KB gzip CSS per component is flagged; the JavaScript is loaded lazily, only when a coarse pointer needs it, or the cost is justified. A shared JavaScript tuning table ships to a component only the rows that component uses; StyleX variable groups and message catalogs keep their own owners.

## Rejected alternatives

- A separate stylesheet for touch-only CSS: breaks the one-import-per-package setup of `spec:AST-080` DEC-3.

## Claim scope and non-goals

Size reporting and the touch-only budget only. Budgets for other kinds of work, render or listener counts, and the report's CI implementation are outside this PR.

## Evidence and implementation relationship

The pull-request size report measures no stylesheet, reports a component's re-export file instead of what its import pulls in, and never fills its before and delta columns. A report fix and the budget flags follow as separate implementation PRs. No implementation is included.

## Writing rubric results

- R1 narration: none.
- R2 research in the record: none.
- R3 evidence naming a change: none; verification names report states.
- R4 rejected alternatives over one line or outside a decision: one, inside DEC-4, one line.
- R5 pull request or issue references remaining: none.
- R6 ruled open questions still listing options: none.

## Scope

- [x] This PR contains specification records only.
- [x] It records observable behavior and preserves equivalent internal implementations.
- [x] Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract.
- [x] Verification states the evidence layer and failure signal without prescribing CI job/workflow topology.
- [x] It records one intentional durable decision, not a rescue for a separable tagalong.
- [x] The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision.
- [x] Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them.
- [x] Public text and artifacts contain no internal Meta context.

## Validation

- `pnpm check:knowledge` (CI lint)
- Prettier
- `git diff --check`

@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.

This spec change can't be approved yet: FR12, PR4 and DEC-4 add new requirements to the CodeBlock record (16 new built-in language groups with their aliases, and a 6,144-byte minified-and-gzipped tokenizer cap), and an engineering owner needs to record that decision by commenting /approve-spec <full head SHA> on this pull request; the author, as an engineering owner, may do so. One correction should land first, so the approval covers the final head: the FR12 compatibility line says Markdown fences in the new languages are highlighted, but Markdown hands CodeBlock only a fence's leading word characters (component:Markdown FR29), so c++ and objective-c fences arrive as c and objective. Please say so in that line, or change Markdown's rule in its own record, and correct the description's Markdown line the same way.

[Automated review]

- Compatibility class: compatible; no prop, export, type, default, target, or ref migration is required
- Controlled/uncontrolled behavior: collapse state remains component-owned, starts expanded when applicable, and returns to expanded when its control disappears
- Visible default change (FR11), not breaking: a block with no header shows its controls in their own column beside the code instead of over it, so its code ends that much earlier, a block sized to its content (`fit-content`) grows by the column's width, and a one-line block reads as one row. A block with a title or a visible language label keeps its header at every line count. Markdown fences with no language take it through the default code path (`component:Markdown`). No prop, type, or target migration follows from it.
- Visible default change (FR12), not breaking: blocks and Markdown fences in the newly built-in languages are highlighted instead of plain, and the exported `tokenize`, `tokenizeAsync`, and `tokenizeStreaming` functions, with the RichText code blocks and editors that call them, return tokens for those identifiers; text, copy output, labels, and a custom `tokenizer` are unchanged, and the built-in tokenizer grows within the PR4 budget.

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.

This promises highlighting for Markdown fences in the new languages, but component:Markdown FR29 hands the default Code block only a fence's leading word characters (packages/core/src/Markdown/parser.ts:3751), so a c++ fence arrives as c (C grammar, c label) and an objective-c fence as objective (plain). Suggest naming that rule here, for example: “Markdown fences reach these identifiers by their leading word (component:Markdown FR29), so c++ and objective-c fences read as c and objective.”

Markdown passes a fence leading word characters (Markdown FR29), so cpp and
objc fences highlight while c++ reads as c and objective-c as objective.

@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.

This spec change can't be approved yet: FR12, PR4 and DEC-4 add new requirements to the CodeBlock record (16 new built-in language groups with their aliases, and a 6,144-byte minified-and-gzipped cap on the tokenizer), and an engineering owner needs to record that decision by commenting /approve-spec <full head SHA> on this pull request; the author, as an engineering owner, may do so. The Markdown fence correction is in, and no other change is required. One point to weigh first: Markdown passes c++ and objective-c fences to CodeBlock as c and objective while RichText keeps the whole word, so once FR12 ships those fences would read and edit with different grammars; naming that in the FR12 compatibility line (and in the description's AST-061 line), or dropping the two aliases, would make the record say what readers will see.

[Automated review]

- Compatibility class: compatible; no prop, export, type, default, target, or ref migration is required
- Controlled/uncontrolled behavior: collapse state remains component-owned, starts expanded when applicable, and returns to expanded when its control disappears
- Visible default change (FR11), not breaking: a block with no header shows its controls in their own column beside the code instead of over it, so its code ends that much earlier, a block sized to its content (`fit-content`) grows by the column's width, and a one-line block reads as one row. A block with a title or a visible language label keeps its header at every line count. Markdown fences with no language take it through the default code path (`component:Markdown`). No prop, type, or target migration follows from it.
- Visible default change (FR12), not breaking: blocks and Markdown fences in the newly built-in languages are highlighted instead of plain, and the exported `tokenize`, `tokenizeAsync`, and `tokenizeStreaming` functions, with the RichText code blocks and editors that call them, return tokens for those identifiers; text, copy output, labels, and a custom `tokenizer` are unchanged, and the built-in tokenizer grows within the PR4 budget. Markdown fences reach these identifiers by their leading word characters (`component:Markdown` FR29): `cpp` and `objc` fences highlight as C++ and Objective-C, while a `c++` fence reads as `c` and an `objective-c` fence as plain `objective`.

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.

The Markdown side reads correctly now. One more surface to consider: RichText keeps a fence's whole first word (packages/richtext/src/markdownCodeFence.ts:65-67), so once FR12 ships the same c++ or objective-c fence would edit with the C++ or Objective-C grammar but read as c or plain objective. If that difference is intended, consider naming it here, for example: “…; RichText keeps the whole first word, so those two fences edit as C++ and Objective-C.” Otherwise dropping the c++ and objective-c aliases avoids it.

…il becomes provider-scoped modules (FR12, FR13, PR4, DEC-4)

The native set is the 11 known families plus C/C++, SQL, Rust, Kotlin, Swift,
and Go, within 4,608 bytes gzipped. GraphQL, Java, Thrift, Objective-C, TOML,
PowerShell, Ruby, Lua, and Dockerfile are importable modules from
@astryxdesign/core/CodeBlock/languages, turned on by CodeLanguageProvider for
CodeBlock, Markdown fences, and RichText code blocks alike; each adds at most
512 bytes. AST-061 notes RichText reads the same provider.
@cixzhang cixzhang changed the title docs(spec): CodeBlock builds in 15 more language families within a 6 KB tokenizer budget docs(spec): CodeBlock native language set by use, plus importable language modules under one provider Oct 24, 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.

This spec change can't be approved yet: FR12, FR13, PR4 and DEC-4 add new requirements and new public API to the CodeBlock record (seven more built-in language families, nine importable modules turned on by CodeLanguageProvider, and a 4,608-byte tokenizer cap with 512 bytes per module), and an engineering owner needs to record that decision by commenting /approve-spec <full head SHA> on this pull request; the author, as an engineering owner, may do so. Two corrections should land first, so the approval covers the final head:

  • The new spec:AST-061 line says read and edit paint the same languages, but Markdown hands CodeBlock a fence's leading word characters while RichText keeps the whole first word, so c++ fences read as C and edit as C++, and objective-c fences read plain and edit as Objective-C; qualify the line or drop those two aliases.
  • FR13 requires RichText code blocks to paint provided modules, but RichText colours with the exported tokenize(code, language), which takes no modules; name the export RichText reads the provider through, and where CodeLanguageProvider is exported from.

[Automated review]

Comment on lines +162 to +164
RichText code blocks colour with `component:CodeBlock`'s tokenizer and read the
same `CodeLanguageProvider` (`component:CodeBlock` FR13), so read and edit paint
the same languages.

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.

This holds for most fences, but not for c++ and objective-c: Markdown hands CodeBlock the fence's leading word characters (component:Markdown FR29), so they read as c and objective, while RichText keeps the whole first word (packages/richtext/src/markdownCodeFence.ts:65-67) and would edit them as C++ and, inside a provider, Objective-C. Consider qualifying the sentence, or dropping those two aliases from FR12 and FR13.

- Controlled/uncontrolled behavior: collapse state remains component-owned, starts expanded when applicable, and returns to expanded when its control disappears
- Visible default change (FR11), not breaking: a block with no header shows its controls in their own column beside the code instead of over it, so its code ends that much earlier, a block sized to its content (`fit-content`) grows by the column's width, and a one-line block reads as one row. A block with a title or a visible language label keeps its header at every line count. Markdown fences with no language take it through the default code path (`component:Markdown`). No prop, type, or target migration follows from it.
- Visible default change (FR12), not breaking: blocks and Markdown fences in the newly built-in languages are highlighted instead of plain, and the exported `tokenize`, `tokenizeAsync`, and `tokenizeStreaming` functions, with the RichText code blocks and editors that call them, return tokens for those identifiers; text, copy output, labels, and a custom `tokenizer` are unchanged, and the built-in tokenizer grows within the PR4 budget. Markdown fences reach these identifiers by their leading word characters (`component:Markdown` FR29): a `cpp` fence highlights as C++, while a `c++` fence reads as `c`.
- Additive API (FR13): `@astryxdesign/core/CodeBlock/languages` and `CodeLanguageProvider` are new; nothing changes until a product imports a module and renders the provider.

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.

FR13 asks RichText code blocks to paint provided modules, but RichText colours with the exported tokenize(code, language) (packages/richtext/src/CodeSyntaxPlugin.tsx:77), which takes no modules, and it can only reach core through published subpaths. Whatever carries the provider's modules there (a hook, a context, or a module argument) is public API too; worth naming it here, along with the entry point that exports CodeLanguageProvider.

…Text reads; AST-061 qualifies two fence spellings

FR13 names useCodeLanguages() and the optional modules argument of the
exported tokenize functions, from @astryxdesign/core/CodeBlock beside
CodeLanguageProvider. AST-061 notes that c++ and objective-c fences read by
their leading word in Markdown and by the whole word in RichText.

@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.

This spec change can't be approved yet: FR12, FR13, PR4 and DEC-4 add new requirements and public API to the CodeBlock record (seven more built-in language families, nine importable modules turned on by CodeLanguageProvider, and a 4,608-byte tokenizer cap with 512 bytes per module), and an engineering owner needs to record that decision by commenting /approve-spec <full head SHA> on this pull request; the author, as an engineering owner, may do so. The RichText export and the c++/objective-c qualification are in, and two corrections should land first so the approval covers the final head:

  • DEC-4 opens with "A reader sees a snippet highlighted in its first render", but PR1 still tokenizes code of 2,000 or more characters asynchronously; scope it to short code, as PR4 does.
  • The new spec:AST-061 exception names only c++ and objective-c, but the same leading-word rule also splits c# and rust,ignore fences once FR12 ships (and diff-ts fences today); state the rule rather than two spellings, or drop "so read and edit paint the same languages".

[Automated review]


**Decider:** `cixzhang`, `2026-10-24`

A reader sees a snippet highlighted in its first render, with no product setup, for the languages people write most: the native set is the 11 families CodeBlock already knows plus C and C++, SQL, Rust, Kotlin, Swift, and Go, which together cover about 97% of fences that name a language in a large engineering Markdown corpus, inside a 4,608-byte budget every consumer pays. Less common languages are opt-in modules, so a product pays only for the ones it imports; one scoped provider turns them on for CodeBlock, Markdown fences, and RichText code blocks alike, because those surfaces render blocks with no per-block props, and read and edit must paint the same languages. Modules are opaque so the grammar format stays internal; any other language uses the `tokenizer` prop. Rejected: every family built in (every consumer pays for the long tail, and the set cannot grow); a per-block `languages` prop (Markdown and RichText could not pass it); a global registry (state shared across React roots and requests); loading grammars on demand (a block would paint plain, then recolour, and wait on the network).

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.

This promise holds only for short code: PR1 sends long built-in code through the async tokenizer, and useTokenLines returns no tokens on the first render for 2,000 or more characters (CodeBlock.tsx:610-612, tokenizer.ts:427). PR4 already scopes it, and an earlier revision of this decision did too; suggest "A reader sees a short snippet highlighted in its first render (PR1), with no product setup, ...".

Comment on lines +162 to +167
RichText code blocks colour with `component:CodeBlock`'s tokenizer and read the
same `CodeLanguageProvider` through `useCodeLanguages()` (`component:CodeBlock`
FR13), so read and edit paint the same languages, except fences spelled `c++` or
`objective-c`: `Markdown` reads a fence by its leading word characters
(`component:Markdown` FR29), so it paints those as `c` and plain `objective`,
while RichText keeps the whole word.

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.

The split this line explains reaches every fence whose first word runs past letters, digits and underscores, not only c++ and objective-c: once FR12 ships, a c# fence reads with the C grammar and edits plain, and a rust,ignore fence reads as Rust and edits plain; a diff-ts fence already reads as ts with the diff layer and edits plain. Suggest stating the rule, for example "except a fence whose first word runs past letters, digits and underscores, such as c++, c#, objective-c, rust,ignore or diff-ts".

…ates the fence first-word rule

DEC-4 promises first-render paint for short code, as PR1 and PR4 do. AST-061
states the rule behind the read/edit exception: a fence whose first word runs
past letters, digits, and underscores reads by its leading word in Markdown
and by the whole word in RichText.

@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.

This spec change needs no further edits: the DEC-4 first-render scoping and the AST-061 fence rule are in, and both records match the shipped tokenizer and Markdown's fence handling. Because FR12, FR13, PR4 and DEC-4 add new requirements and public API to the CodeBlock record (seven more built-in language families, nine importable modules turned on by CodeLanguageProvider, and a 4,608-byte tokenizer cap with 512 bytes per module), together with a new spec:AST-061 line, approval waits on an engineering owner recording that decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a1301a3

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 24, 2026
@github-actions github-actions Bot added the spec-auto-merge Auto-merge was enabled by the spec owner gate label Oct 24, 2026
@cixzhang
cixzhang merged commit 39b5981 into main Oct 24, 2026
54 checks passed
@github-actions
github-actions Bot deleted the codeblock-languages-spec branch October 25, 2026 06:20

This branch was successfully deployed

1 active deployment
Preview — a1301a39 Deployed Oct 24, 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. spec-auto-merge Auto-merge was enabled by the spec owner gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant