Actions
Bug #12393
openWLeafletMap JS error when refreshing after panning
Start date:
02/08/2024
Due date:
% Done:
0%
Estimated time:
Description
When you pan a WLeafletMap after its coordinates were initially set using panTo() and then rerender the session, a JS error occurs: Wt4_10_3.$(...).wtObj is undefined.
A minimal example is this:
LeafletApplication::LeafletApplication(const Wt::WEnvironment &env)
: WApplication(env)
{
auto map = root()->addNew<Wt::WLeafletMap>();
map->panTo(Wt::WLeafletMap::Coordinate(50.906705, 4.655800));
auto button = root()->addNew<Wt::WPushButton>("Crash and burn, please");
button->clicked().connect([this, map] {
map->panTo(Wt::WLeafletMap::Coordinate(0.0, 0.0));
redirect(url());
});
}
The application uses Leaflet 1.9.4 with reload-is-new-session set to false:
<session-management>
<reload-is-new-session>false</reload-is-new-session>
</session-management>
<properties>
<property name="leafletJSURL">https://unpkg.com/leaflet@1.9.4/dist/leaflet.js</property>
<property name="leafletCSSURL">https://unpkg.com/leaflet@1.9.4/dist/leaflet.css</property>
</properties>
The JS error occurs when clicking the button. The error is propagated to the server logs upon clicking again. This can also be triggered by panning and then refreshing manually (after adding an initial size and layer).
Note that when Leaflet option trackResize is true (the default), this also occurs upon resize because the map is then panned automatically. A resize is triggered e.g. when the virtual keyboard opens on Android (even when the map is hidden).
- Panning causes Leaflet to emit
moveend, which causesWLeafletMap::position_to be changed - Upon rerendering,
WLeafletMap::defineJavaScript()is re-executed - The JS members
WLeafletMap(constructor) andwtResizewere initially assigned and still exist because we rerender the existing session - Member
WLeafletMaphas theposition_coordinates in its parameters, which now differ from the initial coordinates WWebWidget::setJavaScriptMember()andWWebWidget::addJavaScriptStatementwill cause member changes to be put intojsStatements_- In
WWebWidget::updateDom(),declareJavaScriptMember()is first executed forjsMembers_that are not injsStatements_ wtResizedoes not occur injsStatements_(because it has not changed), butWLeafletMapdoes, so assignment forwtResizeis executed first
Updated by Matthias Van Ceulebroeck about 2 months ago
- Target version set to 4.12.3
Updated by Raf Pauwels about 2 months ago
- Status changed from InProgress to Review
- Assignee deleted (
Raf Pauwels)
Actions