Skip to content

Fixed issue with importScript method in plotly-interop-5.4.0.js #460

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

Closed
wants to merge 2 commits into from

Conversation

brettwinters
Copy link
Contributor

Fixed issue with importScript function in plotly-interop-5.4.0.js that conflicts with AMD (Asynchronous Module Definition) loaders, such as RequireJS, which might be active in your Blazor environment (such as used in Blazor.Monaco - StackExchange).

Plotly tries to define itself as an anonymous module, but AMD doesn't support multiple anonymous define calls in the same script.

To resolve this issue, I bypassed the AMD detection

// Temporarily disable AMD
const originalDefine = window.define;
window.define = undefined;

Then re-enabled it again onload/onerror:

script.onload = () => {
            window.define = originalDefine; //restore AMD
            scriptCache.set(id, scriptUrl);
            plotlyReady = true;
            plotlyReadyCallbacks.forEach(callback => callback());
            resolve();
        };
        script.onerror = (error) => {
            window.define = originalDefine; //restore AMD
            reject(new Error(`Failed to load script ${scriptUrl}: ${error.message}`));
        };

Note, I think AMD is depreciated in plotly.js version 3.0 according to this merge

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