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

Upgrade react-pdf from v8 to v9 #894

Draft
wants to merge 10 commits into
base: stable
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"react-imask": "^7.6.1",
"react-leaflet": "^4.2.1",
"react-number-format": "^5.4.2",
"react-pdf": "^8.0.2",
"react-pdf": "^9.2.1",
"react-router-dom": "^6.25.1",
"typescript": "^5.5.4",
"uuid": "^10.0.0",
Expand Down
9 changes: 6 additions & 3 deletions src/components/elements/upload/fileDialog/FilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import {
Typography,
} from '@mui/material';
import React, { useMemo, useState } from 'react';
import { Document, Page } from 'react-pdf';
import { Document, Page, pdfjs } from 'react-pdf';
import { FileFieldsFragment } from '@/types/gqlTypes';

pdfjs.GlobalWorkerOptions.workerSrc = new URL(
'pdfjs-dist/build/pdf.worker.min.mjs',
import.meta.url
).toString();

export type FileDialogProps = {
file: Pick<FileFieldsFragment, 'url' | 'name' | 'contentType'> &
Partial<Omit<FileFieldsFragment, 'url' | 'name' | 'contentType'>>;
Expand Down Expand Up @@ -179,8 +184,6 @@ const FilePreview: React.FC<{ file: FileDialogProps['file'] }> = ({ file }) => {
</Typography>
<Box
sx={(theme) => ({
backgroundColor: theme.palette.grey[300],
padding: 2,
gigxz marked this conversation as resolved.
Show resolved Hide resolved
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { DialogProps, Paper, Stack } from '@mui/material';
import pdfWorker from 'pdfjs-dist/build/pdf.worker.js?url';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it makes more sense for this to live in FilePreview since that component is actually rendering the pdf previews

import React, { useMemo } from 'react';
import { pdfjs } from 'react-pdf';

import FilePreview from '@/components/elements/upload/fileDialog/FilePreview';
import useSafeParams from '@/hooks/useSafeParams';
import ViewRecordDialog from '@/modules/form/components/ViewRecordDialog';
import { FileFieldsFragment, RecordFormRole } from '@/types/gqlTypes';

pdfjs.GlobalWorkerOptions.workerSrc = pdfWorker;

// component for viewing a FileFieldsFragment. Viewing an unsaved File is not currently supported
export type FileRecordDialogProps = {
file: FileFieldsFragment;
Expand Down
3 changes: 3 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export default defineConfig(({ command, mode }) => {
// Drop log statements when minifying
pure: ['console.log', 'console.info', 'console.debug'],
},
optimizeDeps: {
include: ['pdfjs-dist/build/pdf.worker.min.mjs'],
},
test: {
watch: false,
},
Expand Down
Loading
Loading