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

Unable to find Document context while using Thumbnail with a "pdf" property. #1732

Closed
4 tasks done
denyskotsur opened this issue Feb 21, 2024 · 1 comment
Closed
4 tasks done
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@denyskotsur
Copy link

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 the components structured like this (just posted the main idea):

import { Document, Page, Thumbnail } from "react-pdf";

const PDFMain = () => {
  const file = "...somebase64";
  const [pdf, setPDF] = useState(null);

  return (
    <>
      {pdf && <Thumbnail pageNumber={1} pdf={pdf} />}

      <Document
        file={`${PDF_BASE_64_MIME_PREFIX}${file}`}
        onLoadSuccess={documentLoadHandler}
      >
        <Page
          ...other props
          onLoadSuccess={setPDF}
          renderAnnotationLayer={false}
          renderTextLayer={false}
        />
      </Document>
    </>
  );
};

I receive an error, even if a pdf exists and is marked as a PDFDocumentProxy.

Uncaught Error: Invariant failed: Unable to find Document context. Did you wrap <Page /> in <Document />?
image

According to the description, I can provide the object to make it work without wrapping it into another Document layer.

image

How can it be resolved? What can I do incorrectly?

Click here to find a link to devbox to check by yourself

Thanks!

Steps to reproduce

  1. Load the document and save the PDFProxyDocument object to a local state.
  2. Pass the saved object to the Thumbnail component, which is placed outside of the initial Document and which is not wrapped by another Document component.
  3. Thumbnails are not loading.

Expected behavior

Thumbnails should appear and read the data from the passed PDFProxyDocument object.

Actual behavior

App crashes because of the error Uncaught Error: Invariant failed: Unable to find Document context. Did you wrap <Page /> in <Document />?

Additional information

No response

Environment

  • React-PDF version: 7.7.0
  • React version: 18.2.0
@denyskotsur denyskotsur added the bug Something isn't working label Feb 21, 2024
@denyskotsur denyskotsur changed the title Unable to find Document context while using Thumbnail with a pdf property. Unable to find Document context while using Thumbnail with a "pdf" property. Feb 21, 2024
@wojtekmaj
Copy link
Owner

Duplicate of #1709

@wojtekmaj wojtekmaj marked this as a duplicate of #1709 Feb 21, 2024
@wojtekmaj wojtekmaj closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
@wojtekmaj wojtekmaj added the duplicate This issue or pull request already exists label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants