Skip to content

UI crash when fail to load the document #2051

@ddtch

Description

@ddtch

Before you start - checklist

  • I followed instructions in documentation written for my React-PDF version
  • I have checked if this bug is not already reported
  • I have checked if an issue is not listed in Known issues
  • If I have a problem with PDF rendering, I checked if my PDF renders properly in PDF.js demo

Description

I have a problem in my Next.js app. Whenever a document fails to load with an error, for example 403 or 404, my whole UI crashes. Even though I have the error handlers.

<Document
            file={url}
            onLoadSuccess={onDocumentLoadSuccess}
            onLoadError={() => onFileLoadError?.()}
            options={options}
            externalLinkTarget="_blank"
            loading={<div className="text-center p-4">Loading PDF...</div>}
            error={<div>ERROR</div>}
          >
            {numPages && (
              <Page
                key={`page_${currentPage}`}
                pageNumber={currentPage}
                renderAnnotationLayer={false}
                renderTextLayer={true}
                scale={scale}
              />
            )}
          </Document>

Steps to reproduce

  1. import Document,
  2. assign loading url with error
  3. click preview

Expected behavior

I expect just to show to users error component.

Actual behavior

Whole application crashes.

Additional information

No response

Environment

  • Browser (if applicable):
  • React-PDF version:
  • React version:
  • Bundler name and version (if applicable):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions