Created
January 8, 2021 10:37
-
-
Save yjaaidi/4f26e9b7dfe446500ba927561cb9cc3c to your computer and use it in GitHub Desktop.
Storybook Angular Custom Elements reload hack
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
/** | |
* @hack detect when story is changed and reload because custom elements | |
* break HMR. | |
* Storybook will replace storybook-dynamic-app-root's children. | |
* Then we reload the page to redefine elements. | |
*/ | |
const rootEl = document.querySelector('#root'); | |
rootEl.addEventListener('DOMNodeRemoved', (evt) => { | |
if (evt.relatedNode === rootEl) { | |
document.location.reload(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment