Skip to content

Instantly share code, notes, and snippets.

@yjaaidi
Created January 8, 2021 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjaaidi/4f26e9b7dfe446500ba927561cb9cc3c to your computer and use it in GitHub Desktop.
Save yjaaidi/4f26e9b7dfe446500ba927561cb9cc3c to your computer and use it in GitHub Desktop.
Storybook Angular Custom Elements reload hack
/**
* @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