Skip to content

[fix] Heading: a missing level renders an h2 and warns, instead of crashing - #12372

Closed
josephfarina wants to merge 2 commits into
mainfrom
josephfarina/rl-heading-missing-level
Closed

josephfarina wants to merge 2 commits into
mainfrom
josephfarina/rl-heading-missing-level

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Record change (component:Heading): FR1 and the Level row now say that a missing level, or one that is not 1–6, renders h2 at the level 2 scale and warns in development, and that a numeric string reads as its number. Types are unchanged.

Proof: Heading.test.tsx covers a missing level, a numeric string, a bare level (true) and a valid level without a warning: 40/40 pass with CI=1. Prettier, eslint and tsc --noEmit are clean. Gate result: on a frozen set of agent-written pages, 32 of 35 that crashed on a level-less Heading now render (16 fully work). Every page that worked before still works, with no new console errors in light, dark or 390 px phone width. No visual change for a valid level, so there are no before/after pictures.


User impact

A page that renders <Heading> without level (or with a value outside 1–6) fails the whole render with React's "Element type is invalid … got: undefined", because levelToTag[undefined] is undefined. TypeScript flags the missing prop, but JavaScript callers, untyped generated pages and pages rendered without a type check reach runtime. Generated pages hit this often: agents carry over <Heading> and <Heading size="lg"> from other libraries. In a corpus of agent-written pages, it was the most common render crash.

Problem and solution fit

  • The crash happens because Heading indexes its tag map with the raw prop and has no baseline for a missing value.
  • It harms the task because one heading takes down the whole page, and the error names no component or prop.
  • After this change the heading renders as an h2 at the level 2 scale, the common section heading, and a development warning names the prop and the fix (Heading: level must be 1, 2, 3, 4, 5 or 6, but it is undefined. … <Heading level={2}>). A numeric string such as level="3" keeps rendering its level and now warns; other values (a bare level, which passes true) render as level 2.

Expected behavior and authority

component:Heading review check: "Reject … a heading that renders without a level baseline". The record's FR1 and Level row now state the runtime fallback. The type stays level: HeadingLevel (required), so typed callers see no change.

Smallest restoration

One resolver (resolveLevel) plus one useDevWarning call in Heading.tsx. No type, default or styling change for a valid level.

Evidence

  • Reproduction before the change: <Heading>Overview</Heading> throws "Element type is invalid".
  • Result after the change: it renders <h2 data-level="2"> and warns once in development.
  • Representative unchanged path: <Heading level={4}> renders h4 and does not warn.
  • Regression test: four new cases in Heading.test.tsx (missing level, numeric string, bare level that passes true, valid level without a warning).
  • Agent-written pages: of 35 that crashed on a level-less Heading, 32 now render. The other 3 stop at a different, unrelated component error. No page that rendered before fails now.

Scope

Components: Heading

  • 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 packages/core/src/Heading/Heading.test.tsx (40 passed); eslint and prettier on the changed files.

Writing rubric results

R1 narration: none; FR1 and the Level row describe current behavior in the present tense.
R2 research: none in the record; the corpus numbers are only in this description.
R3 evidence: FR1 basis stays "Current source and tests".
R4 rejected alternatives: none recorded.
R5 change references: none.
R6 open questions: none.
R7 project status: none.

@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:15pm UTC

Request Review

