Skip to content

fix(CodeBlock): a long line, or code past maxHeight, scrolls before script runs and in a page that runs none - #11970

Merged
josephfarina merged 1 commit into
mainfrom
josephfarina/codeblock-scrolls-without-script
Nov 16, 2026
Merged

josephfarina merged 1 commit into
mainfrom
josephfarina/codeblock-scrolls-without-script

Conversation

@josephfarina

Copy link
Copy Markdown
Contributor

User impact

A reader of a page that has not run script yet, or never will, could not see the end of a long code line, or the code below maxHeight. The code viewport cut it off at the edge of the block, with no way to scroll. This hits every server-rendered page until it hydrates, a reader with script turned off, and every static page, such as a file made with astryx experimental render. On a 420 px phone, any line wider than the block was cut off. A real page shared this week hit it, and its author had to turn on isWrapped for every block to keep the code readable.

Problem and solution fit

  1. Why it occurs: the code viewport uses the shared scroll capability (useScrollableArea). It keeps a viewport at overflow: clip until script measures that the content overflows (spec:AST-025 FR21, DEC-3), so that a fitting area is not a scroll container and does not catch native Sticky from an outer scroller.
  2. Why it harms the task: before script runs, and always in a page with no script, nothing measures, so the overflow stays clipped and cannot be reached.
  3. Why that matters: the code is the content. A cut-off line is lost code text.

DEC-3 gives a consumer an explicit way to keep its viewport a Sticky boundary while it fits: stickyContainment: 'always', which BottomSheetPanel already uses. Nothing inside the code viewport sticks to an outer scroller: the sticky header and the corner controls are siblings of the viewport, not inside it. So CodeBlock opts in, and its viewport is overflow: auto on both axes from the served markup on.

Expected behavior and authority

  • component:CodeBlock review checks reject lost code text, and its FR8 evidence row names "overflow is unreachable" as a failure.
  • spec:AST-025 DEC-3: stickyContainment="always" is the explicit opt-in for a consumer whose fitting viewport may remain a Sticky boundary.
  • component:CodeBlock FR8 and spec:AST-025 FR12–FR13: the viewport is a Tab stop only while its code overflows. This does not change.

Smallest restoration

One option on CodeBlock's useScrollableArea call, with a comment that says why. No new API, prop, default or visual change for code that fits.

Evidence

  • Reproduction before the change: a page with a long-line CodeBlock (in a Grid cell, a Card, an HStack fill item and a bare HStack), rendered to a static file and opened in Chromium at 420 px. In each case the viewport computes overflow-x: clip, it is 338–370 px wide while its content is 847 px, and setting scrollLeft to 200 leaves it at 0.
  • Result after the change: the same page and the same four cases compute overflow-x: auto, and scrollLeft goes to 200. The page itself does not overflow, and the viewport has no tabindex before script runs.
  • Representative unchanged path: a fitting CodeBlock looks the same (no scrollbar). The Tab stop, the focus ring, copy, collapse and wrapping behave as before: the CodeBlock, useScrollableArea and ScrollableArea suites pass (242 tests).
  • Regression test: CodeBlock.noScript.test.tsx checks that the served markup lets the viewport scroll a long line and a height-bounded block, and that there is no Tab stop before overflow is measured. All three tests fail without the change.

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

  • pnpm exec vitest run --project ui packages/core/src/CodeBlock packages/core/src/hooks/useScrollableArea.test.tsx packages/core/src/ScrollableArea
  • Chromium at 420 px over static renders of the reproduction page, built from main and from this branch: computed overflow-x, clientWidth/scrollWidth, scrollLeft after setting it to 200, page overflow and tabindex (numbers above).
  • Prettier and ESLint on the changed files; node scripts/check-changesets.mjs.

@vercel

vercel Bot commented Nov 16, 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 16, 2026 2:12am UTC

Request Review

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

astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 16, 2026, 2:26 AM UTC

@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 is still running on this head, and no check has failed so far.

The change lets CodeBlock scroll a long line, or code past maxHeight, in server-rendered and script-free pages by opting into the scroll hook's explicit stickyContainment: 'always'; the new test fails without it, and hydrated CodeBlocks render exactly as before. Nothing blocks, and one optional suggestion follows:

  • The second sentence of the new comment in CodeBlock.tsx runs 30 words, past the repository's 25-word comment limit; the inline suggestion shortens it.
Claims and files checked

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

  • Claims
    • Release note: CodeBlock scrolls a long line or code past maxHeight before script runs and in a page without script, such as a rendered static file. Verified: a static render scrolls 200 px sideways and 80 px down on this head and not at all on the base.
    • Release note: until now the code was cut off until script measured it, and stayed cut off in a static page. Verified: the base serves overflow: clip on both axes.
    • Release note: the viewport still becomes a Tab stop only while its code overflows. Verified: no tabindex before script; tabindex="0" after hydration on overflowing stories, as before.
    • Description: the shared scroll hook keeps a viewport clipped until script measures overflow. Verified in the hook's overflow styling.
    • Description: nothing inside the code viewport is sticky; the header and corner controls are its siblings. Verified in CodeBlock.tsx.
    • Description: the bottom sheet panel already uses the same opt-in. Verified.
    • Description: the CodeBlock record rejects lost code text and lists unreachable overflow as a failure, and the scroll record names the opt-in as explicit. Verified.
    • Description: no new API, prop, default or visual change for code that fits. Verified: the API report has no rows, and before and after frames are identical.
    • Description: at 420 px the base computes clip and does not scroll, the head computes auto and scrolls 200 px, the page does not overflow, and there is no Tab stop before script. Verified for a bare block and a block in a Card.
    • Description: the CodeBlock, scroll hook and ScrollableArea suites pass (242 tests). Verified.
    • Description: all three new tests fail without the change. Verified.
    • Description: Prettier, ESLint and the changeset check pass. Verified.
    • Description: a real page hit this problem this week. Not checkable; context only.
  • Files
    • .changeset/codeblock-scrolls-without-script.md: clear
    • packages/core/src/CodeBlock/CodeBlock.noScript.test.tsx: clear
    • packages/core/src/CodeBlock/CodeBlock.tsx: optional comment-length suggestion

Automated review (maintainer link)

Comment on lines +1145 to +1149
// Nothing inside the code viewport sticks to an outer scroller, so the
// viewport stays a scroll container while its code fits. A long line, or
// code past `maxHeight`, then scrolls from the first paint: before script
// measures it, and in a page that never runs script, such as a rendered
// file. The Tab stop still follows measured overflow.

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.

Optional: the second sentence here runs 30 words, past the repository's 25-word limit for a descriptive comment (INV29 in docs/architecture/knowledge-contracts.md). A shorter form that keeps the reason:

Suggested change
// Nothing inside the code viewport sticks to an outer scroller, so the
// viewport stays a scroll container while its code fits. A long line, or
// code past `maxHeight`, then scrolls from the first paint: before script
// measures it, and in a page that never runs script, such as a rendered
// file. The Tab stop still follows measured overflow.
// Nothing in the code viewport sticks to an outer scroller. So the viewport
// stays a scroll container while its code fits. Then overflow scrolls before
// script runs, and in a page with no script. The Tab stop still follows
// measured overflow.

@josephfarina
josephfarina merged commit cd3ed29 into main Nov 16, 2026
87 checks passed
@github-actions
github-actions Bot deleted the josephfarina/codeblock-scrolls-without-script branch November 16, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — f64b150c Deployed Nov 16, 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