dash icon indicating copy to clipboard operation
dash copied to clipboard

Load asset files with ending ".mjs" as js modules

Open jowlo opened this issue 1 year ago • 4 comments

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 avatar Jan 23 '24 18:01 jowlo

@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?

alexcjohnson avatar Jan 24 '24 14:01 alexcjohnson

Hope this gets upstreamed!

insilications avatar Feb 11 '24 14:02 insilications

@insilications we’re just blocked on a test, maybe you’d like to write one so we can merge this?

alexcjohnson avatar Feb 11 '24 15:02 alexcjohnson

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.

jowlo avatar Feb 12 '24 10:02 jowlo