Repository navigation
fix(dashboard): don't fail PDF export when a MapLibre/Mapbox map is present - #46694
Open
anshurajbisoyi98-ctrl wants to merge 1 commit into
Open
anshurajbisoyi98-ctrl wants to merge 1 commit into
anshurajbisoyi98-ctrl wants to merge 1 commit into
Conversation
…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>
|
We would appreciate it if you could provide us with more info about this issue/pr! Please do not leave the |
| image: { type: 'jpeg', quality: 1 }, | ||
| html2canvas: { scale: 2 }, | ||
| excludeClassNames: ['header-controls'], | ||
| excludeClassNames: ['header-controls', ...MAP_CONTROL_CLASS_NAMES], |
Contributor
There was a problem hiding this comment.
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
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
Contributor
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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+xmlURI 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,%3Cturns into a raw<inside astyleattribute, 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-attribandmapboxgl-ctrl-logoto dom-to-pdf'sexcludeClassNames. The zoom/compass buttons use the same kind of icons, but dom-to-pdf already drops every<button>. I first tried excluding the wholemaplibregl-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 indownloadAsPdf.tsnever 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
preserveDrawingBufferon Safari inDeckGLContainer.tsx, so its WebGL canvas reads back empty. Happy to look at that in a follow-up.TESTING INSTRUCTIONS
superset load-examplesand open the "deck.gl Demo" dashboardThe unit tests in
downloadAsPdf.test.tspass, including a new one for the excluded classes.ADDITIONAL INFORMATION
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.