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
Use ownerDocument instead of global document #2721
Conversation
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.
This looks good to me!
@yamachig could you add a changelog entry and if possible also submit the same PR against canary? Thanks! |
@probablyup thank you for reviewing! OK, I added a changelog entry and submitted the same PR #2726 against canary. |
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.
Thanks!
const el = document.createElement('style'); | ||
let targetDocument = document; | ||
if(target) targetDocument = target.ownerDocument; | ||
else if(tagEl) targetDocument = tagEl.ownerDocument; |
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'd write this as:
const targetDocument = target ? target.ownerDocument : tagEl ? tagEl.ownerDocument : document
but that's just my anti-mutability bias 🤷♀
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.
@Jessidhia thank you for reviewing! I agree with anti-mutability, though, the eslint rule (no-nested-ternary) didn't let me do so :)
if(target) targetDocument = target.ownerDocument; | ||
else if(tagEl) targetDocument = tagEl.ownerDocument; | ||
|
||
const el = targetDocument.createElement('style'); |
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.
Interesting that this causes no security issues; apparently any <style>
tags' associated StyleSheet
are considered same-origin. https://html.spec.whatwg.org/multipage/semantics.html#the-style-element:concept-css-style-sheet-origin-clean-flag
This can still break for CSP reasons, though, but it'd break regardless of whether we use CSSOM or child text nodes.
Looks like the travis config / vm is way broken. |
@yamachig rebase when you get a chance |
fa460b8
to
daea21a
Compare
@probablyup OK, I rebased. Is that correct? |
Yeah looks like CI is passing now, good. |
It seems that on Microsoft Edge, you cannot appendChild an Element from different Document.
This causes a problem, for example, when you are using StyleSheetManager with a new window created by window.open, like this code:
This code throws an error on Edge, but not on Chrome or Firefox. (I tested with Microsoft Edge 44.18362.267.0.)
I replaced the global document variables with dynamically created Document from ownerDocument so that the code works properly on Edge.