-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: react-shadow 제거 및 dev, prod 환경에 따른 entry 분기 처리 로직 제거
- Loading branch information
1 parent
b84bfce
commit 929c2b9
Showing
9 changed files
with
72 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,27 +1,16 @@ | ||
import { createRoot } from 'react-dom/client' | ||
import { SHADOW_HOST_ID } from '@/constants' | ||
|
||
import { SHADOW_ID } from '@/constants' | ||
|
||
export default function createShadowRoot(styles: string[], options: { root?: HTMLElement } = {}) { | ||
const isDev = import.meta.env.MODE === 'development' | ||
const root = options.root || document.createElement('div') | ||
root.setAttribute('id', SHADOW_ID) | ||
const shadowRoot = root.attachShadow({ mode: 'open' }) | ||
export default function createShadowRoot(styles: string[]): ShadowRoot { | ||
const host = document.createElement('div') | ||
host.setAttribute('id', SHADOW_HOST_ID) | ||
const shadowRoot = host.attachShadow({ mode: 'open' }) | ||
|
||
const globalStyleSheet = new CSSStyleSheet() | ||
globalStyleSheet.replaceSync(styles.join('\n')) | ||
|
||
shadowRoot.adoptedStyleSheets = [globalStyleSheet] | ||
|
||
if (isDev) { | ||
const styleElement = document.querySelector('style[data-vite-dev-id]') | ||
|
||
if (styleElement) { | ||
shadowRoot.appendChild(styleElement) | ||
} | ||
} | ||
|
||
document.body.appendChild(root) | ||
document.body.appendChild(host) | ||
|
||
return createRoot(shadowRoot) | ||
return shadowRoot | ||
} |