diff --git a/.gitignore b/.gitignore index 5fa1d822a..ddd558e54 100644 --- a/.gitignore +++ b/.gitignore @@ -67,3 +67,6 @@ __TEST__ /playwright/.cache/ /e2e-report/ _examples + +# specs +specs/ diff --git a/examples/content-preact/content/scripts.tsx b/examples/content-preact/content/scripts.tsx index 4d4998c07..2ee91fa1c 100644 --- a/examples/content-preact/content/scripts.tsx +++ b/examples/content-preact/content/scripts.tsx @@ -1,12 +1,15 @@ import {render} from 'preact' import ContentApp from './ContentApp' -import './styles.css?inline_style' + +let unmount: () => void +import.meta.webpackHot?.accept() +import.meta.webpackHot?.dispose(() => unmount?.()) if (document.readyState === 'complete') { - initial() + unmount = initial() || (() => {}) } else { document.addEventListener('readystatechange', () => { - if (document.readyState === 'complete') initial() + if (document.readyState === 'complete') unmount = initial() || (() => {}) }) } @@ -21,13 +24,36 @@ function initial() { // This way, styles from the extension won't leak into the host page. const shadowRoot = rootDiv.attachShadow({mode: 'open'}) - // Inform Extension.js that the shadow root is available. - window.__EXTENSION_SHADOW_ROOT__ = shadowRoot + const style = document.createElement('style') + shadowRoot.appendChild(style) + + fetchCSS().then((response) => { + style.textContent = response + }) + console.log('Running....???') + + import.meta.webpackHot?.accept('./styles.css', () => { + fetchCSS().then((response) => { + style.textContent = response + }) + }) + // Preact specific rendering render(
- Learn more about creating cross-browser extensions at - https://extension.js.org - -
-+ Learn more about creating cross-browser extensions by + + . +
+- Learn more about creating cross-browser extensions at - https://extension.js.org - -
-