8000 Allow nested ReactComponents to ignore the shadow DOM by philippjfr · Pull Request #7991 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@philippjfr
Copy link
Member
@philippjfr philippjfr commented Jun 18, 2025

Currently Bokeh components always create a shadow root that ensures they are isolated from the rest of the page. This isolation is very useful to ensure styling can be well scoped but also has a significant performance penalty. When using custom ReactComponents this performance penalty is compounded by the fact that the shadow DOM boundary layer means that if a ReactComponent has children, who are themselves ReactComponents, we still have to create distinct React roots for each child. So now we have nested shadow roots, containing nested React roots.

This PR provides an option to allow children of ReactComponents, that are themselves ReactComponents to be rendered directly into their parents React roots, bypassing the regular Bokeh View.render pipeline and instead embedding the child component directly as a React node. This has the major benefit that it is a whole lot faster, but also has the potential to have CSS leak across components in this setup. However, it is not uncommon for a bunch of components or even an entire to be styled very similarly, which means this is a perfectly acceptable approach.

To ensure that CSS and styling still applies:

  • We inject the stylesheets on the shadow root of the parent (or parent's parent, ...)
  • We replace :host selectors with explicit IDs
  • We patch the View.el and View.container to ensure that HTML attributes are applied to the correct node

Since this has to be enabled explicitly this is fully backwards compatible and I'd like to test this in the wild a bit before documenting the option in more detail.

@codecov
Copy link
codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.07%. Comparing base (0bb1ccc) to head (10f6eda).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7991      +/-   ##
==========================================
- Coverage   87.07%   87.07%   -0.01%     
==========================================
  Files         346      346              
  Lines       53374    53413      +39     
==========================================
+ Hits        46478    46507      +29     
- Misses       6896     6906      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@philippjfr philippjfr merged commit df5b6e0 into main Jun 19, 2025
46 of 52 checks passed
@philippjfr philippjfr deleted the disable_shadow_dom branch June 19, 2025 14:48
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0