-
Notifications
You must be signed in to change notification settings - Fork 316
feat: rewrite shadow root css #5809
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6c9f4de
refactor: remove a private export from theme package
Jack-Works bac9aea
chore: wip
Jack-Works 31aa5e7
fix: global styles
Jack-Works ff4d53d
fix: works again
Jack-Works 578e6c7
fix: global styles clone
Jack-Works 09415ec
fix: nested shadow root isolation
Jack-Works 3f2b115
feat: add implementation space for speedy mode
Jack-Works ba653db
feat: add constructable stylesheet
Jack-Works d4d88f8
feat: add constructable stylesheet
Jack-Works 6dd5ddc
fix: event prop in portal
Jack-Works 9561394
fix: global styles
Jack-Works 48a1e1b
refactor: global styles
Jack-Works 6ef177b
fix: a check
Jack-Works 26be484
fix: a check
Jack-Works 3db8103
chore: code style
Jack-Works 7bb3432
fix: portal order
Jack-Works 6167959
chore: rename file
Jack-Works 27628f6
chore: short class name
Jack-Works 88fd54b
fix: typo
Jack-Works a0c8c99
fix: storybook
Jack-Works 8cb198f
Update packages/plugin-infra/src/utils/createInjectHooksRenderer.tsx
Jack-Works File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { GlobalStyles, Theme, useTheme } from '@mui/material' | ||
| import { useRef } from 'react' | ||
| import { CSSVariableInjectorCSS } from './constants' | ||
|
|
||
| export function CSSVariableInjector(props: React.PropsWithChildren<{ useTheme?: () => Theme }>) { | ||
| const { current: useConsistentTheme } = useRef(props.useTheme || useTheme) | ||
| const colorScheme = useConsistentTheme().palette.mode | ||
|
|
||
| return <GlobalStyles styles={CSSVariableInjectorCSS(colorScheme)} /> | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { createContext } from 'react' | ||
| import type { StyleSheet } from './ShadowRootStyleSheet' | ||
|
|
||
| /** @internal */ | ||
| export const StyleSheetsContext = createContext<readonly StyleSheet[]>(null!) | ||
| /** @internal */ | ||
| export const PreventEventPropagationListContext = createContext<(keyof HTMLElementEventMap)[]>([]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { useState, useRef, useLayoutEffect } from 'react' | ||
| import { createPortal } from 'react-dom' | ||
| import { ShadowRootStyleProvider } from './ShadowRootStyleProvider' | ||
|
|
||
| /** | ||
| * Render it's children inside a ShadowRoot to provide style isolation. | ||
| */ | ||
| export function ShadowRootIsolation({ | ||
| children, | ||
| ...props | ||
| }: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>) { | ||
| const [dom, setDOM] = useState<HTMLSpanElement | null>() | ||
|
|
||
| const container = useRef<HTMLDivElement>() | ||
| if (!container.current) { | ||
| container.current = document.createElement('div') | ||
| } | ||
| useLayoutEffect(() => { | ||
| if (!dom) return | ||
| if (dom.shadowRoot) return | ||
|
|
||
| const shadow = dom.attachShadow({ mode: 'open' }) | ||
| shadow.appendChild(container.current!) | ||
| }, [dom]) | ||
|
|
||
| if (!dom?.shadowRoot) return <span {...props} ref={(x) => (x !== dom ? setDOM(x) : undefined)} /> | ||
|
|
||
| return ( | ||
| <span {...props}> | ||
| <ShadowRootStyleProvider shadow={dom.shadowRoot}> | ||
| {createPortal(children, container.current)} | ||
| </ShadowRootStyleProvider> | ||
| </span> | ||
| ) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this
<span/>necessary?Don't see any css selector match
[data-plugin-render]or some other usageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary. This span is used to wrap all plugins because there're many plugins and it's a noise. With this span, we can fold all plugins at once.
This
data-plugin-renderis not used anywhere. It's for a better view in the F12 DOM view.