feat: add cssPropertyRename option to prevent CSS @property conflicts#2005
feat: add cssPropertyRename option to prevent CSS @property conflicts#2005taiiiyang wants to merge 2 commits intowxt-dev:mainfrom
Conversation
❌ Deploy Preview for creative-fairy-df92c4 failed.
|
aklinker1
left a comment
There was a problem hiding this comment.
Code looks good, thanks for writing tests.
We had really bad performance with the splitShadowRootCss function that some else found and improved. Since that function and this new one both are apart of the same function, createShadowRootUi, and slow performance here is known to cause a bad UX, can you benchmark the createShadowRootUi function using real CSS from tailwind?
Compare how many times per second createShadowRootUi can run with or without cssPropertyRename. If it's slow, try and optimize it. If it's fast and the hit is negligable, no need to make any improvements.
You can use Vitest's bench utils to write the benchmark, please include it in the PR, don't just delete it after writing it.
packages/wxt/src/utils/__tests__/rename-css-custom-properties.test.ts
Outdated
Show resolved
Hide resolved
I have made adjustments to the current
|

Overview
Add
cssPropertyRenameoption tocreateShadowRootUithat allows renaming CSS custom property prefixes to preventconflicts with host page styles.
Problem:
When extensions use Tailwind CSS v4 with Shadow Root UI, the
@propertyrules (e.g.,@property --tw-gradient-from { syntax: "<color>"; }) are extracted and injected into the host page's<head>. This causes conflicts with host pagesusing Tailwind CSS v3, which use composite CSS variable values that don't match the typed syntax constraint.
Solution:
renameCssCustomProperties()utility function that renames:@propertyrules:@property --tw-xxx→@property --wxt-tw-xxx--tw-xxx: value→--wxt-tw-xxx: valuevar()references:var(--tw-xxx)→var(--wxt-tw-xxx)cssPropertyRenameoption toShadowRootContentScriptUiOptionsfromPrefixandtoPrefixare optional:toPrefixis provided: prepends prefix to all custom propertiesfromPrefixis provided: removes the matching prefixfromPrefixwithtoPrefixManual Testing
Related Issue
This PR closes #1955