dash
dash copied to clipboard
Load asset files with ending ".mjs" as js modules
When a script file in the assets
folder ends in .mjs
, the type="module"
attribute is added to the <script>
tag.
Fixes #1904
Contributor Checklist
- [x] I have run the tests locally and they passed. (refer to testing section in contributing)
- [x] I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
optionals
- [x] I have added entry in the
CHANGELOG.md
- [x] If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
- [ ] this GitHub #PR number updates the dash docs
- [ ] here is the show and tell thread in Plotly Dash community
@jowlo this looks great, thanks! Can you add a test of this in test_clientside.py, with a .mjs
file in the corresponding assets folder?
Hope this gets upstreamed!
@insilications we’re just blocked on a test, maybe you’d like to write one so we can merge this?
Sorry for the delay here, this issue slowly settled down to the bottom of my todo list...
I added a simple tests that just checks whether any script tag with type="module"
was loaded.
The test also registers a simple display callback just like the most basic test for (non-module) clientside callbacks.
I moved the display function to its own module clientsideModule.mjs
to make sure it is loaded correctly. clientside.mjs
just loads this modules, which would not be possible if clientside.mjs
was not loaded as module itself.