Skip to content

fix(EuiCodeBlock): fixes re-renders causing blank lines to appear when using isVirtualized if scrolled - #9196

Merged
mgadewoll merged 7 commits into
elastic:mainfrom
sravanth-space:fix/virtualized-code-block-label-bug
Nov 14, 2025
Merged

mgadewoll merged 7 commits into
elastic:mainfrom
sravanth-space:fix/virtualized-code-block-label-bug

Conversation

@sravanth-space

@sravanth-space sravanth-space commented Nov 9, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Partially reverts the implementation approach from PR #8887 while maintaining the accessibility improvements.

Why are we making this change?

Problem:
After PR #8887, the accessibility label was injected inside the <pre> element managed by react-window's virtualization as part of the VirtualizedOuterElement. This caused react-window to miscalculate scroll offsets, resulting in blank lines appearing when:

  • User scrolls down in a virtualized code block
  • Content is updated (e.g., build logs appending new lines)
  • The component re-renders

Root Cause:
react-window's FixedSizeList requires the outer element to be "pure" - any injected content disrupts its internal measurements and scroll position calculations.

Solution:

  • Move the accessibility label from VirtualizedOuterElement to VirtualizedInnerElement to ensure a stable container for the virtualized calculations
    • the label remains a child of the pre element and hence is read as label when the code element is focused
    • This ensures the outer virtualized container stays clean for proper scroll calculations while maintaining accessibility

Screenshots #

before after
image image

Its best to use the sandbox mentioned in the issue https://codesandbox.io/p/devbox/euicodeblock-virtualized-within-euiflyout-height-100-forked-6j2tlc?workspaceId=ws_PBRiDLztB2gZ9hEEoiqpdS and change it with this pr patch.

Impact to users

Fixes a bug where virtualized code blocks would show blank lines when scrolled or when content updates. No breaking changes.

🟢 There are no updates required on consumers side.

QA

Remove or strikethrough items that do not apply to your PR.

General checklist

  • Browser QA
    • Checked for accessibility including keyboard-only and screenreader modes
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately

@cla-checker-service

cla-checker-service Bot commented Nov 9, 2025 •

Copy link
Copy Markdown

💚 CLA has been signed

@github-actions

github-actions Bot commented Nov 9, 2025

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 9, 2025
@sravanth-space
sravanth-space marked this pull request as ready for review November 9, 2025 11:11
@sravanth-space
sravanth-space requested a review from a team as a code owner November 9, 2025 11:11
@sravanth-space sravanth-space changed the title fix: move CodeBlock accessibility labels outside containers fix[EuiCodeBlock]: move CodeBlock accessibility labels outside containers Nov 9, 2025
@sravanth-space sravanth-space changed the title fix[EuiCodeBlock]: move CodeBlock accessibility labels outside containers fix(EuiCodeBlock): fixes re-renders causing blank lines to appear when using isVirtualized if scrolled Nov 10, 2025
@sravanth-space
sravanth-space force-pushed the fix/virtualized-code-block-label-bug branch from 5d1a2a8 to 0000557 Compare November 11, 2025 15:25
@mgadewoll
mgadewoll self-requested a review November 12, 2025 10:21

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

@sravanth-space Thanks for digging into this bug! It's awesome that you found the root cause for the issue 🎉
There are some adjustments we'll need to make here to ensure the component remains accessible.

);

// Render the accessibility label outside the virtualized container
// This preserves accessibility while fixing virtualization bugs

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.

This preserves accessibility while fixing virtualization bugs

This is unfortunately not true.
While the element is in the DOM and navigable by screen reader browse mode, moving the label out of the pre breaks accessibility when focusing the element as the label now is not read.

ℹ️ Why was it added as child in the first place?
The main limitation here is that pre does not support aria-label or aria-labelledby, so we can't keep the label outside of the element. To ensure its read out together it has to be content of the focusable element.

expected (production state) unexpected (current PR state)
Screen.Recording.2025-11-13.at.13.45.17.mov
Screen.Recording.2025-11-13.at.13.44.38.mov

@sravanth-space

Copy link
Copy Markdown
Contributor Author

@sravanth-space Thanks for digging into this bug! It's awesome that you found the root cause for the issue 🎉 There are some adjustments we'll need to make here to ensure the component remains accessible.

Thanks so much for the thorough review and for catching the accessibility issues! 🙏
I've pushed the changes to address all your feedback.

@mgadewoll

mgadewoll commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

@sravanth-space Please be so kind to also update the PR description according to the final updates 🙏

@mgadewoll

Copy link
Copy Markdown
Contributor

@sravanth-space I added a VRT-only story as regression test for this bug, I hope you don't mind me pushing it directly.

@sravanth-space

