react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Please help me testing React-PDF 5.0 beta update!

Open wojtekmaj opened this issue 6 years ago • 41 comments

Hi, React-PDF v5.0.0-beta.5 has been released introducing a few major updates:

  • React-PDF now ships with ES6 Modules
  • Updated pdf.js from 2.1.266 to 2.4.456.

Breaking changes:

  • You will need to change your imports to bundler-specific entry files, for example instead of:
    import { Document } from 'react-pdf/dist/entry.webpack';
    
    you'll now write:
    import { Document } from 'react-pdf/dist/esm/entry.webpack';
    
  • Dropped support for IE 11 due to pdf.js dropping support

so upgrade should be a piece of cake.

Please share your experiences - whether it works correctly in your project, doesn't break the build, and so on.

Thanks!

wojtekmaj avatar Dec 07 '19 20:12 wojtekmaj

Hello,

i have updated from version 4.1.0 to this one and changed the imports. I could not detect any problems while building or executing.

Edll avatar Dec 09 '19 11:12 Edll

Hi

I just tested the new version: "react-pdf": "^5.0.0-beta"

In a testing (production build) environment, the following is logged to the console of Chromium: Refused to execute script from 'https://<redacted>/13.67eff32e9ffe66eca602.chunk.worker.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. And: Warning: Setting up fake worker.

The 13.67eff32e9ffe66eca602.chunk.worker.js file does not exist. It was never generated by Webpack. Webpack did generate two worker .js files that include "pdf" strings: vendors~pdfjsWorker.67eff32e9ffe66eca602.chunk.js 17fac81207a6368c84f4.worker.js

This is a SPA so the MIME type error is due to the frontend 404 page being returned from an invalid route.

I imagine this is probably a Webpack configuration issue. "webpack": "^4.41.3" "webpack-cli": "^3.3.10"

I am importing the Document and Page components each in a separate file and component: import { Document } from 'react-pdf/dist/esm/entry.webpack'; import { Page } from "react-pdf/dist/esm/entry.webpack";

It doesn't happen with Webpack config: mode: "development" But does happen with: mode: "production"

My Webpack config is a bit long/complicated so I'll see if I can isolate this to a particular set of config options.

robsco-git avatar Dec 17 '19 11:12 robsco-git

My Webpack config is a bit long/complicated so I'll see if I can isolate this to a particular set of config options.

I boiled this down to the Webpack config option: optimization.sideEffects.

With mode: "production" I needed to set:

optimization: {
    sideEffects: false,
}

This got the production build to work without falling back to the "fake worker" at runtime.

I imagine this is related to: https://github.com/wojtekmaj/react-pdf/blob/adb00b8a89c9ce2a27b554f348258b5a0a2c9e69/package.json#L8

robsco-git avatar Dec 17 '19 18:12 robsco-git

Removing the line https://github.com/wojtekmaj/react-pdf/blob/adb00b8a89c9ce2a27b554f348258b5a0a2c9e69/package.json#L8

Worked for me without having to include:

optimization: {
    sideEffects: false,
}

in my Webpack config with mode: "production".

Sorry for sort of hijacking this thread. I'll create a pull request shortly.

robsco-git avatar Dec 18 '19 09:12 robsco-git

I've tested 5.0.0-beta.2 both in development mode and a build that I ran locally. I didn't see any errors on the screen or in the console. I tested a wide variety of documents. It'd be nice to get the Worker Blob fix #452 in.

brentmitch avatar Jan 15 '20 18:01 brentmitch

I have tried running it with typescript but to no avail. Is there an up to date version of the @types/react-pdf that's compatible with the beta ?

I was hoping the beta might fix the #280 dependancy issue. I have used the cdn workaround and got react-pdf to work but would like to get rid of the error message.

vincentdegheyndt avatar Mar 04 '20 08:03 vincentdegheyndt

There are no substantial differences between 4.x and 5.x API, so types for 4.x should work 🤔

wojtekmaj avatar Mar 05 '20 18:03 wojtekmaj

Weird. Maybe I did something wrong.

import { Document } from 'react-pdf/dist/esm/entry.webpack'; import { Page } from 'react-pdf/dist/esm/entry.webpack'; import { pdfjs } from 'react-pdf/dist/esm/entry.webpack';

I used these lines to import the files and I get "Could not find a declaration file for module 'react-pdf/dist/esm/entry.webpack'."

vincentdegheyndt avatar Mar 10 '20 08:03 vincentdegheyndt

