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

Pdf re-rendering the same url if provided file prop as an Object(httpHeaders Prop #1049

Closed
4 tasks done
andrewpradeep opened this issue Sep 9, 2022 · 1 comment
Closed
4 tasks done
Labels
duplicate This issue or pull request already exists question Further information is requested

Comments

@andrewpradeep
Copy link

andrewpradeep commented Sep 9, 2022

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

We were using the react-pdf component to render a pdf with "url" as string in "file" Prop . The issue started when we needed to included the "httpHeaders" in the file prop which changed the prop from "string" to "object". The component started re-rendering again and again even if the props were the same causing multiple api calls for the pdf

Steps to reproduce

  1. Use the react-pdf component inside an functional component(PARENT) which will re-render multiple times
  2. pass the "file" prop as an object "file= {url: example.com, httpHeaders: { iscached : false }}"
  3. Do not change the prop but observe that the document gets re-rendered and url gets called everytime the component (PARENT) re-renders

Expected behavior

Only single api call should have been made to the pdf file

Actual behavior

multiple api calls are made for the pdf even if props are unchanged

Additional information

image

most likely from this line

if (file !== prevProps.file) {

both objects are same in terms of value but the document gets loaded again, we can fix it if we use "JSON.stringify" to compare the "file" prop

Environment

  • Browser (if applicable): Chrome (Version 104.0.5112.101 (Official Build) (arm64))
  • React-PDF version: "4.2.0"
  • React version: "16.14.0"
  • Webpack version (if applicable): 4
@andrewpradeep andrewpradeep added the bug Something isn't working label Sep 9, 2022
@andrewpradeep andrewpradeep changed the title Pdf re-rendering the same url if provided file is an Object(httpHeaders Prop Pdf re-rendering the same url if provided file prop as an Object(httpHeaders Prop Sep 9, 2022
@wojtekmaj
Copy link
Owner

Duplicate of #308

@wojtekmaj wojtekmaj marked this as a duplicate of #308 Sep 13, 2022
@wojtekmaj wojtekmaj closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2022
@wojtekmaj wojtekmaj added duplicate This issue or pull request already exists question Further information is requested and removed bug Something isn't working labels Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants