Skip to content

Commit 5102377

Browse files
authored
Merge pull request Expensify#68332 from callstack-internal/remove-legacy-pdf-worker
Remove legacy pdf worker to reduce bundle size
2 parents d0bb88f + b789b51 commit 5102377

3 files changed

Lines changed: 1 addition & 16 deletions

File tree

config/webpack/webpack.common.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,12 @@ const getCommonConfiguration = ({file = '.env', platform = 'web'}: Environment):
189189
*/
190190
exclude: [new RegExp(`node_modules/(?!(${includeModules})/).*|.native.js$`)],
191191
},
192-
193192
// We are importing this worker as a string by using asset/source otherwise it will default to loading via an HTTPS request later.
194193
// This causes issues if we have gone offline before the pdfjs web worker is set up as we won't be able to load it from the server.
195194
{
196-
// eslint-disable-next-line prefer-regex-literals
197195
test: new RegExp('node_modules/pdfjs-dist/build/pdf.worker.min.mjs'),
198196
type: 'asset/source',
199197
},
200-
{
201-
// eslint-disable-next-line prefer-regex-literals
202-
test: new RegExp('node_modules/pdfjs-dist/legacy/build/pdf.worker.min.mjs'),
203-
type: 'asset/source',
204-
},
205198

206199
// Rule for react-native-web-webview
207200
{

src/components/PDFThumbnail/index.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import 'core-js/proposals/promise-with-resolvers';
22
// eslint-disable-next-line import/extensions
33
import pdfWorkerSource from 'pdfjs-dist/build/pdf.worker.min.mjs';
4-
// eslint-disable-next-line import/extensions
5-
import pdfWorkerLegacySource from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
64
import React, {useMemo, useState} from 'react';
75
import {View} from 'react-native';
86
import {Document, pdfjs, Thumbnail} from 'react-pdf';
97
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
108
import useThemeStyles from '@hooks/useThemeStyles';
119
import addEncryptedAuthTokenToURL from '@libs/addEncryptedAuthTokenToURL';
12-
import {isMobileSafari, isModernSafari} from '@libs/Browser';
1310
import PDFThumbnailError from './PDFThumbnailError';
1411
import type PDFThumbnailProps from './types';
1512

16-
const shouldUseLegacyWorker = isMobileSafari() && !isModernSafari();
17-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18-
const pdfWorker = shouldUseLegacyWorker ? pdfWorkerLegacySource : pdfWorkerSource;
19-
2013
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
21-
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorker], {type: 'text/javascript'}));
14+
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'}));
2215
}
2316

2417
function PDFThumbnail({previewSourceURL, style, isAuthTokenRequired = false, enabled = true, onPassword, onLoadError, onLoadSuccess}: PDFThumbnailProps) {

src/types/modules/pdf.worker.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
declare module 'pdfjs-dist/legacy/build/pdf.worker.min.mjs';
21
declare module 'pdfjs-dist/build/pdf.worker.min.mjs';

0 commit comments

Comments
 (0)