react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

[2.0]: 🐛 Hot/live reloading no longer working?

Open luskin opened this issue 4 years ago • 9 comments

Describe the bug Hot/live reloading doesn't appear to be working in v2.0. For example, setup an extremely simple PDFViewer:

export const App = (): JSX.Element => {
  return (
      <PDFViewer style={{ width: '100vw', height: '100vh', padding: 0, margin: 0 }}>
        <Document>
          <Page size="A4" style={styles.page}>
            <Text>Test</Text>
          </Page>
        </Document>
      </PDFViewer>
  )
}

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

  1. Run the most simple PDF you can
  2. Alter the text from Test to anything else...
  3. The page appears to update but the new text is not reloaded
  4. This used to work in the v1.X versions of this package

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: chrome
  • React-pdf version: v2.0.14

luskin avatar Jun 02 '21 18:06 luskin

Hey @luskin !

Alter the text from Test to anything else...

You mean making Text a state value and updating it real time? Or just alter Text on your code editor?

diegomura avatar Jun 03 '21 13:06 diegomura

Altering the value of the <Text> string children, i.e. <Text>Initial Text</Text> -> <Text>New Text</Text>

luskin avatar Jun 03 '21 17:06 luskin

To be clear, it's not just text, it's making any change anywhere inside the PDF generation React code... nothing triggers a re-render.

luskin avatar Jun 03 '21 19:06 luskin

I'm not sure exactly if this is something related to react-pdf to be honest 🤔 Hot-reloading is not something this lib offers, rather than something your projects has configured, and that depends directly from what bundler or app type you are running. For ex. I have a create-react-app project for dev purposes where hot-reloading is working fine. If you can provide a way to replicate it I'll try to take a look, but I don't think this qualifies as a bug

diegomura avatar Jun 05 '21 22:06 diegomura

That's a fair point @diegomura, it's a standard create-react-app project on our end as well so not sure where the problem exists. I'll work to getting this replicated in a project. What's weird is everything outside of react-pdf hot-reloads just fine, the only thing in the entire application that doesn't trigger a reload is anything within the PDF Rendered.

luskin avatar Jun 08 '21 17:06 luskin

Same problem here! I've also used create-react-app and have to refresh manually. Let me know if you figure it out!

einarpersson avatar Jun 17 '21 09:06 einarpersson

I'm encountering this issue with Gatsby as well.

sandren avatar Jul 11 '21 20:07 sandren

I'm experiencing this when <Document/> lives in a separate file from the renderer

DavidLemayian avatar Dec 09 '21 17:12 DavidLemayian

Experiencing this as well. @diegomura any tips on debugging this?

process0 avatar Aug 25 '22 21:08 process0

any solution ?

joacub avatar Oct 17 '22 19:10 joacub

there is not changes on this, is been difficult to make changes

joacub avatar Nov 09 '22 08:11 joacub

i have debuged this and found the issue, react-fast-refresh does not detect any compatible refresher and therefore is trigerring a full reload as a fallback but this full refresh have exactly the same components as the components updates are not compatible with and nothing is being refreshed.

This is a concept issue and have pretty dificult solution or at least i dont see any solution, as the reconcilier that react pdf should implement a refresher that only update the component that it is updated and this is not what this tool is doing today.

if you use the Whole Document in the same page all will work as react-refresh detects the changes in the parent and the renderer and will change everything but when is in the childs this will not work as this childs has no compatible renderer as i said already.

If the primitives changes to something that react udnerstand this i think will work.

joacub avatar Nov 12 '22 21:11 joacub

this is an example why this was working before:

https://github.com/diegomura/react-pdf/blob/v1.6.17/src/elements/View.js

in thatcode all elements have a render lifecicle so this will called everytime that react-refresh call this and the component is a regular react component that makes all the logic whe ncalled on new changes.

joacub avatar Nov 12 '22 21:11 joacub

is there any plan in having this working again or changing the lifecycle of the Primitives components. or making them as a normal components so the render can be called ??

joacub avatar Nov 12 '22 22:11 joacub