cyntler / react-doc-viewer

File viewer for React.
https://cyntler.github.io/react-doc-viewer
Apache License 2.0
372 stars 125 forks source link

No doc rerender while uploading a new one #283

Open ksalpern opened 1 month ago

ksalpern commented 1 month ago

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

zshnrg commented 1 month ago

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

SuperZ3 commented 1 month ago

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 }}>

rats4final commented 1 month ago

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