Last active
December 2, 2023 02:38
-
-
Save miclgael/73ce0297321338d4092258d99240710f to your computer and use it in GitHub Desktop.
Storybook 7 - global style leak fix
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
// ==UserScript== | |
// @name Storybook global style fix | |
// @namespace Violentmonkey Scripts | |
// @match http://localhost:6006/ | |
// @grant none | |
// @version 1.0 | |
// @author Michael Gale <https://www.michaelgale.dev> | |
// @description Fixes global style leaking into your components in Storybook 7 by harshly removing the offending style tag from the iframe. | |
// ==/UserScript== | |
window.onload = function () { | |
const findAndRemove = () => { | |
const iframe = document?.querySelector('#storybook-preview-iframe') | |
const innerDoc = iframe?.contentDocument || iframe?.contentWindow?.document; | |
const innerStyles = [...innerDoc?.querySelectorAll('style')] | |
const badStyles = innerStyles?.find(style => { | |
return style?.innerHTML?.includes('@property') | |
}) | |
badStyles?.remove() | |
} | |
findAndRemove() | |
setInterval(findAndRemove, 1000) | |
window.addEventListener('resize', findAndRemove) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An overly hectic way of fixing this: storybookjs/storybook#17533
(Requires Violent Monkey )