I'm considering using this in Polar (https://getpolarized.io/) as I need to rework our PDF viewer to be a bit more modern, support mobile + tablets, etc.

For us this would be a major component and I need it to be really solid.

There are a few things that are missing with react-pdf ... which you seem to have done a great job with btw!

  • PDFFindController isn't currently used? It's definitely a bit tough to figure out but I think I figured how their API (which is a big ugly).

  • Typescript. Would be nice if this was done completely in Typescript. How would you feel about a PR that migrated everything to TS?

  • The latest PDF.js (which just dropped 5x days ago) supports setting the background color of the canvas. I want to play with a dark mode and sepia mode for our users (top requested feature) so working on a port to the latest pdf.js might be done eventually as getting this done is a big priority for us.

I figure if the Typescript change is too much for you I can just work on the PDFFindController and latest PDF.js migration and then maybe you could cherrypick those and we would just maintain a fork for a bit.

Thoughts?

InputNeuron avatar Mar 26 '20 17:03 InputNeuron

@vincentdegheyndt That would be @DefinitelyTyped typings issue.

wojtekmaj avatar Mar 29 '20 10:03 wojtekmaj

@burtonator

PDFFindController isn't currently used? It's definitely a bit tough to figure out but I think I figured how their API (which is a big ugly).

I experimented with that in the past a little, but didn't find a good way to implement it as understandable React-based API. It's a pain - I'd love to see some concepts around this.

Typescript. Would be nice if this was done completely in Typescript. How would you feel about a PR that migrated everything to TS?

Since majority of our contributors, including the main one being me, are not very familiar with TypeScript, I see this as a thing that could potentially slow us down by a large chunk. We would need someone with this knowledge available as a fully fledged team member.

The latest PDF.js (which just dropped 5x days ago) supports setting the background color of the canvas. I want to play with a dark mode and sepia mode for our users (top requested feature) so working on a port to the latest pdf.js might be done eventually as getting this done is a big priority for us.

Mozilla doesn't have very good history with keeping their version numbers in line with semver guidelines, and that's why it's set to exact match in our dependencies. Still, more often than not, you can go ahead and try newer PDF.js version on your own (using yarn resolutions for example) without any major issues.

wojtekmaj avatar Mar 29 '20 10:03 wojtekmaj

FYI: next beta, v5.0.0-beta.3 is out :)

wojtekmaj avatar Apr 27 '20 15:04 wojtekmaj

Updated to v5.0.0-beta.3 from 4.1.0. I did not change how we import and stuck with current:

import { pdfjs, Document } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js`;

Importing like import { Document } from 'react-pdf/dist/esm/entry.webpack'; did not seem to work in our webpack project.

No other issues. The newer version of PDF.js fixed a rendering issue in some of our pdfs, so this update has been very welcome.

Thank you!

aleyan avatar Apr 28 '20 22:04 aleyan

Updated to 5.0.0-beta.3 and my app worked well.

xeger avatar Apr 29 '20 15:04 xeger

Updated to 5.0.0-beta.3

Uncaught TypeError: Cannot read property 'destroy' of undefined at Document.componentWillUnmount (Document.js:457)

457: this.loadingTask.destroy();

may be we need to null check loadingTask

pavanbi2i avatar Jun 02 '20 14:06 pavanbi2i

React-PDF 5.0.0-beta.4 is out. Hopefully a final one (although Webpack's 18th beta is making me feel a little better 😅)

pdf.js 2.4.456 is under the hood, although an ES5 build as I saw multiple compatibility issues with the new build, and I didn't want to introduce additional breaking changes between beta releases. Fix for @pavanbi2i's issue is also included.

wojtekmaj avatar Jun 10 '20 07:06 wojtekmaj

With v5.0.0-beta.4 I am seeing the following error in the console. Anyone else experiencing the same?

image

samalexander avatar Jun 10 '20 09:06 samalexander

Same - posting the error text for searchability:

getGlobalEventBus is deprecated, use a manually created EventBus instance instead.

A couple notes:

danieltott avatar Jun 11 '20 14:06 danieltott

I tried the following using yarn resolutions to try to use pdfjs-dist 2.5.207, but pdfjs was undefined 🤷‍♂️:

"resolutions": {
  "react-pdf/pdfjs-dist": "2.5.207"
},

danieltott avatar Jun 11 '20 15:06 danieltott

Hi @wojtekmaj,

Is npm updated too ? I've run npm update react-pdf and nothing happen. Should I delete this package and get the beta from github ?

ghost avatar Jun 11 '20 17:06 ghost