-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Child window revert #829
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
Child window revert #829
Conversation
💃 |
Making a callable Alternatively, we could rely on the Third option would be to catch the security exception, assume that if it's thrown, the style sheet is from a different domain, and thus doesn't need to be checked for duplicates anyway. Not sure what is going on with #822 though, I can't reproduce it. |
That's what I thought about too. But that would mean that pages with multiple plotly graph div would get duplicate style rule ad infinitum. A hacky alternative would be to store |
Really, you're already mutating the document by adding the styles, one additional variable isn't the worst thing. I'm still trying to think up something better though... |
Could add a child div to the graph div with a specific id. Add a specific style for that id to the plotcss rules. Check to see if the child gets styled. If it does, bail, if it doesn't, inject styles. Then delete the child. It's a little hacky, but I like it better than tacking a variable onto the parent document. In regards to #822, I think we'd need to switch back to the old way of just injecting an entirely new stylesheet, appending to a stylesheet that may or may not have come from a different domain seems to be fragile... |
Good point. It might be worth exploring. I've made an attempt on the
That's an interesting solution. How would it work?
Looks like this issue is now fixed in |
Good question! Not entirely sure, I'll attempt to put a demo together when I get a chance.
I would expect it to, it's using the old way of just creating an entirely new stylesheet to append to. The code you reverted attempted to append to an existing stylesheet if one was present. I suspect #822 is caused by attempting to append to a stylesheet that came from a different domain. With the benefit of hindsight, I think the old way was actually the better way. |
Works something like this. I don't think the test style I added is compiled quite right, but other then that, it all works. |
@nielsenb-jf your patch on After the revert in I'd vote for adding a top-level (and well-documented 😄 ) method on |
@etpinard to some degree, I understand the reluctance, it seems to be a niche feature. But on the other hand, plotly already does plenty to the document it's instantiated in, both by injecting styles, and appending a tester div. Drawing a line here seems arbitrary, but it's probably as good of a line in the sand as any. The issue we saw in Firefox (#826) comes from reading styles from stylesheets loaded from a different domain, which is not allowed in Firefox. #822 comes from appending to a stylesheet loaded from a different domain, which is not allowed in Chrome. I can produce neither error when style injection is done to a new stylesheet (preventing #822, essentially the same way styles are currently injected), and no reading of stylesheets is done (preventing #826, done either by using a style test div or a state variable on the document). It's for all intents and purposes the same thing you're doing currently, just with either a state variable or an additional tester div. As for a |
Follow up I've been meaning to ask since I started working on this. Why are the styles added programmatically anyway? Most JavaScript libraries that require styles just ask the user to include a compiled stylesheet in their document. Then there's no worry about loading it twice. It would also eliminate the code around generating the plotcss file and for injecting it. |
Very good question. For folks importing plotly.js in a But, for (npm) users bundling plotly.js, adding a
From my experiences, that would most old JS libraries [...] |
Fixes #826 and attempts to solve #822
Reverts #806 and @nielsenb-jf 's #764
As mentioned in #827 accessing style sheets programmatically can caused some security errors. While workaround do exist (see here), I prefer not throwing in a somewhat piece of code until we test rigorously on several browsers.
Looking forward, we should perhaps try to support plotting in child windows differently maybe by exposing
Plotly.addStyles
method that folks wanting to plot in child windows would be expected to call.That said, some parts of #764 should be incorporated in a future release such as the more general
gd._document
that we should use to displayLib.notifier
among other things.