-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@storybook/html 5.0.1 can't run scripts on story load, aka 'DOMContentLoaded' doesn't help anymore #6113
Comments
Nevermind, solved |
@BennyZ28 what was the solution? |
@shilman Actually I haven’t solved it, I throught I had after too many hours in front of the screen but I was wrong. So, any help still appreciated! |
Whenever the 'page' changes, the old Inside your function runOnInit() {
console.log('Init')
}
function runOnPageChange() {
console.log('Page has changed!')
}
document.addEventListener('DOMContentLoaded', function() {
runOnInit();
const callback = function(mutationsList) {
for (let i = 0, len = mutationsList.length; i < len; i++) {
if (mutationsList[i].type == 'childList') {
runOnPageChange();
break;
}
}
};
const observer = new MutationObserver(callback);
const config = { childList: true, subtree: false };
observer.observe(document.getElementById('root'), config);
}, false); To understand how |
🙏 |
The workaround is too complex, why not storybook provide a callback just called after the story is added to the dom tree? |
Still not fixed properly: #15753 |
Hey there! I include a separate JavaScript file into Storybook for my HTML components. This JavaScript file listens for I did not want to have to rewrite my frontend JavaScript code to be able to use it with Storybook, so I decided to adapt the code from d4nyll to dispatch a Essentially, the snippet does the following:
Hopefully, it might help someone else. Thanks! Place the following script inside of
Edit I discovered after posting this solution, that when changing "Stories" within a "Component" that I was accidentally adding an event listener every time to my button (as part of the
The key here is the A slight rewrite to my frontend assets, but I can live with that! |
Is this really still state of the art? WTF? |
Trying your approach @JoshuwayMorris but on an AutoDocs page it causes chrome to hang, also in Storybook 8 there is no docs-root, is this suppose to be the storybook frame, or the previews frame? |
Hi folks! So, here's my situation: some of my components require javascript. I can successfully call the javascript file in
preview-head.html
but, initialising it is a problem.Before v5.0.1 I used to have:
and it worked, but now it doesn't.
I've been looking all over your docs and Stackoverflow itself but I can't find a solution to this. It feels like it should be something Storybook should be keeping in consideration.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: