Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Lazy loading pdf.js library (#9371)
Browse files Browse the repository at this point in the history
* Lazy loading pdf.js library

* Removing pdfjs lib from plugins/export

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
  • Loading branch information
jespino and mattermod committed Nov 29, 2021
1 parent fbf5f76 commit 887a77b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
6 changes: 4 additions & 2 deletions components/pdf_preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import PropTypes from 'prop-types';
import React from 'react';
import PDFJS from 'pdfjs-dist';
import debounce from 'lodash/debounce';

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

getPdfDocument = () => {
PDFJS.getDocument(this.props.fileUrl).then(this.onDocumentLoad).catch(this.onDocumentLoadError);
import('pdfjs-dist').then((PDFJS) => {
PDFJS.disableWorker = true;
PDFJS.getDocument(this.props.fileUrl).then(this.onDocumentLoad).catch(this.onDocumentLoadError);
});
}

onDocumentLoad = (pdf) => {
Expand Down
1 change: 0 additions & 1 deletion plugins/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ window.ReactRedux = require('react-redux');
window.ReactBootstrap = require('react-bootstrap');
window.ReactRouterDom = require('react-router-dom');
window.PropTypes = require('prop-types');
window.PDFJS = require('pdfjs-dist');
window.Luxon = require('luxon');

// Functions exposed on window for plugins to use.
Expand Down
4 changes: 0 additions & 4 deletions root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import './entry.js';
import React from 'react';
import ReactDOM from 'react-dom';

import PDFJS from 'pdfjs-dist';

import {logError} from 'mattermost-redux/actions/errors';

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

PDFJS.disableWorker = true;

// This is for anything that needs to be done for ALL react components.
// This runs before we start to render anything.
function preRenderSetup(callwhendone) {
Expand Down

0 comments on commit 887a77b

Please sign in to comment.