Open fonsp opened 3 years ago
A second reason is because
const { default: confetti } = await import("https://cdn.skypack.dev/canvas-confetti@1")
schedules a microtask (or whatevs), even if the lib is already loaded, whereas the original does not.
In Pluto, this can cause a single-frame flash where the DOM is rendered without the output from a script, causing scroll shifts and all that.
In one case (a big matrix of Scrubbables), this was causing a real problem, and I had to fix it like so: https://github.com/JuliaPluto/PlutoUI.jl/commit/7180494e58b7b6f872322a4843ce56ecfd5954c1
In this notebook, I made this technique "official" by storing past imports in a Map
.
I think I have a good solution! We can make ES6 imports work using a code transformation, detecting import ... from ...
and then either:
<script>
await import(
with the Map
system from my previous comment.Now... rewriting code is hard and we are going to make mistakes. So I have an idea!
SyntaxError: Cannot use import statement outside a module
, then we print a second message to the console: "Oops! Pluto was not able to blabla, try putting it at the top of the code."@dralletje WDYT?
The microtask thing can be solved way easier, should to that anyway for any microtask stuff...
All I know is that as soon as we are transpiling javascript code, we'll become one of these things always lagging a couple feature behind, not being compatible with this and that unless we actively keep maintaining it with every new thing that comes out...
I first wanna apply the microtask fix and see if that makes it worthwhile, would love to keep type=module
clean (you I don't like that we "support" it at all :P)
Oooh awesome! I can make a notebook that you can fix?
Fixing the underlying microtask problem instead of writing our own transpiler is a 👌👌👌 idea
Normally, you can import libraries inside JS using the import syntax:
In Pluto, this is currently not supported (because code is not executed at toplevel), and you need to use a different syntax as workaround:
Can we add support for the toplevel syntax? Should we do some regex tricks to rewrite user code?