Repository navigation
fix(EuiCodeBlock): keep virtualized rows mounted when props change - #10252
sravanth-space wants to merge 1 commit into
Conversation
|
👋 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? |
|
We don't accept community contributions for issues not labelled "help wanted". Please read our contribution guidelines. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change to stabilize virtualized code blocks across re-renders.
No open issues 🎉
What changed in this PR
Fixes #10251 by keeping virtualized EuiCodeBlock elements stable across re-renders, preventing unnecessary remounts that cause flicker and lost text selection.
Changes:
- Moves the outer and inner virtualized components to module scope.
- Passes element props and the screen-reader label through context without changing the public API.
- Adds a regression test confirming that the
<code>DOM node survives content updates.
| File | Description |
|---|---|
packages/eui/src/components/code/code_block.test.tsx |
Tests <code> node identity after a content update. |
packages/eui/src/components/code/code_block_virtualized.tsx |
Uses stable component types and context to update props without remounting. |
Review effort: Balanced
|
@sravanth-space please read our contributing guidelines. Let's first agree on a direction in the issue and only once we label it "help wanted", we can accept an external contribution. This helps us manage our workload and make sure every change is in accordance with our roadmap. |
Summary
EuiCodeBlockVirtualizedno longer remounts the inner<code>element and its rows whenEuiCodeBlockre-renders.VirtualizedOuterElementandVirtualizedInnerElementare now stable module-level components.preProps,codePropsandlabelreach them through context.<code>element is the same node after a re-render with new content.useMemowithcodePropsandlabelas dependencies, and both change identity on every render (codePropsdepends on therestprops object;labelis a new JSX element). react-window therefore received a newinnerElementTypeeach time and React remounted the inner tree, which shows as a flicker when content updates often and drops any text selection.API Changes
No public API changes.
Screenshots
No visual change. The difference is in the DOM: the
<code>element is no longer replaced on each content update.<code>replaced once per update (13 times in ~12 s in the repro)Impact Assessment
components/codesnapshots are unchanged, no HTML structure or class names changed.Not yet tested in Kibana.
Impact level: 🟢 Low
Release Readiness
n/an/an/an/a, bug fixQA instructions for reviewer
EuiCodeBlockevery second. With this change the "replaced" counter stays at 0 (onmainit grows by about 1 per second).EuiCodeBlockstill scrolls and updates correctly.code block:) still work on a virtualized block.Checklist before marking Ready for Review
QA: Tested docs changesBreaking changes: Addedbreaking changelabelReviewer checklist
🤖 Generated with Claude Code