perf: only import JSZip when needed (bundle splitting) (#1933)

This commit is contained in:
Braden MacDonald
2025-05-30 09:45:20 -07:00
committed by GitHub
parent 0eaa7f6f88
commit f02347dd71
2 changed files with 6 additions and 3 deletions

View File

@@ -358,7 +358,9 @@ describe('FilesAndUploads', () => {
global.fetch = jest.fn().mockImplementation(() => mockFetchResponse);
fireEvent.click(downloadButton);
expect(fetch).toHaveBeenCalledTimes(2);
await waitFor(() => {
expect(global.fetch).toHaveBeenCalledTimes(2);
});
});
it('sort button should be enabled and sort files by name', async () => {

View File

@@ -1,7 +1,6 @@
import { camelCaseObject, ensureConfig, getConfig } from '@edx/frontend-platform';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import JSZip from 'jszip';
import saveAs from 'file-saver';
ensureConfig([
@@ -39,11 +38,13 @@ export async function getAssetDetails({ courseId, filenames, fileCount }) {
/**
* Fetch asset file.
* @param {blockId} courseId Course ID for the course to operate on
*/
export async function getDownload(selectedRows, courseId) {
const downloadErrors = [];
if (selectedRows?.length > 1) {
// Don't import JSZip until/unless we need it, to bundle multiple files into one download.
// This helps keep the main Authoring MFE bundle size smaller.
const JSZip = (await import('jszip')).default;
const zip = new JSZip();
const date = new Date().toString();
const folder = zip.folder(`${courseId}-assets-${date}`);