Bug #12393
openWLeafletMap JS error when refreshing after panning
0%
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) andwtResize
were initially assigned and still exist because we rerender the existing session - Member
WLeafletMap
has theposition_
coordinates in its parameters, which now differ from the initial coordinates WWebWidget::setJavaScriptMember()
andWWebWidget::addJavaScriptStatement
will cause member changes to be put intojsStatements_
- In
WWebWidget::updateDom()
,declareJavaScriptMember()
is first executed forjsMembers_
that are not injsStatements_
wtResize
does not occur injsStatements_
(because it has not changed), butWLeafletMap
does, so assignment forwtResize
is executed first
No data to display