Skip to content

Fix GeoJson on_each_feature callback crashing - #2358

Open
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:fix-on-each-feature-asi
Open

KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:fix-on-each-feature-asi

Conversation

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor

Fix GeoJson(on_each_feature=...) crashing since v1.0.0

The problem

Every map that passes on_each_feature to GeoJson fails in the browser:

Uncaught TypeError: (intermediate value)(intermediate value)(...) is not a function
    at Object.geo_json_..._onEachFeature

The GeoJson layer then shows no features at all. The example in the
on_each_feature user guide
is affected too: none of its markers are drawn.

The cause

#2263 (released in v1.0.0) added a small IIFE at the start of the generated
onEachFeature function, which copies feature to the child layers of
multi-geometries. That statement has no trailing semicolon:

(function propagate(parent){ ... })(layer)
(function (feature, layer) { ... })(feature, layer);

A line that starts with ( doesn't trigger automatic semicolon insertion, so
the browser reads this as one expression. It calls the IIFE's return value
(undefined) with the user's callback as its argument, which throws.

The fix

Add the missing semicolons to the IIFE in the template. No behaviour changes
apart from that: the propagation from #2263 still runs first, then the
user's callback.

Tests

  • New Selenium test test_geojson_on_each_feature. It adds a GeoJson with an
    on_each_feature callback that binds a permanent tooltip, then checks that
    the console has no errors and the tooltip is shown.

  • Checked in a browser, before and after the fix:

    Map Before After
    Point feature with an on_each_feature tooltip (the new test case) TypeError, 0 markers, 0 tooltips No errors, 1 marker with its tooltip
    Basic example from the on_each_feature user guide TypeError, 0 markers No errors, both markers
  • tests/test_features.py and tests/test_issue_2278.py still pass.

The feature-propagation IIFE in the GeoJson template had no trailing
semicolon, so the browser parsed it together with the following
on_each_feature call and tried to call its return value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
pypi — b0cd9ff1 Deployed Nov 19, 2026 by KhadeerBasha1232 via packages #2112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant