Skip to content

Fix duplicate HTML when map.save() is called repeatedly#2239

Open
vraj2131 wants to merge 1 commit into
python-visualization:mainfrom
vraj2131:fix-repeated-save-duplication
Open

Fix duplicate HTML when map.save() is called repeatedly#2239
vraj2131 wants to merge 1 commit into
python-visualization:mainfrom
vraj2131:fix-repeated-save-duplication

Conversation

@vraj2131

@vraj2131 vraj2131 commented Jun 12, 2026

Copy link
Copy Markdown

Summary

  • Use stable script names for SetIcon and ElementAddToElement so repeated save() calls replace JavaScript instead of appending duplicates
  • Avoid clearing figure.html during render() so geopandas legend HTML added directly to the figure is preserved
  • Add regression test ensuring multiple save() calls produce identical HTML

Fixes #2237

Test plan

  • pytest tests/test_map.py::test_repeated_save_produces_identical_html
  • pytest geopandas/tests/test_explore.py legend tests (categorical legend, colorbar, mapclassify)
  • pytest tests --ignore=tests/selenium
  • pre-commit run on changed files

@vraj2131 vraj2131 force-pushed the fix-repeated-save-duplication branch from 14e8de6 to 9707f4a Compare June 13, 2026 04:27
Repeated save() calls appended duplicate JavaScript because SetIcon and
ElementAddToElement created new render children with unique IDs on each
pass. Use stable script names so repeated renders replace instead of
append. Do not clear figure.html in render(); geopandas adds legend HTML
directly there.

Fixes python-visualization#2237
@vraj2131 vraj2131 force-pushed the fix-repeated-save-duplication branch from 9707f4a to 2b7290a Compare June 13, 2026 04:28
@banderlog

Copy link
Copy Markdown

neuroslope

@hansthen

Copy link
Copy Markdown
Collaborator

Seems like a sensible change. I do not understand everything yet. Why is the render method redefined?

Comment thread folium/figure.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are irrelevant

Comment thread folium/__init__.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are irrelevant

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are irrelevant

@banderlog

banderlog commented Jun 13, 2026

Copy link
Copy Markdown

Adding elements.ElementAddToElement.render() AND map.Marker.SetIcon.render() actually solves the problem -- output HTML files will have identical md5hash.

But I have no idea why

UPD: all other changes, except those two above mentioned functions are irrelevant

Comment thread folium/folium.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are irrelevant

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.

Repeated saves duplicate HTML content and increase file size

3 participants