Closed taka-oyama closed 3 years ago
Agree with this issue. This happens in bootstrap 5.x production release irrespective of how you initialize the modal. Either dynamically via JS or via Data attributes.
Currently the workaround to overcome this issue is to load the bootstrap.bundle.js
within the HTML body and not in the head. But it ideally cannot be the solution to this issue.
It happens to me too and it didn't happen in beta3. When can we expect a fix since this is (in my opinion) pretty serious?
Hey guys. Let's take it from the beginning.
Advising the Starter template and following the script loading best practices, your script
tag, should be loaded at the end of the body
element.
So the provided example is an anti-pattern, which at least could have the 'defer' attribute(which would guide to other problems)
I can confirm that the default option doesn't being initialized if the scripts is loaded before body.
So till be fixed, please try to load your script before body
closing tag 🐰
Loading script before closing of body tag is not an option in many cases, for example in a CMS. We should not restrict the users to load the scripts in body, bootstrap should work in either way.
I also just encountered this same issue coming from 5.0.0-beta3 and realized what was happening before finding this GH issue. Forcing users to load the Bootstrap JS file in a specific way for no good reason is not a solution.
Additionally, as others have mentioned, it is sometimes not feasible or even possible to load scripts in the way being suggested.
Guys, please calm down for a second. No one tries to enforce here something.
Like @GeoSot already mentioned, adding scripts into the <head>
can be considered an antipattern, because it blocks the page rendering while the script files are downloaded and evaluated. One could argue that this should only be done, if your scripts really require it to be loaded upfront.
We adhere to the practise of putting our script tags at the end of the <body>
, thus it didn't appear to be a problem while developing and testing our components. It was simply an oversight on our end and not something we did on purpose.
I understand, there are different requirements on a project and to load bootstrap in a certain way shouldn't be your concern. This is going to be addressed with the next release, but please accept, that we are all humans and errors can happen.
The defer
attribute on the script tag "solves" the issue (of course async attribute is not enough). If this will a "wontfix" at the end then we have a documentation issue.
facing this issue again with bootstrap 5.10 along with Asp.net core MVC 6, when try loading modal either with pure javascript or jQuery, it throws this error again, I have tried either put script in most near </body>
tag or add defer
attribute but this won't fix.
HELP!!
Hey @NotAsea This issue is closed. If you're facing a problem, please create a new issue referencing this one and include a live reproducible example. Otherwise, it's impossible for us to track already-closed stuff.
In case anyone else stumbles here, this is what solved it for me: https://github.com/twbs/bootstrap/issues/38307#issuecomment-1485570305
Upgraded from v5 beta 3 to v5 seems to have broken dynamic modal.
When I do
I get the following error:
Please checkout the details by checking out the snippet below.
https://jsbin.com/tikogemofi/edit?html,console
This only seems to happen if I put the bootstrap JS file in
<head>
.By debugging for a bit, I was able to see that the code below
https://github.com/twbs/bootstrap/blob/main/js/src/util/backdrop.js#L14
was set to
null
.This error probably occurred because document.body does not exist yet when the JS gets loaded in
<head>
.