@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 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:28 PM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 9b67f41

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
TopNav 79.6 kB (+335 B) · 11.8 kB CSS (0) — — · — · —
MobileNav 77.8 kB (+320 B) · 11.4 kB CSS (0) — — · — · —
AppShell 99.0 kB (+281 B) · 14.4 kB CSS (0) — — · — · —
23 more components
Component Size LoC Visual · A11y · RTL
lab/DialogHeroHeader 90.6 kB (+281 B) · 372 B CSS (0) — — · — · —
DrawerHeader 69.5 kB (+271 B) · 13.8 kB CSS (0) — — · — · —
DialogHeader 69.4 kB (+247 B) · 12.4 kB CSS (0) — — · — · —
Heading 13.9 kB (+225 B) · 5.5 kB CSS (0) — — · — · —
lab/TourStep 95.1 kB (+223 B) · 691 B CSS (0) — — · — · —
MultiSelector 103.4 kB (+218 B) · 17.8 kB CSS (0) — — · — · —
PowerSearch 310.4 kB (+201 B) · 25.6 kB CSS (0) — — · — · —
lab/Comments 377.1 kB (+191 B) · 2.5 kB CSS (0) — — · — · —
Markdown 205.5 kB (+189 B) · 22.1 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 309.3 kB (+186 B) · 454 B CSS (0) — — · — · —
lab/CommentThread 370.3 kB (+185 B) · 2.4 kB CSS (0) — — · — · —
Selector 114.9 kB (+184 B) · 18.7 kB CSS (0) — — · — · —
SideNav 122.6 kB (+175 B) · 12.2 kB CSS (0) — — · — · —
Pagination 147.8 kB (+174 B) · 19.1 kB CSS (0) — — · — · —
AlertDialog 130.1 kB (+165 B) · 15.5 kB CSS (0) — — · — · —
DropdownMenu 108.9 kB (+141 B) · 18.9 kB CSS (0) — — · — · —
MoreMenu 109.2 kB (+137 B) · 18.9 kB CSS (0) — — · — · —
TableHeaderCell 104.5 kB (+128 B) · 19.1 kB CSS (0) — — · — · —
TableCell 104.7 kB (+127 B) · 19.3 kB CSS (0) — — · — · —
ContextMenu 103.4 kB (+119 B) · 18.8 kB CSS (0) — — · — · —
Table 121.9 kB (+116 B) · 19.8 kB CSS (0) — — · — · —
Text · Storybook 13.1 kB (0) · 5.5 kB CSS (0) 859 (0) ✓ · ✓ · —
Tokenizer 105.8 kB (0) · 20.4 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 7.65 MB packed (+861 B); no new dependencies.

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@josephfarina

Copy link
Copy Markdown
Contributor Author

Owner decision (engineering owner, covering this pull request): a Heading given no valid level renders as level 2 instead of crashing the page, and in development warns once per mounted Heading, naming Heading and asking for level. level stays required in the types, so the fallback only catches untyped or invalid input. The Heading record states this, and tests cover a missing level, a string level and a valid level.

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 0a7c720

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval 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.

Approval waits on an engineering owner's decision about the new Heading fallback, and two fixes are needed.

The current component:Heading record does not state the fallback that this pull request writes into FR1 and the Level row: the h2 level, the development warning, and which inputs count as a level. An engineering owner must approve or amend it by commenting /approve-spec with the full head commit SHA, and the author can do this as an engineering owner.

  • A bare level (level={true}) renders an h1, because resolveLevel converts any value with Number(), while the changeset, the doc and the proposed FR1 say that a level that is not 1–6 renders h2; convert only numbers and strings, and add a boolean test case.
  • The changeset lists "A numeric string such as level=\"3\" reads as its number" as part of the fix, but level="3" already rendered h3 before this change, so say instead that it keeps rendering its level and now warns in development.

The new tests fail on the base and pass on the head, and every valid level renders exactly as before.

Claims and files checked

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

  • Claim (changeset): a heading without a level from 1 to 6 renders h2 and warns. False for a bare level, which renders h1.
  • Claim (changeset): it no longer fails with "Element type is invalid". Verified: the new tests fail with that error on the base.
  • Claim (changeset): a numeric string reads as its number. True, but level="3" already did before this change.
  • Claim (description): a missing level crashed the render. Verified.
  • Claim (description): TypeScript already flags a missing level. Verified: level is required.
  • Claim (description): the fallback is h2 at the level 2 scale with a warning that names the prop and the fix. Verified.
  • Claim (description): it warns once, in development only. Verified.
  • Claim (description): typed callers and valid levels see no change. Verified.
  • Claim (description): one resolver and one warning call, with no type, default or styling change for a valid level. Verified.
  • Claim (description): three new test cases, 39 tests passing, lint and formatting clean. Verified.
  • Claim (description): the record's review check calls for a level baseline. The quote exists, but it is about theme-added types and does not decide this fallback.
  • Claim (description): the share of agent-written pages that now render. Not checkable from the repository.
  • Claim (description): no internal context in public text. Verified.
  • File packages/core/src/Heading/Heading.tsx: finding (a bare level renders h1; the warning drops the quotes from string values).
  • File packages/core/src/Heading/Heading.test.tsx: clear.
  • File packages/core/src/Text/Heading.doc.mjs: finding (the h2 statement is false for a bare level).
  • File docs/specs/components/Heading/Heading.spec.md: needs an engineering owner's decision; the Level row's "other value renders level 2" disagrees with FR1 on numeric strings.
  • File .changeset/heading-missing-level.md: finding (numeric strings presented as fixed; the h2 statement).

