You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[EuiCodeBlock] Virtualized code block remounts its rows on every re-render #10251
With isVirtualized, every re-render of EuiCodeBlock replaces the inner <code> element and all rows inside it with new DOM nodes. When the content updates often (for example streaming logs) this shows as a brief, intermittent flicker, and a text selection inside the block is lost within a second.
Cause: EuiCodeBlockVirtualized creates VirtualizedOuterElement and VirtualizedInnerElement inside useMemo. The inner element depends on [codeProps, label], and both change identity on every render of EuiCodeBlock:
codeProps is a useMemo that lists rest as a dependency, and rest is a new object on every render.
codeBlockLabelElement is a new JSX element on every render.
react-window therefore receives a new innerElementType each time and React unmounts and remounts the whole inner tree. The outer <pre> is not affected.
Impact and severity
Visual only: a short flicker when content of a virtualized code block updates frequently, plus lost text selection. No data loss. In our case it is the live log panel, where it is uncomfortable to look at. Workaround: do not use isVirtualized, which is not practical for large content.
Hi @weronikaolejniczak, thanks for pointing me to the contributing guidelines. I missed them and opened #10252 before agreeing on a direction here. Let's discuss the approach here, as you suggested.
EuiCodeBlockVirtualized creates innerElementType in useMemo with codeProps and label as dependencies. Both change identity on every render (codeProps depends on the rest props object, and label is a new JSX element), so react-window gets a new element type each time and React remounts the inner <code> tree. With frequent content updates this shows as a flicker and drops any text selection. In the repro, the <code> element was replaced 13 times in about 12 seconds.
Proposed fix: make both element types stable module-level components and pass preProps, codeProps and label to them through context. Props would still update the rendered elements, but nothing would remount. EuiCodeBlock keeps the same props, exports and types. Only the internals of EuiCodeBlockVirtualized change, so consumers don't have to change anything.
Would you be open to this approach? If so, I'd be happy to contribute the fix once the issue is labelled "help wanted". If you'd prefer a different approach, or to handle it in-house, that works for me too.
Hi @sravanth-space, thanks for the detailed writeup — the diagnosis is correct, and stabilising the element types via context is indeed the right fix for react-window v1. Worth noting it's also the pattern EUI already uses for the same problem in data_grid_body_virtualized.tsx, which cites the same upstream issue. Worth mirroring that file's memo(forwardRef(...)) + displayName while you're in here.
One thing I noticed that I'd implore you to address whilst fixing this, because I see your original proposed PR rewrites the exact lines it lives on:
codeProps is { className, css, 'data-code-language', ...rest }, typed as EuiCodeSharedProps which is infact CommonProps & HTMLAttributes<HTMLElement>, so style is a public, typed prop on EuiCodeBlock that ends up in rest and overwrites react-window's inner style. That style is the only thing establishing the list's scroll range — react-window sets height: estimatedTotalSize on the inner element, and the rows themselves are position: absolute.
Rendering 200 rows at overflowHeight={100} on main:
without a consumer style: <code style="block-size: 3600px; inline-size: 100%;">
with a style={{ padding: 0 }}: <code style="padding: 0px;">
The computed 3600px is gone, so the <pre>'s scrollable extent collapses to roughly the last rendered row and rows 9–200 become unreachable — the list stops virtualising in any useful sense. It only affects the virtualized path; non-virtualized just puts the style on <code> harmlessly.
This is pre-existing on main rather than something you introduced, but since you're rewriting these lines it'd be good to fix here. Spreading EUI's props first resolves it:
The outer <pre> has the same ordering issue. It's only latent today (preProps is a closed set with no style), but preProps.className does silently drop any className react-window passes through, so it's worth reordering both for consistency.
👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.
Thanks @eokoneyo, that's helpful. I'll mirror the memo(forwardRef(...)) + displayName pattern from data_grid_body_virtualized.tsx and reorder the spreads on both elements so react-window's style wins. I'll add a test for the consumer style case and open a PR shortly.
@eokoneyo PR is up (#10390) with your inner-element ordering: a consumer style is no longer applied to the virtualized <code>, so padding: 0 or pointerEvents are ignored there. Is that acceptable as-is, or would you prefer merging non-conflicting styles (and/or a breaking change label)?
@eokoneyo PR is up (#10390) with your inner-element ordering: a consumer style is no longer applied to the virtualized <code>, so padding: 0 or pointerEvents are ignored there. Is that acceptable as-is, or would you prefer merging non-conflicting styles (and/or a breaking change label)?
Hello @sravanth-space thanks for the contribution, I'll take a look at your PR; that been said we should aim to merge non-conflicting styles.
Activity
sravanth-space commentedon Nov 18, 2026
Hi @weronikaolejniczak, thanks for pointing me to the contributing guidelines. I missed them and opened #10252 before agreeing on a direction here. Let's discuss the approach here, as you suggested.
EuiCodeBlockVirtualizedcreatesinnerElementTypeinuseMemowithcodePropsandlabelas dependencies. Both change identity on every render (codePropsdepends on therestprops object, andlabelis a new JSX element), so react-window gets a new element type each time and React remounts the inner<code>tree. With frequent content updates this shows as a flicker and drops any text selection. In the repro, the<code>element was replaced 13 times in about 12 seconds.Proposed fix: make both element types stable module-level components and pass
preProps,codePropsandlabelto them through context. Props would still update the rendered elements, but nothing would remount.EuiCodeBlockkeeps the same props, exports and types. Only the internals ofEuiCodeBlockVirtualizedchange, so consumers don't have to change anything.Would you be open to this approach? If so, I'd be happy to contribute the fix once the issue is labelled "help wanted". If you'd prefer a different approach, or to handle it in-house, that works for me too.
eokoneyo commentedon Nov 24, 2026
Hi @sravanth-space, thanks for the detailed writeup — the diagnosis is correct, and stabilising the element types via context is indeed the right fix for react-window v1. Worth noting it's also the pattern EUI already uses for the same problem in data_grid_body_virtualized.tsx, which cites the same upstream issue. Worth mirroring that file's memo(forwardRef(...)) + displayName while you're in here.
One thing I noticed that I'd implore you to address whilst fixing this, because I see your original proposed PR rewrites the exact lines it lives on:
Both new components spread the EUI props last:
codeProps is
{ className, css, 'data-code-language', ...rest }, typed asEuiCodeSharedPropswhich is infactCommonProps & HTMLAttributes<HTMLElement>, so style is a public, typed prop onEuiCodeBlockthat ends up in rest and overwrites react-window's inner style. That style is the only thing establishing the list's scroll range — react-window setsheight: estimatedTotalSizeon the inner element, and the rows themselves areposition: absolute.Rendering 200 rows at overflowHeight={100} on main:
without a consumer style:
<code style="block-size: 3600px; inline-size: 100%;">with a style={{ padding: 0 }}:
<code style="padding: 0px;">The computed 3600px is gone, so the
<pre>'s scrollable extent collapses to roughly the last rendered row and rows 9–200 become unreachable — the list stops virtualising in any useful sense. It only affects the virtualized path; non-virtualized just puts the style on<code>harmlessly.This is pre-existing on main rather than something you introduced, but since you're rewriting these lines it'd be good to fix here. Spreading EUI's props first resolves it:
The outer
<pre>has the same ordering issue. It's only latent today (preProps is a closed set with no style), butpreProps.classNamedoes silently drop any className react-window passes through, so it's worth reordering both for consistency.github-actions commentedon Nov 24, 2026
👋 Thank you for your suggestion or request! While the EUI team agrees that it's valid, it's unlikely that we will prioritize this issue on our roadmap. We'll leave the issue open if you or anyone else in the community wants to implement it by contributing to EUI. If not, this issue will auto close in one year.
sravanth-space commentedon Nov 24, 2026
Thanks @eokoneyo, that's helpful. I'll mirror the
memo(forwardRef(...))+displayNamepattern fromdata_grid_body_virtualized.tsxand reorder the spreads on both elements so react-window'sstylewins. I'll add a test for the consumerstylecase and open a PR shortly.sravanth-space commentedon Nov 24, 2026
@eokoneyo PR is up (#10390) with your inner-element ordering: a consumer
styleis no longer applied to the virtualized<code>, sopadding: 0orpointerEventsare ignored there. Is that acceptable as-is, or would you prefer merging non-conflicting styles (and/or abreaking changelabel)?eokoneyo commentedon Nov 24, 2026
Hello @sravanth-space thanks for the contribution, I'll take a look at your PR; that been said we should aim to merge non-conflicting styles.