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

[HOLD for payment 2025-01-02] Update react-fast-pdf to use modern pdfjs-dist lib #54095

Open
gedu opened this issue Dec 13, 2024 · 8 comments
Open
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Weekly KSv2

Comments

@gedu
Copy link
Contributor

gedu commented Dec 13, 2024

Background

react-fast-pdf is a library that simplifies working with PDF files in React applications by leveraging pdfjs-dist, a popular library for rendering PDFs. However, pdfjs-dist provides multiple builds of its worker file (pdf.worker.js), including a legacy version designed for older browsers and a modern version optimized for newer environments.
Currently, react-fast-pdf is configured to always load the legacy version of pdf.worker.js (pdfjs-dist/legacy/build/pdf.worker.mjs). This approach ensures compatibility with older browsers but does not take advantage of the performance improvements and reduced file size offered by the modern build. As a result, even applications running in modern browsers are forced to use the less efficient legacy build, which increases resource usage and impacts performance.
This behavior is particularly relevant for developers aiming to optimize their applications for modern environments, where smaller bundle sizes and faster load times are critical for user experience.

Problem

When using react-fast-pdf, it always loads the legacy version of pdf.worker.js from pdfjs-dist, which prevents modern browsers from leveraging newer features and optimizations, leading to performance inefficiencies.

Solution

Update react-fast-pdf so the PDFThumbnail component (and any other relevant parts of React-PDF) to dynamically load the appropriate pdf.worker.js build based on the environment.
Defaulting to the Modern Build: Use the modern pdf.worker.min.mjs file as the default worker for environments that support it.
Fallback to Legacy Build: Gracefully fallback to the legacy build only when necessary (e.g., for older browsers that lack support for modern JavaScript features).
This can be achieved by https://microsoft.github.io/rnx-kit/docs/tools/metro-serializer-esbuild or conditional code

Slack: https://expensify.slack.com/archives/C05LX9D6E07/p1734018163878969

Note: since we are not supporting Legacy browsers we can just use Modern Lib

Issue OwnerCurrent Issue Owner: @greg-schroeder
@melvin-bot melvin-bot bot added the Monthly KSv2 label Dec 16, 2024
@gedu
Copy link
Contributor Author

gedu commented Dec 16, 2024

Hey @mountiny, @rinej will be working on this

@mountiny mountiny self-assigned this Dec 18, 2024
@mountiny mountiny added the Bug Something is broken. Auto assigns a BugZero manager. label Dec 18, 2024
Copy link

melvin-bot bot commented Dec 18, 2024

Triggered auto assignment to @greg-schroeder (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@melvin-bot melvin-bot bot added Daily KSv2 and removed Monthly KSv2 labels Dec 18, 2024
@mountiny
Copy link
Contributor

@rinej can you please comment here?

@mountiny mountiny moved this to MEDIUM in [#whatsnext] #quality Dec 18, 2024
@mountiny mountiny moved this from MEDIUM to LOW in [#whatsnext] #quality Dec 18, 2024
@mountiny mountiny added Weekly KSv2 and removed Daily KSv2 labels Dec 18, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Weekly KSv2 labels Dec 18, 2024
@rinej
Copy link
Contributor

rinej commented Dec 18, 2024

Sure!
I created PRs:
In react-fast-pdf lib: Expensify/react-fast-pdf#40
In Exp App: #54250

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Dec 26, 2024
@melvin-bot melvin-bot bot changed the title Update react-fast-pdf to use modern pdfjs-dist lib [HOLD for payment 2025-01-02] Update react-fast-pdf to use modern pdfjs-dist lib Dec 26, 2024
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Dec 26, 2024
Copy link

melvin-bot bot commented Dec 26, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

Copy link

melvin-bot bot commented Dec 26, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.78-6 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2025-01-02. 🎊

For reference, here are some details about the assignees on this issue:

  • @rinej does not require payment (Contractor)

Copy link

melvin-bot bot commented Dec 26, 2024

@mountiny @greg-schroeder @rinej The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]

@mountiny
Copy link
Contributor

Payment for @sobitneupane

Can you please complete the checklist here? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Weekly KSv2
Projects
Development

No branches or pull requests

5 participants