Skip to content

Commit e32c016

Browse files
jespinomattermod
authored andcommitted
Lazy loading pdf.js library (mattermost#9371)
* Lazy loading pdf.js library * Removing pdfjs lib from plugins/export Co-authored-by: Mattermod <[email protected]>
1 parent 3427adf commit e32c016

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

components/pdf_preview.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import PropTypes from 'prop-types';
55
import React from 'react';
6-
import PDFJS from 'pdfjs-dist';
76
import debounce from 'lodash/debounce';
87

98
import {getFileDownloadUrl} from 'mattermost-redux/utils/file_utils';
@@ -147,7 +146,10 @@ export default class PDFPreview extends React.PureComponent {
147146
}
148147

149148
getPdfDocument = () => {
150-
PDFJS.getDocument(this.props.fileUrl).then(this.onDocumentLoad).catch(this.onDocumentLoadError);
149+
import('pdfjs-dist').then((PDFJS) => {
150+
PDFJS.disableWorker = true;
151+
PDFJS.getDocument(this.props.fileUrl).then(this.onDocumentLoad).catch(this.onDocumentLoadError);
152+
});
151153
}
152154

153155
onDocumentLoad = (pdf) => {

plugins/export.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ window.ReactRedux = require('react-redux');
2929
window.ReactBootstrap = require('react-bootstrap');
3030
window.ReactRouterDom = require('react-router-dom');
3131
window.PropTypes = require('prop-types');
32-
window.PDFJS = require('pdfjs-dist');
3332
window.Luxon = require('luxon');
3433

3534
// Functions exposed on window for plugins to use.

root.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import './entry.js';
66
import React from 'react';
77
import ReactDOM from 'react-dom';
88

9-
import PDFJS from 'pdfjs-dist';
10-
119
import {logError} from 'mattermost-redux/actions/errors';
1210

1311
// Import our styles
@@ -20,8 +18,6 @@ import {isDevMode, setCSRFFromCookie} from 'utils/utils';
2018
import store from 'stores/redux_store.jsx';
2119
import App from 'components/app';
2220

23-
PDFJS.disableWorker = true;
24-
2521
// This is for anything that needs to be done for ALL react components.
2622
// This runs before we start to render anything.
2723
function preRenderSetup(callwhendone) {

0 commit comments

Comments
 (0)