Repository navigation
fix: defer resolution of tooltip target - #5674
Merged
Merged
Conversation
tomivirkki
reviewed
Mar 16, 2023
Also fixed case of target resolution when tooltip is already detached from DOM
|
Kudos, SonarCloud Quality Gate passed!
|
tomivirkki
approved these changes
Mar 17, 2023
bwajtr
added a commit
that referenced
this pull request
Mar 17, 2023
bwajtr
added a commit
that referenced
this pull request
Mar 17, 2023
Collaborator
|
This ticket/PR has been released with Vaadin 24.1.0.alpha1 and is also targeting the upcoming stable 24.1.0 version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Description
The tooltip uses it's
forattribute to control the target element to which the tooltip is attached. Theforattribute contains theidof the target element. There is a_forChangedobserver in the tooltip, which resolves a new target element wheneverforchanges. As long as theidis unique on the page, this works as expected.However, there are situations when there are duplicate
ids on the page, although it's not the author's intent. When you render a list of items using lit.map()function and you then reorder the source list in any way, the lit reacts by rerendeing the content. However, the already created elements on the page are not thrown away or their content cleared before the rerender - elements are reused, and only the diffing parts are rewritten one by one. So it's entirely possible that during the rendering process there are two exactly same items (also with sameid) on the page. That is a problem for a tooltip, which can then resolve incorrect target element. You have to wait until the rerendering finishes to be sure that all changes have been applied and allids are unique again.This also happens when
vaadin-gridis rerendering the content after the items have been sorted differently.The following image shows a state where we are in the middle of such "rerender after sort change":
https://user-images.githubusercontent.com/1890879/222460683-275c6f9a-ac3e-4426-a048-bfd7635a1bc5.png
I can imagine that any custom lit directive which handles list rendering will probably show the same behavior.
This PR solves this problem by deferring the resolution of the target element of the tooltip only after the current rendering is done and
ids of all involved elements become stable and final again.Fixes #5423
Type of change
Checklist