Skip to content

Exclude SVG elements from CSS reset#1252

Merged
ditman merged 3 commits intogoogle:mainfrom
selamw1:svg-reset-rendering
May 8, 2026
Merged

Exclude SVG elements from CSS reset#1252
ditman merged 3 commits intogoogle:mainfrom
selamw1:svg-reset-rendering

Conversation

@selamw1
Copy link
Copy Markdown
Collaborator

@selamw1 selamw1 commented Apr 21, 2026

Fixes #1175

The CSS reset rule all: revert in v0_8 broke SVG rendering by overriding presentational attributes (e.g., fill, stroke).

Solution

Excluded SVG elements and their descendants from the reset:
:where(.a2ui-surface) :where(*:not(svg):not(svg *))

Before Fix After Fix
[Screenshot 2026-04-21 at 1 20 36 PM] [Screenshot 2026-04-21 at 1 22 19 PM]

Pre-launch Checklist

  • I signed the [CLA].
  • I read the [Contributors Guide].
  • I read the [Style Guide].
  • I have added updates to the [CHANGELOG].
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the CSS reset logic to exclude SVG elements and their descendants from the all: revert rule. Feedback indicates that the change lacks accompanying tests as required by the repository style guide. Additionally, it is suggested to simplify the CSS selector using a comma-separated list and to consider the potential inconsistency regarding HTML content nested within SVG foreignObject elements, which would also be excluded from the reset.

Comment thread renderers/react/src/v0_8/styles/reset.ts Outdated
Comment thread renderers/react/src/v0_8/styles/reset.ts Outdated
@selamw1 selamw1 force-pushed the svg-reset-rendering branch 3 times, most recently from e8963c4 to adbdd54 Compare April 21, 2026 20:52
@jacobsimionato jacobsimionato requested a review from ditman April 22, 2026 05:11
@jacobsimionato
Copy link
Copy Markdown
Collaborator

@ditman does this look safe? Do you think it has much chance of breaking things once imported into the google monorepo especially?

@ditman
Copy link
Copy Markdown
Collaborator

ditman commented Apr 28, 2026

Yeah, this looks good to me. The current implementation of the reset is very hardcore, and is probably breaking in the same way internally (it's just that nobody has hit this corner case yet).

I'll bring it up to the internal users' chat to see if anybody has any concerns.

@ditman
Copy link
Copy Markdown
Collaborator

ditman commented May 4, 2026

@selamw1 can we apply this to other versions of the renderers, is this needed on lit v0.9 or any other renderer? We could land them all at the same time!

@selamw1
Copy link
Copy Markdown
Collaborator Author

selamw1 commented May 5, 2026

@selamw1 can we apply this to other versions of the renderers, is this needed on lit v0.9 or any other renderer? We could land them all at the same time!

@ditman yes, I checked and both versions(React v0.8 & v0.9) share the exact same reset.ts file under the hood. This PR fixed both versions at the same time.
Lit Renderers are not affected, Lit components use Shadow DOM to encapsulate styles. It never used the all: revert rule and was never broken.

@ditman
Copy link
Copy Markdown
Collaborator

ditman commented May 5, 2026

Thanks for checking! One last thing, do you mind updating the CHANGELOG.md of the React renderer in the "Unreleased" section listing with a small sentence about this fix (it can be the commit message, or the title of the PR) and a link to the PR (similar to this), so we can compute the next version number when we release this package next? Thanks!!

@selamw1
Copy link
Copy Markdown
Collaborator Author

selamw1 commented May 5, 2026

Thanks for checking! One last thing, do you mind updating the CHANGELOG.md of the React renderer in the "Unreleased" section listing with a small sentence about this fix (it can be the commit message, or the title of the PR) and a link to the PR (similar to this), so we can compute the next version number when we release this package next? Thanks!!

sure, CHANGELOG.md updated.

@ditman
Copy link
Copy Markdown
Collaborator

ditman commented May 6, 2026

I've rebased this branch with main. There has been a big formatting change today that might flag the changes here as being wrong, but the fix should be to run the scripts/fix_format.sh script.

@selamw1 selamw1 force-pushed the svg-reset-rendering branch 5 times, most recently from 9c5faf6 to 5f4dfe7 Compare May 7, 2026 00:38
@selamw1 selamw1 force-pushed the svg-reset-rendering branch from 5f4dfe7 to bf9e1d0 Compare May 7, 2026 01:03
@selamw1
Copy link
Copy Markdown
Collaborator Author

selamw1 commented May 7, 2026

I made several commits to pass the formatting changes, and all checks are now passing successfully.

Copy link
Copy Markdown
Collaborator

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this and adding a test!

@ditman ditman merged commit e3724ff into google:main May 8, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in A2UI May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

reset-styles breaks SVG rendering

3 participants