Skip to content
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

Fix some iframe edge cases #13650

Merged
merged 1 commit into from
Sep 14, 2018
Merged

Fix some iframe edge cases #13650

merged 1 commit into from
Sep 14, 2018

Conversation

JSteunou
Copy link
Contributor

Should fix #13648 by being as protective in setOffsets than in getOffsets

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@sizebot
Copy link

sizebot commented Sep 14, 2018

Details of bundled changes.

Comparing: 8bc0bca...ac7684b

schedule

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
schedule.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
schedule.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

@gaearon
Copy link
Collaborator

gaearon commented Sep 14, 2018

Can you verify this fixes it? Also it would really be helpful to add a case to this fixture:

https://github.com/facebook/react/tree/master/fixtures/dom/src/components/fixtures/selection-events

const doc = node.ownerDocument || document;
const win = doc ? doc.defaultView : window;
const selection = win.getSelection();
const {ownerDocument} = node;
Copy link
Contributor

@acusti acusti Sep 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking this down! This is definitely an oversight of #12037 that we didn’t address.

For context, the reason that getOffsets uses a different method to get a relative window and document object than setOffsets is that getOffsets only needs to use the relative window (which has getSelections), whereas setOffsets needs to use both the window object (for getSelection, again), and the document object (for createRange). So this should really be a hybrid of the two approaches, i.e.:

  const doc = node.ownerDocument || document;
  const win = (doc && doc.defaultView) || window;
  ...
  const range = doc.createRange();

Where it still guards against a missing ownerDocument by falling back to the global and also guards against the case of having an ownerDocument that’s missing a defaultView.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, I changed the logic a bit by over-protecting this path

Update incoming

Should fix facebook#13648 by fallback on `window` when `document.defaultView` does not exists anymore
@JSteunou
Copy link
Contributor Author

@gaearon I have difficulties to reproduce this bug oustide our environment. It's a complicated situation involving a css transition between a state having a wysiwyg jquery editor inside an iframe inside a component and another simple state without this iframe.

Could someone guide me to add a test case?

@JSteunou
Copy link
Contributor Author

JSteunou commented Sep 14, 2018

and yes the actual PR fixes the issue we have

@gaearon
Copy link
Collaborator

gaearon commented Sep 14, 2018

@acusti Can you sign off on the final version please? If it looks good to you I'll get it in.

Copy link
Contributor

@acusti acusti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@gaearon gaearon merged commit 9c961c0 into facebook:master Sep 14, 2018
@gaearon
Copy link
Collaborator

gaearon commented Sep 14, 2018

Thanks.

@JSteunou
Copy link
Contributor Author

Thank you both!

@einarq
Copy link
Contributor

einarq commented Oct 20, 2018

Was this tested in Edge? I saw a bug related to pasting stuff in a TinyMCE editor when using 16.5.1, upgrading to 16.5.2 solved it. But it is still failing in Edge. The issue might be related to something entirely different of course, but it goes away if I downgrade to 16.4.2.
The error coming from TinyMCE is "Unable to get property 'moveToBookmark' of undefined or null reference", not sure if that helps at all.

@acusti
Copy link
Contributor

acusti commented Oct 20, 2018

@einarq Can you post a link to a repo or even just a code sample that makes it possible to reproduce the error on Edge? I’m most interested in how you are including and rendering the TinyMCE editor, but anything that will help me to reproduce it would be helpful. If the error is coming from TinyMCE itself, I’m not sure how it’s related to the changes between 16.4.2 and 16.5.x, but I would be happy to take a look to try to figure it out.

@einarq
Copy link
Contributor

einarq commented Oct 20, 2018 via email

@einarq
Copy link
Contributor

einarq commented Oct 20, 2018 via email

Simek pushed a commit to Simek/react that referenced this pull request Oct 25, 2018
Should fix facebook#13648 by fallback on `window` when `document.defaultView` does not exists anymore
@einarq
Copy link
Contributor

einarq commented Nov 3, 2018 via email

@einarq
Copy link
Contributor

einarq commented Nov 3, 2018 via email

@acusti
Copy link
Contributor

acusti commented Nov 4, 2018

@einarq Thanks for tracking that down! If you want to make a PR that adds an early return if (!win.getSelection) to the top of setOffsets with the explanation of what it addresses, I imagine that would be easy to get merged. I’m puzzled as to why it’s still necessary, considering that support for window.getSelection was added in IE9, and:

const win = (doc && doc.defaultView) || window;

will ensure that even if doc.defaultView is not a proper Window object, we’ll still get the window global, which must have the getSelection method on it. Only thing I could imagine is that doc.defaultView is present but is some kind of limited version of a Window object that doesn’t have the full APIs, maybe for cross-domain security reasons?

But again, having an early return there is harmless, so I’m fine with it, even though I don’t understand why it’s needed.

@einarq
Copy link
Contributor

einarq commented Nov 4, 2018 via email

@einarq
Copy link
Contributor

einarq commented Nov 5, 2018 via email

jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
Should fix facebook#13648 by fallback on `window` when `document.defaultView` does not exists anymore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

16.5 with better support of iframe has some side effects
6 participants