Vendor a glyphicons-only stylesheet instead of the full Bootstrap 3 base - #2257
Vendor a glyphicons-only stylesheet instead of the full Bootstrap 3 base#2257adarshsm wants to merge 3 commits into
Conversation
folium loaded netdna's bootstrap-glyphicons.css for the Awesome Markers glyphicon font. Despite its name that file is a full Bootstrap 3 base stylesheet: alongside the @font-face/.glyphicon rules it ships a normalize reset and global body styles (font, colour, background, margin). Loaded after Bootstrap 5, those body rules leaked onto the host page and, e.g., mispositioned user-added Bootstrap 5 components (python-visualizationGH-1820). Ship a vendored folium/templates/glyphicons.css with only the @font-face and .glyphicon/.glyphicon-* rules (fonts served from jsDelivr), referenced the same way as leaflet.awesome.rotate.css. Icon(prefix="glyphicon") markers keep working; the page-wide body/reset pollution is gone. Closes python-visualization#1820
…DN file The previous approach linked the vendored glyphicons stylesheet from `cdn.jsdelivr.net/gh/.../folium/templates/glyphicons.css`. That URL is served from the default branch, so it 404s until this PR is merged — a chicken-and-egg that fails the snapshot job (the `.glyphicon` rules never load) and, for a released package, would point at a mutable `main`. Inline the glyphicons-only rules into every `Map` as a `<style>` block, read once from the packaged `folium/templates/glyphicons.css`. Markers keep working with no external stylesheet request and no page-wide side effects, which is the python-visualizationGH-1820 goal; the glyph font still loads from the stable `bootstrap@3.3.7` npm files. Update the vendoring test to assert the rules are inlined rather than linked.
|
Pushed a follow-up that should fix the failing snapshot job. What was wrong: the vendored stylesheet was linked from Fix ( One thing that still needs doing: the 7 snapshot baselines legitimately change, because dropping the leaked Bootstrap body-reset alters rendering even for non-glyphicon maps (e.g. |
The netdna glyphicons stylesheet carried a full Bootstrap 3 reset,
including html{font-size:62.5%}. That shrank every relative font size on
the map page, so Leaflet's attribution and branca's colorbar caption
rendered smaller than either library intends. Dropping the reset restores
them, which is the only pixel difference in the seven snapshots.
Screenshots taken from the CI run for 59a744c (ubuntu-latest), so they
match the environment that compares them.
|
CI is fixed in 9d24e8d, and the cause is worth a look before merging. The snapshots were failing for a real reason, not a rendering fluke. All seven failed, and the pixel diffs are confined to text: Leaflet's attribution in the corner and, on The old netdna stylesheet was not glyphicons-only — it carried a full Bootstrap 3 reset, and among it: html{font-size:62.5%;}
body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;...}
*,*:before,*:after{box-sizing:border-box;}
So this is the leak from GH-1820 showing up on the map's own page too, not only on the host page embedding it. The old screenshots recorded the shrunken text; the new ones record what Leaflet and branca ask for. I took the replacement screenshots from the CI artifact of the run against 59a744c ( One thing to flag explicitly since it is your call, not mine: this makes the attribution and colorbar text slightly larger in every map, not just the one in the issue. I think that is correct — folium should not be resizing its own root font — but it is a visible change for existing users, so say the word if you would rather scope the stylesheet differently. |
Closes #1820. Thanks @hansthen for the steer.
folium loads netdna's
bootstrap-glyphicons.cssfor the Awesome Markers glyphicon font. Despite the name, that file is a full Bootstrap 3 base stylesheet — alongside the@font-face/.glyphiconrules it ships a normalize reset and globalbodyrules (font, colour, background,margin). Loaded after Bootstrap 5, thosebodyrules leak onto the host page and, for example, mis-position a user-added Bootstrap 5 modal (the original report).This vendors
folium/templates/glyphicons.csscontaining only the@font-faceand.glyphicon/.glyphicon-*rules (fonts served from jsDelivr), referenced the same way as the existingleaflet.awesome.rotate.css.Icon(prefix="glyphicon")markers keep working exactly as before; the page-widebody/reset pollution is gone.Not a customer-facing change — glyphicon markers are unaffected; the only difference is that folium stops overriding the host page's
bodystyles. Added a regression test asserting the vendored file is used and the netdna URL is gone.