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
Check whether element is in document before calling jQuery.fn.offset() #5584
Conversation
I know this might be tough, since our positioning logic is not the easiest to read and test, but would it be possible for you to create a test for this? It wouldn't be a whole lot different from select2/tests/dropdown/positioning-tests.js Lines 61 to 119 in 2fce8ae
Except you don't need to play around with the CSS and you don't need to attach it to the QUnit fixture (since that would add it into the document). |
I will see what I can do.
…On Tue., Jul. 23, 2019, 05:18 Kevin Brown, ***@***.***> wrote:
I know this might be tough, since our positioning logic is not the easiest
to read and test, but would it be possible for you to create a test for
this?
It wouldn't be a whole lot different from
https://github.com/select2/select2/blob/2fce8ae6c4937b88c332ad3e30e135cf24504cf1/tests/dropdown/positioning-tests.js#L61-L119
Except you don't need to play around with the CSS and you don't need to
attach it to the QUnit fixture (since that would add it into the document).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5584?email_source=notifications&email_token=ABBVGEKHKIN27SPWTQNRPTTQA3ZIXA5CNFSM4IGA6KZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2S5M3A#issuecomment-514184812>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABBVGEILKJCNXRVJJZZX3ADQA3ZIXANCNFSM4IGA6KZA>
.
|
@kevin-brown should this test live within |
That sounds like a good place for it, yes. |
In the interest of getting 4.0.9 out the door without procrastinating even further, I'm moving this PR to land in 4.0.10. |
Sorry. I have been swamped with work lately.
I will try to get to this soon.
…On Wed, Aug 21, 2019 at 5:31 PM Kevin Brown ***@***.***> wrote:
In the interest of getting 4.0.9 out the door without procrastinating even
further, I'm moving this PR to land in 4.0.10.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5584?email_source=notifications&email_token=ABBVGEJYGU5ZILH7IT544WTQFXM5LA5CNFSM4IGA6KZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD43QHMQ#issuecomment-523699122>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABBVGEM6ORWSBYPLMKLLFYDQFXM5LANCNFSM4IGA6KZA>
.
|
This fixes an error which is called out in jQuery Migrate but probably never happens in real life. This is because we call `jQuery.fn.offset` without checking if the element is in the document. Based on testing done here and within the MediaWiki team, I'm pretty sure jQuery never actually implemented explicit checks and this jQuery Migrate warning is just to cover the case where a browser might start returning inconsistnet results. And we could at least reproduce the inconsistency, so that's something. We now default the offset to 0/0 if the parent element happens to not be in the document. This appears to be what jQuery used to do in the past, and generally appears to be what people expect in these cases. This fixes #5584.
Fixes jQuery migrate error when getting offset when dropdownParent not in document
This pull request includes a
The following changes were made
As of jQuery 3.0, jQuery.fn.offset() requires an element connected to a document. In earlier versions of jQuery, the .offset() method would return a value of
{ top: 0, left: 0 }
for some cases of invalid input. jQuery 3.0 throws errors in some of these cases.This PR checks whether the element is within the document. If not, it sets the offset to
{ top: 0, left: 0 }
which is what was happening before. I believe this covers all valid scenarios but perhaps someone else can comment?See the jQuery migrate documentation for more info. https://github.com/jquery/jquery-migrate/blob/master/warnings.md#jqmigrate-jqueryfnoffset-requires-an-element-connected-to-a-document