Skip to content

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

Merged
hansthen merged 2 commits into
python-visualization:mainfrom
vraj2131:fix-repeated-save-duplication
Jun 13, 2026
Merged

Fix duplicate HTML when map.save() is called repeatedly#2239
hansthen merged 2 commits into
python-visualization:mainfrom
vraj2131:fix-repeated-save-duplication

Conversation

@vraj2131

@vraj2131 vraj2131 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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 Outdated

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

Keep only ElementAddToElement.render() and Marker.SetIcon.render()
per review feedback.
@vraj2131

Copy link
Copy Markdown
Contributor Author

The default path uses a new random script name each render, the overrides use deterministic names tied to the element or marker, so repeated save() updates the same script slot instead of duplicating it.

@hansthen

Copy link
Copy Markdown
Collaborator

Running the automated tests now.

@vraj2131

Copy link
Copy Markdown
Contributor Author

Publish Docs fails on an external WMS timeout in WmsTimeDimension.md, issue is not from this PR?

@hansthen hansthen merged commit f13798b into python-visualization:main Jun 13, 2026
13 of 14 checks passed
@hansthen

Copy link
Copy Markdown
Collaborator

Publish Docs fails on an external WMS timeout in WmsTimeDimension.md, issue is not from this PR?

Correct. Will merge.

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