Revert type='module' on components scripts due to backward compatibility issues #1313
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's in this PR?
A previous PR that included support to Vite (see #1308 ) added the
type="module"
attribute to the script tags of the components. This was done mainly to solve the error$ is not a function
when includingjQuery
configuration in VITE, because VITE will loadsjQuery
asynchronously.However, that change will cause that those scripts will be deferred execution until the
DOMContentLoaded
event of the document fires. This might cause backward compatibility issues with existing code using those components, requiring also to add thetype="module"
attribute to other scripts pushed with@push('js')
, since otherwise the pushed scripts will execute before the component's scripts.Example:
When you submit a form, most of the form components have a
enable-old-support
property that is used to auto setup theold()
value submitted within the form when there is a validation error. Some of these components that are based in plugins, like the SelectBs useJQuery
orJavascript
to perform this task. Now, suppose you already have a view with aJavascript
code to inspect the value of aSelectBs
element after a form is submitted in order to enable/disable others elements based on its value. The issue would be that the setup of the old value of theSelectBs
will run after your value inspecting code, so the value you'll read would actually not be the one shown in the form.Important
Another alternative should be found if you want to use
jQuery
with the VITE bundling tool.Checklist