Skip to content

Conversation

@sravanth-space
Copy link
Contributor

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

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
Copy link

cla-checker-service bot commented Nov 9, 2025

💚 CLA has been signed

@github-actions
Copy link

github-actions bot commented Nov 9, 2025

👋 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
Copy link
Contributor

@mgadewoll mgadewoll left a comment

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
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
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
Copy link
Contributor

mgadewoll commented Nov 13, 2025

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

@mgadewoll
Copy link
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
Copy link
Contributor Author

sravanth-space commented Nov 13, 2025

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

Copy link
Contributor

@mgadewoll mgadewoll left a comment

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
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
Contributor

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

@mgadewoll
Copy link
Contributor

buildkite test this

@sravanth-space
Copy link
Contributor Author

sravanth-space commented Nov 14, 2025

@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
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
Collaborator

💚 Build Succeeded

History

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

@mgadewoll mgadewoll merged commit 3efa7c9 into elastic:main Nov 14, 2025
7 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.

3 participants