Skip to content

Fix mounting anywidget CSS in cross-realm roots#10136

Merged
manzt merged 1 commit into
mainfrom
push-qvnmzwtrtkrx
Jul 10, 2026
Merged

Fix mounting anywidget CSS in cross-realm roots#10136
manzt merged 1 commit into
mainfrom
push-qvnmzwtrtkrx

Conversation

@manzt

@manzt manzt commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Follow up to #10127

A widget's _css was only mounted when its view root passed an instanceof Document | ShadowRoot check. That is false for a cross-realm root such as a Document Picture-in-Picture window, so a composed child rendered there got no styles.

Guard on nodeType instead, and construct the stylesheet in the root's own realm so it applies there. Styles now apply in different realms:

A widget's `_css` was only mounted when its view root passed an
`instanceof Document | ShadowRoot` check. That is `false` for a
cross-realm root such as a Document Picture-in-Picture window, so a
composed child rendered there got no styles.

Guard on nodeType instead, and construct the stylesheet in the root's
own realm so it applies there.
Copilot AI review requested due to automatic review settings July 10, 2026 19:19
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 10, 2026 7:20pm

Request Review

Copilot AI 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.

Pull request overview

This PR fixes anywidget CSS injection for views rendered into cross-realm DOM roots (e.g., Document Picture-in-Picture windows), where instanceof Document | ShadowRoot fails and where constructing a CSSStyleSheet in the wrong realm prevents styles from applying.

Changes:

  • Replace realm-sensitive instanceof checks with realm-independent nodeType-based guards for Document/ShadowRoot.
  • Construct CSSStyleSheet instances from the target root’s realm (doc.defaultView.CSSStyleSheet) so adopted stylesheets apply in cross-realm contexts.
  • Ensure <style> element fallback is also created from the target document (doc.createElement("style")).

@manzt manzt merged commit 991e906 into main Jul 10, 2026
36 of 38 checks passed
@manzt manzt deleted the push-qvnmzwtrtkrx branch July 10, 2026 19:22
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.14-dev61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants