Skip to content

fix(dashboard): don't fail PDF export when a MapLibre/Mapbox map is present - #46694

Open
anshurajbisoyi98-ctrl wants to merge 1 commit into
apache:masterfrom
anshurajbisoyi98-ctrl:fix/dashboard-pdf-export-maplibre
Open

anshurajbisoyi98-ctrl wants to merge 1 commit into
apache:masterfrom
anshurajbisoyi98-ctrl:fix/dashboard-pdf-export-maplibre

Conversation

@anshurajbisoyi98-ctrl

@anshurajbisoyi98-ctrl anshurajbisoyi98-ctrl commented Nov 29, 2026 •

Copy link
Copy Markdown

SUMMARY

Dashboard "Export to PDF" fails as soon as a deck.gl chart with a MapLibre base map is on the dashboard. Nothing downloads, and the console only shows Event {type: 'error', target: img}.

The cause is in the dom-to-image fork that dom-to-pdf uses. It serializes the cloned dashboard into a data:image/svg+xml URI but only escapes # and newlines, not %. MapLibre (and Mapbox) style the attribution toggle and the logo with percent-encoded SVG data URIs (url("data:image/svg+xml;charset=utf-8,%3Csvg ...")). When the outer URI is decoded, %3C turns into a raw < inside a style attribute, the SVG is no longer valid XML, and the final image fails to load. That rejects the whole export.

This PR adds maplibregl-ctrl-attrib, maplibregl-ctrl-logo, mapboxgl-ctrl-attrib and mapboxgl-ctrl-logo to dom-to-pdf's excludeClassNames. The zoom/compass buttons use the same kind of icons, but dom-to-pdf already drops every <button>. I first tried excluding the whole maplibregl-control-container, but deck.gl mounts its overlay canvas inside that container, so the charts came out empty.

One thing I noticed but left alone: dom-to-pdf catches its own errors and only calls console.error, so the "PDF download failed" toast in downloadAsPdf.ts never shows for this kind of failure.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before: on the deck.gl Demo dashboard, Export to PDF downloads nothing, and the console shows Event {isTrusted: true, type: 'error', target: img, ...}.

After: the PDF is generated with all deck.gl charts (screenshot of the exported page):

The base map tiles are blank in the PDF on Chrome/Firefox. That's a separate, existing limitation: MapLibre only gets preserveDrawingBuffer on Safari in DeckGLContainer.tsx, so its WebGL canvas reads back empty. Happy to look at that in a follow-up.

TESTING INSTRUCTIONS

  1. superset load-examples and open the "deck.gl Demo" dashboard
  2. ... > Download > Export to PDF
  3. Before this change nothing downloads and the console shows the img error event. With it, the PDF downloads with all the charts.

The unit tests in downloadAsPdf.test.ts pass, including a new one for the excluded classes.

ADDITIONAL INFORMATION

  • Has associated issue: Fixes Dashboard ; Export PDF failed if external map is used #46638
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

AI disclosure: I used Claude to help trace the failure through dom-to-pdf and dom-to-image and to draft this description. I reproduced the bug and tested the fix on a local Superset build, and I reviewed the change myself.

…resent

The dom-to-image fork used by dom-to-pdf builds an SVG data URI without
escaping '%'. MapLibre and Mapbox style the attribution toggle and logo
with percent-encoded SVG data URIs, which decode into a raw '<' inside a
style attribute, so the SVG fails to load and the export is rejected.

Leave those two controls out of the PDF. The control container itself
is kept because deck.gl mounts its canvas inside it.

Fixes apache#46638

Signed-off-by: anshurajbisoyi98-ctrl <anshurajbisoyi98@gmail.com>
@request-info

request-info Bot commented Nov 29, 2026

Copy link
Copy Markdown

We would appreciate it if you could provide us with more info about this issue/pr! Please do not leave the title or description empty.

image: { type: 'jpeg', quality: 1 },
html2canvas: { scale: 2 },
excludeClassNames: ['header-controls'],
excludeClassNames: ['header-controls', ...MAP_CONTROL_CLASS_NAMES],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: For exports containing a MapLibre or Mapbox map, this excludes the full attribution and logo elements, so the PDF loses provider and source credits even when map rendering succeeds.

Assessment: 🟠 Major · 🔁 Occurrence: Often · 🏷️ Logic error

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset-frontend/src/utils/downloadAsPdf.ts
**Line:** 102:102
**Comment:**
	*Logic Error: For exports containing a MapLibre or Mapbox map, this excludes the full attribution and logo elements, so the PDF loses provider and source credits even when map rendering succeeds.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging.
  • Excluding MapLibre and Mapbox attribution elements removes provider and source credits from PDFs containing maps.

Assessed commit: f21c6a8c8c14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard ; Export PDF failed if external map is used

1 participant