Automated review (maintainer link)

Comment thread packages/core/src/Heading/Heading.tsx Resolved
Comment thread packages/core/src/Heading/Heading.tsx Resolved
Comment thread .changeset/heading-missing-level.md Resolved
@astracat-bot

astracat-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

In reply to @josephfarina

I'll run a full review to re-check this with your note.

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

Changes requested: an engineering owner's approval settles the new Heading fallback, and two fixes remain.

  • A bare level (<Heading level>, which passes true) renders an h1, because resolveLevel converts any value with Number(), while the approved FR1, the changeset and the doc say that a level that is not 1–6 renders h2; convert only numbers and strings, and add a boolean test case.
  • The changeset lists "A numeric string such as level="3" reads as its number" as part of the fix, but level="3" already rendered h3 before this change, so say instead that it keeps rendering its level and now warns in development.

The new tests fail on the base and pass on the head, and every valid level renders exactly as before. Two smaller points: quote string values in the warning message, and make the record's Level row agree with FR1 about numeric strings.

Claims and files checked

Review mode: same-head; reason: none

  • Claim (changeset): a heading without a level from 1 to 6 renders h2 and warns. False for a bare level, which renders h1.
  • Claim (changeset): it no longer fails with "Element type is invalid". Verified: the missing-level test fails with that error on the base and passes on the head.
  • Claim (changeset): a numeric string reads as its number. True, but level="3" already rendered h3 before this change, and the new warning is not mentioned.
  • Claim (description): a missing or out-of-range level crashed the whole render because the tag lookup returned nothing. Verified on the base.
  • Claim (description): TypeScript already flags a missing level. Verified: level is required.
  • Claim (description): the fallback is h2 at the level 2 scale, with a development warning that names the prop and the fix. Verified.
  • Claim (description): a numeric string reads as its number and also warns. Verified.
  • Claim (description): the record's FR1 and Level row state the runtime fallback. Verified, and an engineering owner approved them at this head.
  • Claim (description): the record's review check calls for a level baseline. The quoted check exists, but it is about the scale a theme-added type keeps, not this fallback.
  • Claim (description): typed callers and valid levels see no change, with no type, default or styling change for a valid level. Verified.
  • Claim (description): one resolver and one warning call. Verified.
  • Claim (description): a level-less heading threw before and now renders an h2 with data-level="2" and warns once; level={4} renders h4 without a warning. Verified.
  • Claim (description): three new test cases, 39 tests passing, lint and formatting clean. Verified: 39 pass at the head, and the Lint workflow passed.
  • Claim (description): the share of generated pages that now render. Not checkable from the repository.
  • Claim (description): the record changes use the present tense and add no open questions or project status. Verified.
  • Claim (description): no internal context in public text. Verified.
  • File packages/core/src/Heading/Heading.tsx: finding (a bare level renders h1; the warning drops the quotes from string values).
  • File packages/core/src/Heading/Heading.test.tsx: clear.
  • File packages/core/src/Text/Heading.doc.mjs: its h2 statement is false for a bare level until the resolver is fixed.
  • File docs/specs/components/Heading/Heading.spec.md: approved by an engineering owner at this head; non-blocking (the Level row and FR1 disagree about numeric strings, and the verification map does not name the new tests).
  • File .changeset/heading-missing-level.md: finding (numeric strings presented as fixed; the h2 statement is false for a bare level).

