Skip to content

[EuiCodeBlock] Keep virtualized rows mounted when props change - #10390

Merged
eokoneyo merged 5 commits into
elastic:mainfrom
sravanth-space:code-block-virtualized-stable-elements-v2
Nov 27, 2026
Merged

eokoneyo merged 5 commits into
elastic:mainfrom
sravanth-space:code-block-virtualized-stable-elements-v2

Conversation

@sravanth-space

@sravanth-space sravanth-space commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Makes the virtualized outer and inner element types stable module-level memo(forwardRef(...)) components, fed by context
  • Merges a consumer style into the inner <code> without letting it override react-window's list size

Closes #10251

Why are we making this change?

EuiCodeBlockVirtualized built both element types in useMemo. The inner one depended on codeProps and label, which change identity on every render, so react-window remounted the <code> tree on each update (flicker, lost text selection).

Following the review in #10251, the inner <code> now puts codeProps first and react-window's style after it. Before, a consumer style overwrote react-window's block-size, collapsing the scroll range so rows past the first few were unreachable. Non-conflicting consumer styles (e.g. padding) are kept. A consumer height, width, blockSize or inlineSize is ignored, since react-window owns the list size, and react-window's pointerEvents wins while scrolling. I left the outer <pre> order unchanged: react-window passes className={undefined}, so spreading it after preProps would drop euiCodeBlock__pre.

Screenshots

No visual change. Measured in Chrome with a virtualized block that gets one new line per second for 13 s, plus a 200-row block with style={{ padding: 0 }} and overflowHeight={100}:

Before (main) After
<code> element replaced 10 times 0 times
Scroll height of the styled block 168px (rows unreachable) 3648px
Video before video after video

Impact to users

🟢 No changes required on the consumer side.

QA

General checklist

  • Browser QA
    • Checked for accessibility including keyboard-only and screenreader modes
  • Code quality checklist
    • Added or updated jest tests
    • Updated visual regression tests
  • Release checklist
    • A changelog entry exists and is marked appropriately

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?

@github-actions github-actions Bot added the community contribution (Don't delete - used for automation) label Nov 24, 2026
@sravanth-space
sravanth-space marked this pull request as ready for review November 24, 2026 11:59
@sravanth-space
sravanth-space requested a review from a team as a code owner November 24, 2026 11:59
Make the virtualized outer and inner element types stable module-level
components fed by context so react-window no longer remounts the
`<code>` tree on every render. Spread react-window's style after
`codeProps` so a consumer `style` cannot clear the list's block size.
@sravanth-space
sravanth-space force-pushed the code-block-virtualized-stable-elements-v2 branch from 25ac049 to 33554da Compare November 24, 2026 14:08
Merge a consumer `style` into the inner `<code>` instead of letting it
overwrite react-window's list style. A consumer `width`/`inlineSize`
replaces the list's inline size. A consumer `height`, `blockSize` or
min/max block size is ignored so the scroll range is kept, and
react-window's `pointerEvents` wins while scrolling.

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

Hey @sravanth-space your changes LGTM, I've just left some improvements we can make.

@sravanth-space

Copy link
Copy Markdown
Contributor Author

Hey @sravanth-space your changes LGTM, I've just left some improvements we can make.

Hi @eokoneyo Thanks for the review. I just pushed the refactors. Please have a look.

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

Thanks for bringing this up and following through with a fix.

@eokoneyo

Copy link
Copy Markdown
Contributor

buildkite test this

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

@eokoneyo
eokoneyo merged commit 9e7db90 into elastic:main Nov 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community contribution (Don't delete - used for automation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EuiCodeBlock] Virtualized code block remounts its rows on every re-render

2 participants