Skip to content

I 12947 workaround #4

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

Merged
merged 9 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@transcom/react-file-viewer",
"version": "1.3.2",
"version": "1.2.2",
"description": "Extendable file viewer for web",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down Expand Up @@ -82,7 +82,7 @@
"webpack-dev-server": "^5.0.4"
},
"dependencies": {
"pdfjs-dist": "^4.2.67",
"pdfjs-dist": "1.8.357",
"prop-types": "^15.5.10",
"react-visibility-sensor": "^5.0.2",
"sass": "^1.77.2",
Expand Down
38 changes: 24 additions & 14 deletions src/components/drivers/pdf-viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import React from 'react'
import VisibilitySensor from 'react-visibility-sensor'
import * as PDFJS from 'pdfjs-dist';
import { PDFJS } from 'pdfjs-dist/build/pdf.combined'
import 'pdfjs-dist/web/compatibility'

const INCREASE_PERCENTAGE = 0.2
const DEFAULT_SCALE = 1.1
// eslint-disable-next-line no-import-assign
PDFJS.isEvalSupported = false // DO NOT REMOVE THIS LINE OR ADJUST THE BOOLEAN VALUE ELSEWHERE IN THE CODE. This is a temporary workaround for https://github.com/transcom/mymove/security/dependabot/146
PDFJS.disableWorker = true

export class PDFPage extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -103,17 +107,20 @@ export default class PDFDriver extends React.Component {
}

componentDidMount() {
const { filePath } = this.props
const containerWidth = this.container.offsetWidth

const loadingTask = PDFJS.getDocument(filePath)
loadingTask.onProgress = (progressData) => {
this.progressCallback(progressData)
// Only utilize PDFJS.getDocument() if isEvalSupported == false.
if (PDFJS.isEvalSupported == false) {
const { filePath } = this.props
const containerWidth = this.container.offsetWidth

const loadingTask = PDFJS.getDocument(filePath)
loadingTask.onProgress = (progressData) => {
this.progressCallback(progressData)
}

loadingTask.then((pdf) => {
this.setState({ pdf, containerWidth })
})
}

loadingTask.then((pdf) => {
this.setState({ pdf, containerWidth })
})
}

setZoom(zoom) {
Expand Down Expand Up @@ -176,19 +183,22 @@ export default class PDFDriver extends React.Component {
<button
type="button"
className="view-control"
onClick={this.increaseZoom}>
onClick={this.increaseZoom}
>
<i className="zoom-in" />
</button>
<button
type="button"
className="view-control"
onClick={this.resetZoom}>
onClick={this.resetZoom}
>
<i className="zoom-reset" />
</button>
<button
type="button"
className="view-control"
onClick={this.reduceZoom}>
onClick={this.reduceZoom}
>
<i className="zoom-out" />
</button>
</div>
Expand Down
Loading
Loading