danomatic / react-pdf-html

Render HTML in react-pdf
MIT License
162 stars 39 forks source link

TypeError: Cannot read properties of undefined (reading 'top') #99

Open Trev-Chumba opened 2 months ago

Trev-Chumba commented 2 months ago

I have a unique issue where locally the pdf and the library works fine however after deploying it to a particular server i get the above error. Specifically if its a table and needs to move to the next page. I have no clue as to why this only appears on the test apache server.

Ive tried this so far

 <View>
        <Html stylesheet={styleSheet} style={{ height: 'auto', top: 0 }}>
          {htmlData
            .replace(/<figure class="table"[^>]*>/g, '')
            .replace(/<\/figure>/g, '')
            .replace(/<figure[^>]*>/g, '')
            .replace(/vertical-align:[^;]+;/g, 'display: inline-block;')
            .replace(/rowspan/g, 'rowSpan')
            .replace(/windowtext/g, 'black')
            .replace(/height:\d+(\.\d+)?pt;/g, '')
            .replace(/<i>[^<]*<strong>[^<]*<\/strong>[^<]*<\/i>/g, (match) => {
              // Replace the combination with the Text component and custom styles
              return `<em>${match.replace(/<\/?i>/g, '').replace(/<\/?strong>/g, '')}</em>`;
            })}
        </Html>
      </View>

still nothing works The tables in question are 2tablesinHTML.txt

I have also raised this issue in the react-pdf/renderer github but this feels more like an issue with this library because the pdf works without the html data and no issues with page breaks on content written in the react-pdf/render without html data.

https://github.com/diegomura/react-pdf/issues/2804

please if you have any input i can try

analog-sombra commented 1 month ago

aah I am getting same problem still got no solution. image

danomatic commented 1 month ago

This seems at least partly to be an issue internal to the react-pdf library but I'm not sure what. react-pdf-html parses the text and passes down react-pdf elements. That should generally never cause an internal page break issue like that. Have you found any more clues?

Trev-Chumba commented 1 month ago

Honestly more confused but it gives the error only from a particular database but after Dropping the database and redoing the test again same data now it works.

Only glad it happened in the test server and not the real one because I still have no idea why that database was the issue or what's with that data that caused all this.