-
-
Notifications
You must be signed in to change notification settings - Fork 78.8k
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
Fix backdrop "Cannot read property 'removeChild' of null" when removed from body #34014
Conversation
document.body.innerHTML = 'changed'; | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - without the fix, this test causes this failure:
Chrome Headless 90.0.4430.212 (Mac OS 10.15.7) Backdrop should not error if the backdrop no longer has a parent FAILED
Uncaught TypeError: Cannot read property 'removeChild' of null thrown
this is similar to #33727. We have the asynchronous process error The script that triggers that causes the problem, deletes everything without wait for transitionend document.querySelector('#save-changes').addEventListener('click', (event) => {
bootstrap.Modal.getInstance(document.querySelector('#exampleModal')).hide(); // THIS IS AN ASYNC PROCESS
document.body.innerHTML = 'Page content changed (e.g. faking an AJAX navigation). Check the console for the error.'; //THIS remove everything (plus parentElement) synchronously
}); Proposal: as alert, tooltip, backdrop, use the same process and checks, isn't safer to extract the functionality to |
I see what you're talking about - it looks like it's already handled correctly for the other spots: So at least we know this PR is consistent with behavior elsewhere. As far as extracting it to Cheers! |
18087a8
to
94d21eb
Compare
Makes sense @GeoSot, but that can be done separately IMO. PS: I am not sure why the tests are not being run here but failed when running locally on my machine. |
@weaverryan , agreed with Rohit. Lets fix it here, and you can open a next pr, gathering all these |
a2f321b
to
d3f81b6
Compare
ae07e2c
to
e0b81f3
Compare
I've just made the updates and rebased :). Unfortunately, it looks like there are some pesky test problems. I can't repeat them locally, but each time the tests run here, the same test fails on 1 or 2 of the jobs - sometimes its Node 12, sometimes 14, etc :/. Here's an example: https://github.com/twbs/bootstrap/pull/34014/checks?check_run_id=2640394953 I can't figure out how the new behavior would be affecting this other test :/ |
The flakyness can be explained by jasmine running the tests in random order. So if some certain test is ran before the other, things could fail that wouldn't fail in a different order. I suspect the problem here: This will remove our fixture element and may lead to problems. Replacing that with something like Edit: or you can do |
…ed from the body Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
e0b81f3
to
de7b79e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like that did the job. 😊
LGTM 👍
…from the body (#34014) Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
…from the body (twbs#34014) Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com>
Fixes regression of twbs@a2b5901 breaking the test runner because it would wipe document.body.
Hi!
This fixes #33946
Here is a reproducer: https://weaverryan.github.io/bootstrap-modal-close-reproducer/
Code: https://github.com/weaverryan/bootstrap-modal-close-reproducer/blob/main/index.html#L34-L46
Then in the console you'll see:
This occurs if you
hide()
a backdrop, but then the HTML of the backdrop is removed from the body while its animation is finishing. From the reproducer:When would this happen? It happens, for example, if you're using Turbo. For example, if you close a modal, then immediately "visit" another page, in reality, that just swaps the
body.innerHTML
for the page, which causes backdrop to error when it can't find its parent (after the animation).Please let me know if you need any more clarification or tweaks to the PR :).
Thanks!