Repository navigation
fix(CodeBlock): a long line, or code past maxHeight, scrolls before script runs and in a page that runs none - #11970
Conversation
…cript runs and in a page that runs none
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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.tsxruns 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
maxHeightbefore 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: clipon both axes. - Release note: the viewport still becomes a Tab stop only while its code overflows. Verified: no
tabindexbefore 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
clipand does not scroll, the head computesautoand 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.
- Release note: CodeBlock scrolls a long line or code past
- Files
.changeset/codeblock-scrolls-without-script.md: clearpackages/core/src/CodeBlock/CodeBlock.noScript.test.tsx: clearpackages/core/src/CodeBlock/CodeBlock.tsx: optional comment-length suggestion
| // 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. |
There was a problem hiding this comment.
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:
| // 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. |
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 withastryx 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 onisWrappedfor every block to keep the code readable.Problem and solution fit
useScrollableArea). It keeps a viewport atoverflow: clipuntil script measures that the content overflows (spec:AST-025FR21, DEC-3), so that a fitting area is not a scroll container and does not catch native Sticky from an outer scroller.DEC-3 gives a consumer an explicit way to keep its viewport a Sticky boundary while it fits:
stickyContainment: 'always', whichBottomSheetPanelalready 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 isoverflow: autoon both axes from the served markup on.Expected behavior and authority
component:CodeBlockreview checks reject lost code text, and its FR8 evidence row names "overflow is unreachable" as a failure.spec:AST-025DEC-3:stickyContainment="always"is the explicit opt-in for a consumer whose fitting viewport may remain a Sticky boundary.component:CodeBlockFR8 andspec:AST-025FR12–FR13: the viewport is a Tab stop only while its code overflows. This does not change.Smallest restoration
One option on CodeBlock's
useScrollableAreacall, with a comment that says why. No new API, prop, default or visual change for code that fits.Evidence
overflow-x: clip, it is 338–370 px wide while its content is 847 px, and settingscrollLeftto 200 leaves it at 0.overflow-x: auto, andscrollLeftgoes to 200. The page itself does not overflow, and the viewport has notabindexbefore script runs.useScrollableAreaand ScrollableArea suites pass (242 tests).CodeBlock.noScript.test.tsxchecks 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
Testing
pnpm exec vitest run --project ui packages/core/src/CodeBlock packages/core/src/hooks/useScrollableArea.test.tsx packages/core/src/ScrollableAreaoverflow-x,clientWidth/scrollWidth,scrollLeftafter setting it to 200, page overflow andtabindex(numbers above).node scripts/check-changesets.mjs.