-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 issue whereby tooltips loaded dynamically while moving the map were never shown. #8672
Fix issue whereby tooltips loaded dynamically while moving the map were never shown. #8672
Conversation
@theGOTOguy could you stop adding new commits to this PR? It creates a lot of unnecessary noise. Besides, we will rebase and quash the commits either way. |
Also please rebase your PR on |
30306b8
to
f5a57c1
Compare
…ap," which was added multiple times.
f5a57c1
to
fa40d46
Compare
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.
The check for map dragging was added in #7862 to prevent adding / removing of the tooltip when occasionally hovering over the marker with the mouse while dragging.
this._moving = false; | ||
Draggable._dragging = false; | ||
|
||
if (fireDragend) { |
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.
@mourner @jonkoops @IvanSanchez do you see any problems with setting the flags to false
before fireing the event?
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.
It seems like the only way this would matter would be if someone was looking at _moving
or _dragging
during the handling of a dragend
event. We're not doing it internally to Leaflet, but it's possible that someone who depends on us might. To do so would be inadvisable, because there would be a race between the event firing and _moving
and _dragging
being updated after the event is fired. Maybe mark this as a breaking API change in case someone depends on the state of _moving
or _dragging
in an event triggered by dragend
?
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 have no issue with that, this is internal state so folks should not be relying on it anyways.
src/layer/Tooltip.js
Outdated
if (!this._openOnceFlag) { | ||
this._openOnceFlag = true; | ||
this._map.once('moveend', () => { | ||
this._openOnceFlag = false; | ||
this._openTooltip(e); | ||
}); | ||
} |
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.
@mourner @jonkoops @IvanSanchez have someone a good Idea to make this cleaner? The once
listener should not be added multiple times and it is important to pass e
as argument from the original _openTooltip
call.
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.
Here's a couple of ideas:
Superficially, you could do something like this:
// If the map is moving, we will show the tooltip after it's done.
if (this._map.dragging && this._map.dragging.moving() && !this._openOnceFlag) {
this._openOnceFlag = true;
this._map.once('moveend', () => {
this._openOnceFlag = false;
this._openTooltip(e);
});
return;
}
It's not satisfying because we still have to store _openOnceFlag
.
However, maybe there's a better solution. There are only four places where _openTooltip
is called at all, and they're all here in Tooltip.js
.
We could replace all instances of _openTooltip
with _openTooltipWhenNotMoving
, with:
_openTooltipWhenNotMoving(e) {
if (this._map.dragging && this._map.dragging.moving()) {
this._map.once('moveend', () => {
this._openTooltip(e);
});
} else {
this._openTooltip(e);
}
}
Then remove the moving checks from _openTooltip
proper.
In this way, we avoid storing an extra variable, and call _openTooltip
at most once at an appropriate time when it would be needed.
Edit: I'm concerned that the _openOnceFlag
might actually be incorrect. If the Tooltip
was closed for any reason (say, permanent
is set to false
by some external code), then we could find that if it is later set to true
again then it would no longer appear if _openTooltip
is called while dragging.
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've implemented the former solution, which at least resolves a little bit of the nesting.
I don't see a better solution than the _openOnceFlag
that you implemented, and I've convinced myself that it is correct even in case where some external code toggles permanent
.
This is still an issue for me in production, and I'm wondering if you could take a look at the changes I've made and let me know if the solution as it sits is appropriate or if more changes are desired. |
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.
Fine for me but we need an approve from another maintainer @IvanSanchez @mourner
…re never shown. (#8672) Co-authored-by: Florian Bischof <design.falke@gmail.com>
Slava Ukraini,
leaflet
team!This pull request resolves #8591, whereby
Tooltip
s were not added to the DOM while the map was moving.@BasieP's analysis of the offending code was correct, as is the workaround suggested; However, I am using
react-leaflet
, where this workaround is not an option.An automatic test is included.