-
-
Notifications
You must be signed in to change notification settings - Fork 370
fix: prevent namespace pollution bug #5170
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
Conversation
3afaff1 to
d0777cf
Compare
|
Thanks for looking into this, I had a go but was quite lost. For me this patch works the first time a plot is displayed in IJulia, the second time the plot isn't displayed and I see this in the console: Uncaught SyntaxError: redeclaration of let plotlyloader
<anonymous> scratch.ipynb line 162569 > injectedScript:1
attachWidget index.es6.js:2640
insertWidget index.es6.js:2543
_insertOutput widget.js:579
onModelChanged widget.js:305
invokeSlot index.es6.js:555
emit index.es6.js:513
emit index.es6.js:112
_onListChanged model.js:277
invokeSlot index.es6.js:555
emit index.es6.js:513
emit index.es6.js:112
push observablelist.js:139
_add model.js:226
add model.js:146
_onIOPub widget.js:98
_handleIOPub future.js:236 |
|
You can fix that with IIFE, instead of: let plotlyloader = window.document.createElement("script")
let src="https://requirejs.org/docs/release/$(PlotsBase._requirejs_version)/minified/require.js"
plotlyloader.addEventListener("load", plots_jl_plotly_$unique_tag);
plotlyloader.src = src
document.querySelector("#$unique_tag").appendChild(plotlyloader)you do ;(() => {
let plotlyloader = window.document.createElement("script")
let src="https://requirejs.org/docs/release/$(PlotsBase._requirejs_version)/minified/require.js"
plotlyloader.addEventListener("load", plots_jl_plotly_$unique_tag);
plotlyloader.src = src
document.querySelector("#$unique_tag").appendChild(plotlyloader)
})() |
|
Or changing |
|
@JamesWrigley @BeastyBlacksmith Me and Panagiotis would be happy to have a call to go over the JS code in Plots.jl together? We're happy to help! I think it would be nice to bring everything up to date, with MathJax 2 -> 3, plotlyjs 2 -> 3, removing requirejs and with modern JavaScript, imports and CDNs. That also makes future maintenance easier |
|
I hate web dev so I'll politely decline 😅 I'm just a drive-by contributor trying to get Plotly and IJulia to work together. Removing requirejs sounds good though 👍 That was the original cause of the issue I was trying to fix since requirejs was previously bundled with Jupyter and Plots.jl was relying on that. |
Thats a generous offer, thanks. For example next week tuesday somewhen between 9am and 1pm would work for me. We can also discuss the date on zulip if you prefer. |
|
Meeting tuesday 11 CEST :) https://meet.google.com/env-maxy-bzx if anyone wants to join |
And in the meantime, I updated this PR with Fons' fix. The discussion stays relevant of course, as we probably shouldn't be doing these tricks anyway (with a |
|
Should we work on the |
So in this case I guess you need two PRS one against |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate web dev so I'll politely decline 😅 I'm just a drive-by contributor trying to get Plotly and IJulia to work together.
😄, same here !
And in the meantime, I updated this PR with Fons' fix. The discussion stays relevant of course, as we probably shouldn't be doing these tricks anyway (with a script type="module" or similar approach.
I manually checked that the PR works so until someone else has a better proposal, I'm ok with this.
If we can get rid of requirejs I'm all in favor.
A PR against master is more important than v2 for the end users.
done at #5171! |
|
Thanks ! Let's wait for the meeting results and then this can go in. |
Description
fonsp/Pluto.jl#3306 and #5156
There is a small issue with the id generation; it should start with a letter.
Apart from that, the main issue here is referencing functions that get executed inside a different "module" (in julia terms). Pluto (and maybe also VSCode?) do not hoist the functions to the top level as you would expect, so referencing the created function from onload isn't working. The solution is simple; programmatically register the handler, and then
appendChildthe script to the DOM.Attribution
Things to consider