Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC: Isolated components #8139

Closed
wants to merge 1 commit into from
Closed

POC: Isolated components #8139

wants to merge 1 commit into from

Conversation

fregante
Copy link
Collaborator

@fregante fregante commented Apr 3, 2024

Demo for:

I just wanted to share the progress on this issue, I think I got it.

This solution:

  • supports both import './somethingGlobal.css' and import './Component.module.css'
  • ensures no global styles leak (the component can directly import bootstrap for example)
  • automatically creates, injects and awaits the CSS file specific to the component in a shadow DOM
  • uses React.lazy to load components
  • requires no webpack config
  • its shadow DOM can be opened/closed at build time, to ensure privacy without compromising testability
  • it uses a unique element name to eliminate any conflicts that may arise from using div as the name

Unfixable without iframes:

  • if the component dynamically import()s another CSS file, this CSS file is still injected into the main document

Some context and brainstorming also be found on:

How to try this PR:

  1. visit https://pbx.vercel.app
  2. notice red widget appearing in the middle, without any red color leaking out

What's next:

  • validate idea by using it on our own components
  • include any other improvements mentioned in the original issue

@fregante
Copy link
Collaborator Author

fregante commented Apr 4, 2024

Closing this PR to keep it as a POC. I'll open another PR shortly

@fregante fregante closed this Apr 4, 2024
@fregante fregante deleted the F/dev/isolated-components branch April 4, 2024 10:30
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.

Figure out ergonomics of CSS modules in ShadowDOM components
1 participant