react-doc-viewer icon indicating copy to clipboard operation
react-doc-viewer copied to clipboard

No doc rerender while uploading a new one

Open ksalpern opened this issue 1 year ago • 3 comments

Hey, thank you a lot for this lib, it made my life easier with PDFs!)

I had an issue in my app, I have input for PDF files. It work perfectly for the first time, but when I want to upload a new file, file name changes, file URL also changes but document preview itself doesn't change. I checked your Storybook with PDF input and as you can see, the same result here.

https://github.com/user-attachments/assets/223c71eb-7cd9-44e4-a6f4-4e9424c64159

ksalpern avatar Aug 01 '24 11:08 ksalpern

I have a similar issue but I experienced it when some documents that have been fetched want to be displayed according to user's choice, the pdf is not re-rendered. For my case, this solution can solve the issue by adding a key to DocViewer with a value of file name

Hope this solution can help in your case

zshnrg avatar Aug 05 '24 01:08 zshnrg

I found PDFRender use mainState from PDFProvider like this:

https://github.com/cyntler/react-doc-viewer/blob/bd5f92563f2e168c4cc1181546bb300bb18be5bc/src/renderers/pdf/components/pages/PDFPages.tsx#L13C1-L19C62

but in PDFProvider, it combines mainState with state only at initial time and not update any more:

https://github.com/cyntler/react-doc-viewer/blob/bd5f92563f2e168c4cc1181546bb300bb18be5bc/src/renderers/pdf/state/index.tsx#L26C3-L38C6

so i think we can update mainState either in useEffect or obtain it from PDFProvider like this <PDFContext.Provider value={{ state, dispatch, mainState }}>

SuperZ3 avatar Aug 05 '24 09:08 SuperZ3

@cyntler I would love to see a proper fix for this

rats4final avatar Aug 15 '24 08:08 rats4final