Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asynchronously load libraries for png and pdf exports #41036

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { css } from "@emotion/react";
import html2canvas from "html2canvas";

export const SAVING_DOM_IMAGE_CLASS = "saving-dom-image";
export const SAVING_DOM_IMAGE_HIDDEN_CLASS = "saving-dom-image-hidden";
Expand All @@ -22,6 +21,7 @@ export const saveChartImage = async (selector: string, fileName: string) => {

node.classList.add(SAVING_DOM_IMAGE_CLASS);

const { default: html2canvas } = await import("html2canvas");
const canvas = await html2canvas(node, {
useCORS: true,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import html2canvas from "html2canvas";
import jspdf from "jspdf";

import { color } from "metabase/lib/colors";

import { SAVING_DOM_IMAGE_CLASS } from "./save-chart-image";
Expand All @@ -17,6 +14,7 @@ export const saveDashboardPdf = async (
return;
}

const { default: html2canvas } = await import("html2canvas");
const image = await html2canvas(node, {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'd keep import on the top level, but with import(), so the new chunk will be created automatically and at the same time user will not need to wait for chunk to be downloaded after a click to "download"

actually if you already wait for downloading some big file, chunk loading is not a problem, so please ignore my comment

useCORS: true,
onclone: (doc: Document, node: HTMLElement) => {
Expand All @@ -35,6 +33,7 @@ export const saveDashboardPdf = async (
const pdfWidth = imageWidth;
const pdfHeight = imageHeight + 80;

const { default: jspdf } = await import("jspdf");
const pdf = new jspdf({
unit: "px",
hotfixes: ["px_scaling"],
Expand Down