-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Datepicker: Hide the UI on destroy #2268
Conversation
Co-authored-by: DawnSovereign <jason.t.kim2@gmail.com>
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 for the PR.
If the DOM is not getting destroyed, we should make sure it is after the fix. Is just hiding enough to achieve that?
I'd also want to understand fully why just setting this._curInst
to null
caused this issue; without this, the fix may be incomplete. Can you analyze this & report back?
Also, we'll need tests.
Co-authored-by: DawnSovereign <jason.t.kim2@gmail.com>
@DawnSovereign are you able to get this stack trace with the local, unminified code? or click on it and see what function it's in, and find the corresponding function in the source code? from the screenshot, it looks like it's this function, right? jquery-ui/ui/widgets/datepicker.js Lines 2166 to 2177 in 5e4f1b8
|
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'll review the code logic in more detail later but I'll reiterate this needs tests before we can merge anything.
You can also see that existing tests are not passing, please make sure they do. |
Co-authored-by: DawnSovereign <jason.t.kim2@gmail.com>
@mgol Thanks for taking a look. We've pushed a unit test that reproduces the issue. It fails in We've reverted the fix back to hiding the datepicker instead of destroying the div. This is because several tests expect to re-use the element after it is destroyed. If we want to properly remove the element when the datepicker is destroyed, it looks like this may be a breaking change? I can open a ticket for that separately with more details. The underlying issue is that destroying the datepicker by itself does not hide it. The current tests in The long term solution is to remove the element when the datepicker is destroyed, and update the tests, and mark this as a (potential?) breaking change. |
Co-authored-by: DawnSovereign <jason.t.kim2@gmail.com>
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.
LGTM. @fnagel can you have a look as well?
At first I thought that just hiding the elements instead of destroying sounds not ideal, but then I've seen the comment about "This is because several tests expect to re-use the element after it is destroyed." so the change makes sense to me. It's not ideal that the destroy method does not really destroy everything (elements, events, ...) like other widgets do, but the Datepicker does not use the widget factory and always was a little special. So to me, this change improves the current state and fixes a bug introduces with 1.13.x. Only the test comment is a little confusing (see my review). @mgol We might want to squash the commits when merging this. |
@fnagel Was the comment your only concern to address before merging? I get your comment about destroying; I had a look at the code and it seemed not that easy to retrofit it into the existing design. Please approve if you have no further concerns to address. |
@mgol I'm fine with merging it as it is. Datepicker was always special (as mentioned before, no widget factory in use) and SHOULD have been replaced with the new calendar and datepicker widget but never has. Not sure what little surprises will come up when we start changing how the structure and design currently looks ;-) |
Just to make sure, I checked myself what was the cause of the original issue. Datepicker attaches a global jquery-ui/ui/widgets/datepicker.js Line 2201 in cd41c45
It never removes it. This handler hides the datepicker in certain conditions - but the first thing it checks is whether $.datepicker._curInst is truthy:jquery-ui/ui/widgets/datepicker.js Lines 1005 to 1022 in cd41c45
Since #1852 made _curInst cleared, this method stopped doing anything.
Some parts of the description from #2178 are incorrect, though - in 1.12.1, the datepicker UI was not hidden on destroy either! It was just hidden after the first Therefore, this PR actually changes the behavior compared to 1.12.1 which was already partially broken. I think it's a reasonable change - the datepicker UI should hide when destroying the widget - but let's call it out. |
Issue: #2178 - date picker remains after being destroyed
We confirmed through git bisect that this commit, 817ce38, introduced a bug while fixing a memory leak with the date picker. This commit sets the current instance to null,
jquery-ui/ui/widgets/datepicker.js
Line 440 in 5665215
Our proposed fix is to hide the date picker when the destroy function using
$.datepicker._hideDatepicker();
so the user can no longer hover over a "ghost" date picker that can no longer be interacted with.