Skip to content

feat: Automatically place document-level CSS outside shadow root - #1594

Merged
aklinker1 merged 5 commits into
mainfrom
extract-root-css-properties
Apr 19, 2025
Merged

aklinker1 merged 5 commits into
mainfrom
extract-root-css-properties

Conversation

@aklinker1

@aklinker1 aklinker1 commented Apr 19, 2025 •

Copy link
Copy Markdown
Member

Overview

This PR adds two features:

  • New splitShadowRootCss function that will split CSS into two parts: one part that needs to go on the document outside the shadow root, and one part that continues to be placed in the shadow root.
  • Use the new function inside createShadowRootUi to automatically move document-level CSS out of the shadow root.

TODO

  • Test in reproduction
  • Style block is removed on reload during development - that means it will be removed when ctx is invalidated in prodcution
  • Add new util to auto-imports and package exports

Manual Testing

Try with reproduction: https://github.com/mengxi-ream/tailwind-wxt-bug

# Install this branch
pnpm i https://pkg.pr.new/wxt@1594

Before

Translate X/Y don't work:

Screenshot 2025-04-19 at 9 33 48 AM

After

Side panel is hidden until you click it!

Screenshot 2025-04-19 at 9 28 51 AM Screenshot 2025-04-19 at 9 29 11 AM

Related Issue

This PR closes #1461

@netlify

netlify Bot commented Apr 19, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 196c2f2
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/6803b4ec59a4e30008d96d87
😎 Deploy Preview https://deploy-preview-1594--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pkg-pr-new

pkg-pr-new Bot commented Apr 19, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@1594

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@1594

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@1594

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@1594

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@1594

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@1594

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@1594

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@1594

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@1594

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@1594

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@1594

wxt

npm i https://pkg.pr.new/wxt@1594

commit: 196c2f2

let shadowCss = css;
let documentCss = '';

const rulesRegex = /(\s*@property[\s\S]*?{[\s\S]*?})/gm;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently, the only rule we look for is @property declarations.

@aklinker1 aklinker1 self-assigned this Apr 19, 2025
@aklinker1
aklinker1 marked this pull request as ready for review April 19, 2025 14:36
@aklinker1
aklinker1 requested a review from Timeraa as a code owner April 19, 2025 14:36
@aklinker1

Copy link
Copy Markdown
Member Author

Confirmation it works with daisyui: #1457 (reply in thread)

@aklinker1
aklinker1 merged commit 760c34e into main Apr 19, 2025
@aklinker1
aklinker1 deleted the extract-root-css-properties branch April 19, 2025 17:12
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for helping make WXT better!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically add styles required on the root document outside shadow root

1 participant