From 84ef2049dc3e014b74742fec6af8fcc3e19ea36e Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 25 Nov 2024 18:25:09 +0100 Subject: [PATCH 1/3] Fix console errors during PDF preview --- config/webpack/webpack.common.ts | 2 +- patches/react-fast-pdf+1.0.15.patch | 13 +++++++++++++ src/components/PDFThumbnail/index.tsx | 2 +- src/types/modules/pdf.worker.d.ts | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 patches/react-fast-pdf+1.0.15.patch diff --git a/config/webpack/webpack.common.ts b/config/webpack/webpack.common.ts index 8aa8f5aa566c..c60670c72324 100644 --- a/config/webpack/webpack.common.ts +++ b/config/webpack/webpack.common.ts @@ -175,7 +175,7 @@ const getCommonConfiguration = ({file = '.env', platform = 'web'}: Environment): // We are importing this worker as a string by using asset/source otherwise it will default to loading via an HTTPS request later. // 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. { - test: new RegExp('node_modules/pdfjs-dist/legacy/build/pdf.worker.mjs'), + test: new RegExp('node_modules/pdfjs-dist/legacy/build/pdf.worker.min.mjs'), type: 'asset/source', }, diff --git a/patches/react-fast-pdf+1.0.15.patch b/patches/react-fast-pdf+1.0.15.patch new file mode 100644 index 000000000000..bfca1b418964 --- /dev/null +++ b/patches/react-fast-pdf+1.0.15.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/react-fast-pdf/dist/PDFPreviewer.js b/node_modules/react-fast-pdf/dist/PDFPreviewer.js +index 53d4849..aea6027 100644 +--- a/node_modules/react-fast-pdf/dist/PDFPreviewer.js ++++ b/node_modules/react-fast-pdf/dist/PDFPreviewer.js +@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { + Object.defineProperty(exports, "__esModule", { value: true }); + // @ts-expect-error - This line imports a module from 'pdfjs-dist' package which lacks TypeScript typings. + // eslint-disable-next-line import/extensions +-const pdf_worker_mjs_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.mjs")); ++const pdf_worker_mjs_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.min.mjs")); + const react_1 = __importStar(require("react")); + const times_1 = __importDefault(require("lodash/times")); + const react_window_1 = require("react-window"); diff --git a/src/components/PDFThumbnail/index.tsx b/src/components/PDFThumbnail/index.tsx index 1115ea21dad4..495c14ff76e1 100644 --- a/src/components/PDFThumbnail/index.tsx +++ b/src/components/PDFThumbnail/index.tsx @@ -1,6 +1,6 @@ import 'core-js/proposals/promise-with-resolvers'; // eslint-disable-next-line import/extensions -import pdfWorkerSource from 'pdfjs-dist/legacy/build/pdf.worker.mjs'; +import pdfWorkerSource from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs'; import React, {useMemo, useState} from 'react'; import {View} from 'react-native'; import {Document, pdfjs, Thumbnail} from 'react-pdf'; diff --git a/src/types/modules/pdf.worker.d.ts b/src/types/modules/pdf.worker.d.ts index cc59c0cb95a9..a6d70e529b7f 100644 --- a/src/types/modules/pdf.worker.d.ts +++ b/src/types/modules/pdf.worker.d.ts @@ -1 +1 @@ -declare module 'pdfjs-dist/legacy/build/pdf.worker.mjs'; +declare module 'pdfjs-dist/legacy/build/pdf.worker.min.mjs'; From 42c1ff5fce6407d7c8477a09884b9a949b04b2e0 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Mon, 25 Nov 2024 18:58:20 +0100 Subject: [PATCH 2/3] Fix storybook test --- .storybook/webpack.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.storybook/webpack.config.ts b/.storybook/webpack.config.ts index 92cea8666bc2..1c22608160cf 100644 --- a/.storybook/webpack.config.ts +++ b/.storybook/webpack.config.ts @@ -95,7 +95,7 @@ const webpackConfig = ({config}: {config: Configuration}) => { }); config.module.rules?.push({ - test: /pdf\.worker\.mjs$/, + test: /pdf\.worker\.min\.mjs$/, type: 'asset/source', }); From 0ac24b3243c5b2ec17f9303f8f2e2d9cb525a1a2 Mon Sep 17 00:00:00 2001 From: VickyStash Date: Thu, 28 Nov 2024 09:26:55 +0100 Subject: [PATCH 3/3] Update react-fast-pdf version --- package-lock.json | 9 +++++---- package.json | 2 +- patches/react-fast-pdf+1.0.15.patch | 13 ------------- 3 files changed, 6 insertions(+), 18 deletions(-) delete mode 100644 patches/react-fast-pdf+1.0.15.patch diff --git a/package-lock.json b/package-lock.json index 78c655c256cb..01e63ab53f53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,7 +73,7 @@ "react-content-loader": "^7.0.0", "react-dom": "18.3.1", "react-error-boundary": "^4.0.11", - "react-fast-pdf": "1.0.15", + "react-fast-pdf": "1.0.20", "react-map-gl": "^7.1.3", "react-native": "0.75.2", "react-native-android-location-enabler": "^2.0.1", @@ -34622,9 +34622,10 @@ } }, "node_modules/react-fast-pdf": { - "version": "1.0.15", - "resolved": "https://registry.npmjs.org/react-fast-pdf/-/react-fast-pdf-1.0.15.tgz", - "integrity": "sha512-xXrwIfRUD3KSRrBdfAeGnLZTf0kYUa+d6GGee1Hu0PFAv5QPBeF3tcV+DU+Cm/JMjSuR7s5g0KK9bePQ/xiQ+w==", + "version": "1.0.20", + "resolved": "https://registry.npmjs.org/react-fast-pdf/-/react-fast-pdf-1.0.20.tgz", + "integrity": "sha512-E2PJOO5oEqi6eNPllNOlQ8y0DiLZ3AW8t+MCN7AgJPp5pY04SeDveXHWvPN0nPU4X5sRBZ7CejeYce2QMMQDyg==", + "license": "MIT", "dependencies": { "react-pdf": "^9.1.1", "react-window": "^1.8.10" diff --git a/package.json b/package.json index 7278d11da7cd..a76dd7713271 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "react-content-loader": "^7.0.0", "react-dom": "18.3.1", "react-error-boundary": "^4.0.11", - "react-fast-pdf": "1.0.15", + "react-fast-pdf": "1.0.20", "react-map-gl": "^7.1.3", "react-native": "0.75.2", "react-native-android-location-enabler": "^2.0.1", diff --git a/patches/react-fast-pdf+1.0.15.patch b/patches/react-fast-pdf+1.0.15.patch deleted file mode 100644 index bfca1b418964..000000000000 --- a/patches/react-fast-pdf+1.0.15.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/node_modules/react-fast-pdf/dist/PDFPreviewer.js b/node_modules/react-fast-pdf/dist/PDFPreviewer.js -index 53d4849..aea6027 100644 ---- a/node_modules/react-fast-pdf/dist/PDFPreviewer.js -+++ b/node_modules/react-fast-pdf/dist/PDFPreviewer.js -@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { - Object.defineProperty(exports, "__esModule", { value: true }); - // @ts-expect-error - This line imports a module from 'pdfjs-dist' package which lacks TypeScript typings. - // eslint-disable-next-line import/extensions --const pdf_worker_mjs_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.mjs")); -+const pdf_worker_mjs_1 = __importDefault(require("pdfjs-dist/legacy/build/pdf.worker.min.mjs")); - const react_1 = __importStar(require("react")); - const times_1 = __importDefault(require("lodash/times")); - const react_window_1 = require("react-window");