sravanth-space commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor Author

@sravanth-space I added a VRT-only story as regression test for this bug, I hope you don't mind me pushing it directly.

Thanks. I have updated the PR description and for the jest and cypress tests I haven't added/updated please let me know if I need to add/update any.

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

🟢 The changes are LGTM and the fix works correctly. Awesome work!
Thanks for contributing! 🎉

@mgadewoll

Copy link
Copy Markdown
Contributor

buildkite test this

sravanth-space and others added 7 commits November 14, 2025 10:46
- Fixes blank rendering in virtualized CodeBlock when scrolled (elastic#9034)
- Moves labels outside <pre> in both virtualized and regular variants
- Preserves accessibility while preventing react-window calculation issues
- Ensures consistent architecture across all CodeBlock rendering modes

Partially reverts the implementation approach from PR elastic#8887 while
maintaining the accessibility improvements.
renamed with the PR number instead of issue number.
…ibility

Addresses review feedback by placing the label in VirtualizedInnerElement
instead of outside the <pre> tag, preserving screen reader support while
fixing react-window scroll calculations.

Reverts the changes in code_block.tsx

Also updated the changelog to include the bug number.
remove virtualizedList

Updated the comments
@sravanth-space
sravanth-space force-pushed the fix/virtualized-code-block-label-bug branch from 912a330 to 2d429f9 Compare November 14, 2025 10:46
@mgadewoll

Copy link
Copy Markdown
Contributor

@sravanth-space What was the force-push for? Did you rebase or add any changes?

@mgadewoll

Copy link
Copy Markdown
Contributor

buildkite test this

@sravanth-space

sravanth-space commented Nov 14, 2025 •

Copy link
Copy Markdown
Contributor Author

@sravanth-space What was the force-push for? Did you rebase or add any changes?

Sorry I have rebased without any changes.😅

@mgadewoll

Copy link
Copy Markdown
Contributor

@sravanth-space What was the force-push for? Did you rebase or add any changes?

Sorry I have rebased without any changes.

ℹ️ @sravanth-space Just fyi, we don't have to rebase right away if the PR says This branch is out-of-date with the base branch. If there are conflicts, yes. If the PR changes are complex and might affect other components where it's better to check against new changes in main, also yes.
Otherwise, for this PR that has scoped, minimal changes it's enough to ensure the CI finishes green.

@elasticmachine

Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

History

@elasticmachine

Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

History

@mgadewoll
mgadewoll merged commit 3efa7c9 into elastic:main Nov 14, 2025
acstll added a commit to elastic/kibana that referenced this pull request Nov 20, 2025
- `@elastic/eui`: `v109.0.0` ⏩ `v109.1.0`
- `@elastic/eslint-plugin-eui`: `v2.5.0` ⏩ `v2.6.0`

---

## Changes

- Updated i18n EUI mapping 6cc95b0
- Updated test in Unified Search
668948f

## Package updates

### `@elastic/eui`
[`v109.1.0`](https://github.com/elastic/eui/releases/v109.1.0)

- Added `--euiBottomBarOffset` CSS variable to `EuiBottomBar` for
positioning other fixed elements relative to the bottom bar's height
([#9211](elastic/eui#9211))
- Updated `boxesVertical` icon and restored `checkInCircleFilled`,
`errorFilled`, and `warningFilled` icons.
([#9194](elastic/eui#9194))
- Updated `EuiSuperDatePicker` with new time zone information, opt-in
via `timeZoneDisplayProps`.
([#9191](elastic/eui#9191))
- Updated the position of `EuiModal` by removing bottom padding in
`EuiOverlayMask` ([#9190](elastic/eui#9190))
- Added `EuiPopover` and `EuiToolTip`'s `repositionOnScroll` to
`componentDefaults` ([#9152](elastic/eui#9152))
- Updated `EuiSuperDatePicker` with new time window buttons for time
shifting and zoom out, opt-in via `showTimeWindowButtons` boolean prop.
([#9151](elastic/eui#9151))
- Added beta prop `hasAriaDisabled` to all base button components:
`EuiButton`, `EuiButtonEmpty`, `EuiButtonIcon`, `EuibuttonGroup`,
`EuiFilterButton` ([#9201](elastic/eui#9201))
- Added `euiDisabledSelector` variable that combines CSS selectors
`:disabled` and `[aria-disabled="true"]`
([#9201](elastic/eui#9201))
- Added custom test matchers that check for both `disabled` and
`aria-disabled` attributes:
([#9201](elastic/eui#9201))
  - React testing Library: `.toBeEuiDisabled()`
  - Enzyme: `.toHaveEuiDisabledProp()`
  - Cypress: `should('be.euiDisabled)`

**Bug fixes**

- Fixed unexpected duplicate columns in `EuiDataGrid` crashing the
column sorting by removing duplicate columns entirely
([#9209](elastic/eui#9209))
- Fixed a visual bug in `EuiTable` where long table row content would be
cut off on mobile screens
([#9206](elastic/eui#9206))
- Fixed virtualized `EuiCodeBlock` rendering blank lines when content
updates if scrolled. ([#9196](elastic/eui#9196))
- Fixed `EuiButtonGroup` button sizing to ensure square buttons when
used with `isIconOnly=true`
([#9170](elastic/eui#9170))

**Accessibility**

- Fixed an issue where portalled components like `EuiPopover` were not
included in `EuiFlyout`'s focus trap through
`includeSelectorInFocusTrap`, making them inaccessible to keyboard users
([#9103](elastic/eui#9103))

### `@elastic/eslint-plugin-eui`
[`v2.6.0`](https://github.com/elastic/eui/blob/main/packages/eslint-plugin/changelogs/CHANGELOG_2025.md#v260)

- Added new `require-table-caption` rule.
([#9168](elastic/eui#9168))

---------

Co-authored-by: Elastic Machine <[email protected]>
andrimal pushed a commit to andrimal/kibana that referenced this pull request Nov 20, 2025
- `@elastic/eui`: `v109.0.0` ⏩ `v109.1.0`
- `@elastic/eslint-plugin-eui`: `v2.5.0` ⏩ `v2.6.0`

---

## Changes

- Updated i18n EUI mapping 6cc95b0
- Updated test in Unified Search
668948f

## Package updates

### `@elastic/eui`
[`v109.1.0`](https://github.com/elastic/eui/releases/v109.1.0)

- Added `--euiBottomBarOffset` CSS variable to `EuiBottomBar` for
positioning other fixed elements relative to the bottom bar's height
([elastic#9211](elastic/eui#9211))
- Updated `boxesVertical` icon and restored `checkInCircleFilled`,
`errorFilled`, and `warningFilled` icons.
([elastic#9194](elastic/eui#9194))
- Updated `EuiSuperDatePicker` with new time zone information, opt-in
via `timeZoneDisplayProps`.
([elastic#9191](elastic/eui#9191))
- Updated the position of `EuiModal` by removing bottom padding in
`EuiOverlayMask` ([elastic#9190](elastic/eui#9190))
- Added `EuiPopover` and `EuiToolTip`'s `repositionOnScroll` to
`componentDefaults` ([elastic#9152](elastic/eui#9152))
- Updated `EuiSuperDatePicker` with new time window buttons for time
shifting and zoom out, opt-in via `showTimeWindowButtons` boolean prop.
([elastic#9151](elastic/eui#9151))
- Added beta prop `hasAriaDisabled` to all base button components:
`EuiButton`, `EuiButtonEmpty`, `EuiButtonIcon`, `EuibuttonGroup`,
`EuiFilterButton` ([elastic#9201](elastic/eui#9201))
- Added `euiDisabledSelector` variable that combines CSS selectors
`:disabled` and `[aria-disabled="true"]`
([elastic#9201](elastic/eui#9201))
- Added custom test matchers that check for both `disabled` and
`aria-disabled` attributes:
([elastic#9201](elastic/eui#9201))
  - React testing Library: `.toBeEuiDisabled()`
  - Enzyme: `.toHaveEuiDisabledProp()`
  - Cypress: `should('be.euiDisabled)`

**Bug fixes**

- Fixed unexpected duplicate columns in `EuiDataGrid` crashing the
column sorting by removing duplicate columns entirely
([elastic#9209](elastic/eui#9209))
- Fixed a visual bug in `EuiTable` where long table row content would be
cut off on mobile screens
([elastic#9206](elastic/eui#9206))
- Fixed virtualized `EuiCodeBlock` rendering blank lines when content
updates if scrolled. ([elastic#9196](elastic/eui#9196))
- Fixed `EuiButtonGroup` button sizing to ensure square buttons when
used with `isIconOnly=true`
([elastic#9170](elastic/eui#9170))

**Accessibility**

- Fixed an issue where portalled components like `EuiPopover` were not
included in `EuiFlyout`'s focus trap through
`includeSelectorInFocusTrap`, making them inaccessible to keyboard users
([elastic#9103](elastic/eui#9103))

### `@elastic/eslint-plugin-eui`
[`v2.6.0`](https://github.com/elastic/eui/blob/main/packages/eslint-plugin/changelogs/CHANGELOG_2025.md#v260)

- Added new `require-table-caption` rule.
([elastic#9168](elastic/eui#9168))

---------

Co-authored-by: Elastic Machine <[email protected]>
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.

3 participants