Skip to content

IFrame issue: Can not integrate newest Plotly with GWT #5367

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
jnehlmeier opened this issue Jan 4, 2021 · 3 comments
Closed

IFrame issue: Can not integrate newest Plotly with GWT #5367

jnehlmeier opened this issue Jan 4, 2021 · 3 comments

Comments

@jnehlmeier
Copy link

jnehlmeier commented Jan 4, 2021

Hi,

I am unsure if you would consider it a bug, but at least for me it is a regression. I have been using very old Plotly 1.16.2 with GWT (gwtproject.org) just fine and thought about updating Plotly to 1.58.4. However when doing so, all charts are broken because Plotly 1.58.4 resets all layout configuration sections that are a plain javascript object, e.g. layout.xaxis.

The issue is that Plotly's isPlainObject(obj) method returns false because prototypes do not match

Object.getPrototypeOf(obj) === Object.prototype

But let me explain:

GWT is a Java to JavaScript compiler and kind of a framework to build JS apps using Java. The bootstrap mechanism of GWT apps put all the JavaScript code produced by GWT into its own iframe to not pollute the root window object. However the DOM tree of the app will be constructed in the root document and not within the iframe document. So only the GWT produced JS code lives inside the iframe.

Using GWT APIs I can load the JavaScript code of Plotly when needed and basically I have two choice:

  • inject a script tag containing plotly code in the root window
  • inject a script tag containing plotly code in the iframe window

When injecting Plotly into the root window, the above mentioned isPlainObject() method fails, since the Plotly configuration object is constructed from within the iframe by GWT code and thus have an object prototype originating from the iframe window.

When injecting Plotly into the GWT iframe, the isPlainObject() method works correctly again since Plotly runs together with GWT code in the same iframe and prototypes now match as expected. However Plotly then seems to inject CSS (and some testing divs as well) into the iframe document. This results in unstyled charts in the GWT app, because the GWT app DOM tree is constructed in the root windows which does not know about the Plotly CSS in the iframe.

Wondering what would be a good solution to make Plotly more compatible with GWT or in general with cross iframe / window usages.

@jnehlmeier
Copy link
Author

Interesting enough it seems like that isPlainObject(obj) also did this prototype check in 1.16.2. But given that 1.16.2 works fine in my GWT app when injecting Plotly into the root window, I must have been pretty lucky and never triggered a code path using isPlainObject(obj)!

So i digged a little further and it seems like this commit
2289657#diff-91cf4d62b1e2b6b1ba56098e7cfdc6a3ec8cf275c6fd2b6f4b9a6f5bfca058d8R142
causes the trouble now for me. Thus I can not upgrade to anything >= 1.24.1.

I have seen that isPlainObject() already has a special treatment for nw.js to bypass the prototype check. Maybe it is possible to do the same for cross iframe usages? If not detectable in code then via a general configuration option?

@alexcjohnson
Copy link
Collaborator

We've discussed this - and the currently available workaround of creating a window.process = {versions: 1}; in the environment where this will be executed - in #5151. And in #1405 (the same issue from a few years back) someone else mentioned the iframe case. Closing this one, but I'll add a comment to #5151 as I'm starting to think my earlier stance is a bit overly conservative.

@jnehlmeier
Copy link
Author

Thanks, didn't found the mentioned issues in my initial search. Yeah adding window.process is probably the way I will go, since I don't want to create a custom build of plotly with modified isPlainObject().

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

No branches or pull requests

2 participants