Upgrade react-pdf and migrate to ESM#51
Merged
roryabraham merged 2 commits intoExpensify:mainfrom Jan 20, 2026
Merged
Conversation
Open
16 tasks
roryabraham
approved these changes
Jan 20, 2026
| @@ -1,4 +1,4 @@ | |||
| import PDFPreviewer from './PDFPreviewer'; | |||
| import PDFPreviewer from './PDFPreviewer.js'; | |||
Contributor
There was a problem hiding this comment.
I was a bit skeptical of importing .js extensions directly in a .ts source, but this is actually the expected behavior for the current choice of TS configs:
compilerOptions: {
module: "nodenext",
moduleResolution: "nodenext",
}
This is a subtle distinction explained here.
We could support extensionless import by using moduleResolution: "bundler", but that would force that any consumer must use a bundler like webpack. Generally that would likely be fine, but there might be edge cases such as running the package in a Node.js server for SSR or running in a test runner. So it seems the current choice is actually the most portable, even if it feels a bit foreign. It's correct according to the official guidelines of TypeScript + Node.js
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
react-pdfto fix a crash that occurs when a PDF source changes before the previous PDF has finished loading:webpackto fix a crash when importingpdf.js:react-pdfhas dropped support for CommonJS and is now ESM-only.Related Issues
Expensify/App#76303
Manual Tests
Apply the following patch in E/App to make testing easier:
Diff
You may also need to update the source URLs to PDFs uploaded from your account.
Open a PDF viewer (attachment or receipt) and quickly click on the
Open different PDFbutton multiple times.Observe that the page crashes and the following error is printed in the console:
Cannot read properties of null (reading 'sendWithPromise').Run
npm i && npm run build && npm packon this PR to build the package.Install it in E/App using
npm pkg set overrides.webpack=^5.104.1 devDependencies.webpack=^5.104.1 && npm install ../react-fast-pdf/react-fast-pdf-1.0.30.tgz(you may need to adjust the path), and removeesm/from the path here.Repeat step 2 and verify that the page no longer crashes.
Linked PRs
Videos
Screen.Recording.2026-01-10.at.20.11.40.mov
Screen.Recording.2026-01-10.at.21.54.21.mov