Automated review (maintainer link)

@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 9b67f41

@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 finished on this head yet.

The Heading fallback matches the record change an engineering owner approved for this head, and both earlier fixes are in: a bare level now renders an h2, and the changeset describes level="3" accurately. The new tests fail on the base and pass on the head, and every valid level renders as before. One optional follow-up: name the new fallback cases in the record's verification map row for FR1.

Claims and files checked

Review mode: full; reason: spec-record

  • Claim (changeset): a heading without a level from 1 to 6 renders h2 and warns in development, instead of failing with "Element type is invalid". Verified: the missing-level and bare-level tests fail with that error on the base and pass on the head.
  • Claim (changeset): level="3" keeps rendering its level and now warns. Verified: h3 with no warning on the base, h3 with one warning on the head.
  • Claim (description): a missing or out-of-range level failed the whole render because the tag lookup returned nothing. Verified on the base.
  • Claim (description): TypeScript already flags a missing level, and the type stays required. Verified.
  • Claim (description): the fallback is h2 at the level 2 scale, with a development warning that names the prop and the fix. Verified.
  • Claim (description): a numeric string keeps its level and now warns, and a bare level renders level 2. Verified.
  • Claim (description): the record's FR1 and Level row state the fallback. Verified, and an engineering owner approved them at this head.
  • Claim (description): the record's review check calls for a level baseline. The quoted check exists; it concerns the scale a theme-added type keeps, and the fallback rests on the approved FR1.
  • Claim (description): one resolver plus one warning call, with no type, default or styling change for a valid level. Verified.
  • Claim (description): a level-less heading threw before and now renders an h2 with data-level="2" and warns once; level={4} renders h4 without a warning. Verified.
  • Claim (description): four new test cases, 40 tests passing, lint and formatting clean. Verified.
  • Claim (description): the share of generated pages that now render. Not checkable from the repository.
  • Claim (description): the record text uses the present tense and adds no research, open questions or project status. Verified.
  • Claim (description): no internal context in public text. Verified.
  • File packages/core/src/Heading/Heading.tsx: clear.
  • File packages/core/src/Heading/Heading.test.tsx: clear.
  • File packages/core/src/Text/Heading.doc.mjs: clear.
  • File docs/specs/components/Heading/Heading.spec.md: approved at this head; non-blocking note on the verification map.
  • File .changeset/heading-missing-level.md: clear.

Automated review (maintainer link)

josephfarina added a commit that referenced this pull request Nov 19, 2026
- #12694 fix(cli): the Order Detail template's discount uses a minus sign held to its amount
  Author: @josephfarina
- #12114 fix(templates): reset, reply, send and go-into icons mirror in right-to-left pages
  Author: @josephfarina
- #12143 refactor(templates): example blocks lay out with HStack and VStack instead of flex wrappers
  Author: @josephfarina
- #12158 fix(core): ChatComposer keeps its send action inside the composer on a narrow screen
  Author: @josephfarina
- #12242 fix(cli): the npm commands the CLI runs for itself use npm's own noproxy setting
  Author: @josephfarina
- #12283 fix(core): dark secondary text meets 4.5:1 on the neutral fill over the page and cards
  Author: @josephfarina
- #12290 fix(Markdown): keep bulleted and numbered lists inside their column
  Author: @josephfarina
- #12372 [fix] Heading: a missing level renders an h2 and warns, instead of crashing
  Author: @josephfarina
- #12447 spec(AST-057): the swipe codemod's paths match it in any lifecycle folder
  Author: @josephfarina
- #12475 fix(templates): on a phone the settings search moves under the title
  Author: @josephfarina
- #12530 fix(cli): the contact-form template fits a phone; its section fills the width up to 800px
  Author: @josephfarina
@josephfarina

Copy link
Copy Markdown
Contributor Author

Landed in #12812.

@github-actions
github-actions Bot deleted the josephfarina/rl-heading-missing-level branch November 19, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 9b67f415 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