Skip to content

fix(Page): prevent crash when document fails to load#2090

Open
cyphercodes wants to merge 1 commit intowojtekmaj:mainfrom
cyphercodes:fix/page-crash-on-document-error
Open

fix(Page): prevent crash when document fails to load#2090
cyphercodes wants to merge 1 commit intowojtekmaj:mainfrom
cyphercodes:fix/page-crash-on-document-error

Conversation

@cyphercodes
Copy link
Copy Markdown

Description

When the Document component fails to load a PDF (e.g., 403 or 404 error), it sets pdf to false. The Page component was throwing an invariant error when pdf was false, causing the entire UI to crash even when error handlers were provided.

The Problem

Users reported that when a document fails to load with an error, the whole UI crashes even though they have error handlers in place:

<Document
  file={url}
  onLoadError={() => onFileLoadError?.()}
  error={<div>ERROR</div>}
>
  {numPages && (
    <Page pageNumber={currentPage} ... />
  )}
</Document>

The Fix

Changed the invariant check from:

invariant(pdf, '...')

to:

invariant(pdf !== null && pdf !== undefined, '...')

This allows pdf to be false (indicating a load error) and lets the renderContent() function handle it gracefully by showing the error message instead of throwing an error.

Changes

  • Modified the invariant check in Page.tsx to allow pdf === false
  • The existing error handling in renderContent() already handles pdf === false correctly

Fixes #2051

When the Document component fails to load a PDF, it sets pdf to false.
The Page component was throwing an invariant error when pdf was false,
causing the entire UI to crash even when error handlers were provided.

This change allows pdf to be false (indicating a load error) and lets
the renderContent() function handle it gracefully by showing the error
message instead of throwing.

Fixes wojtekmaj#2051
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI crash when fail to load the document

1 participant