Skip to content
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

Revert type='module' on components scripts due to backward compatibility issues #1313

Merged

Conversation

dfsmania
Copy link
Collaborator

Question Answer
Pull request type ISSUE
License MIT

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 including jQuery configuration in VITE, because VITE will loads jQuery 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 the type="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 the old() value submitted within the form when there is a validation error. Some of these components that are based in plugins, like the SelectBs use JQuery or Javascript to perform this task. Now, suppose you already have a view with a Javascript code to inspect the value of a SelectBs 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 the SelectBs 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

  • I tested these changes.

@dfsmania dfsmania merged commit 4dafd79 into jeroennoten:master Oct 15, 2024
34 checks passed
@dfsmania dfsmania deleted the fix_components_backward_compatibility branch October 15, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant