Skip to content

Commit f02347d

Browse files
perf: only import JSZip when needed (bundle splitting) (openedx#1933)
1 parent 0eaa7f6 commit f02347d

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/files-and-videos/files-page/FilesPage.test.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ describe('FilesAndUploads', () => {
358358

359359
global.fetch = jest.fn().mockImplementation(() => mockFetchResponse);
360360
fireEvent.click(downloadButton);
361-
expect(fetch).toHaveBeenCalledTimes(2);
361+
await waitFor(() => {
362+
expect(global.fetch).toHaveBeenCalledTimes(2);
363+
});
362364
});
363365

364366
it('sort button should be enabled and sort files by name', async () => {

src/files-and-videos/files-page/data/api.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { camelCaseObject, ensureConfig, getConfig } from '@edx/frontend-platform';
22
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
33

4-
import JSZip from 'jszip';
54
import saveAs from 'file-saver';
65

76
ensureConfig([
@@ -39,11 +38,13 @@ export async function getAssetDetails({ courseId, filenames, fileCount }) {
3938
/**
4039
* Fetch asset file.
4140
* @param {blockId} courseId Course ID for the course to operate on
42-
4341
*/
4442
export async function getDownload(selectedRows, courseId) {
4543
const downloadErrors = [];
4644
if (selectedRows?.length > 1) {
45+
// Don't import JSZip until/unless we need it, to bundle multiple files into one download.
46+
// This helps keep the main Authoring MFE bundle size smaller.
47+
const JSZip = (await import('jszip')).default;
4748
const zip = new JSZip();
4849
const date = new Date().toString();
4950
const folder = zip.folder(`${courseId}-assets-${date}`);

0 commit comments

Comments
 (0)