bito-code-review[bot] commented on code in PR #44529:
URL: https://github.com/apache/superset/pull/44529#discussion_r4086966181
##########
superset-frontend/src/utils/downloadAsImage.tsx:
##########
@@ -559,14 +571,36 @@ export default function downloadAsImageOptimized(
}),
};
- const dataUrl = isPng
- ? await domToImage.toPng(agRootWrapper, agImageOptions)
- : await domToImage.toJpeg(agRootWrapper, agImageOptions);
+ let dataUrl: string;
+ if (isSafari()) {
+ // `dom-to-image-more` relies on SVG <foreignObject>, which WebKit
does
+ // not reliably paint. Keep the ag-grid preparation above, then use a
+ // DOM painter for the actual Safari capture.
+ const { default: html2canvas } = await import('html2canvas');
+ const canvas = await html2canvas(agRootWrapper, {
+ backgroundColor:
+ bgcolor === TRANSPARENT_RGBA ? null : (bgcolor ?? null),
+ height: imageHeight,
+ width: originalWidth,
+ scale,
+ useCORS: true,
+ logging: false,
+ ignoreElements: element => !filter(element),
+ onclone: (_document, clone) => {
+ preserveCanvasContent(agRootWrapper, clone);
+ },
+ });
+ dataUrl = canvas.toDataURL(
+ isPng ? 'image/png' : 'image/jpeg',
+ IMAGE_DOWNLOAD_QUALITY,
+ );
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>duplicated Safari capture logic</b></div>
<div id="fix">
The two new Safari branches (575-596 and 649-677) duplicate the html2canvas
setup: dynamic import, the options object
(backgroundColor/scale/useCORS/logging/ignoreElements), and `toDataURL(...,
IMAGE_DOWNLOAD_QUALITY)`. Only the element, dimensions, and `onclone` differ.
Extract one helper to keep the two capture paths from drifting.
</div>
</div>
<small><i>Code Review Run #24d708</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
##########
superset-frontend/plugins/preset-chart-deckgl/src/DeckGLContainer.tsx:
##########
@@ -51,6 +51,9 @@ const TICK = 250; // milliseconds
const DEFAULT_MAP_STYLE =
'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
+const isSafari = () =>
+ /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Duplicated Safari detection logic</b></div>
<div id="fix">
`isSafari()` and the `preserveDrawingBuffer`/`canvasContextAttributes`
wiring duplicate `plugin-chart-point-cluster-map/src/MapLibre.tsx` (lines
48-49, 230, 243-244) exactly. If the detection or prop contract changes, both
plugins must be updated in lockstep. Consider extracting a shared helper (e.g.
in `@superset-ui/core`) and reusing it in both `MapLibre.tsx` and
`DeckGLContainer.tsx`.
</div>
</div>
<small><i>Code Review Run #24d708</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]