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

customTextRenderer not working correctly in v6 #1151

Closed
4 tasks done
paescuj opened this issue Nov 9, 2022 · 3 comments
Closed
4 tasks done

customTextRenderer not working correctly in v6 #1151

paescuj opened this issue Nov 9, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@paescuj
Copy link
Contributor

paescuj commented Nov 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

The customTextRenderer doesn't seem to work correctly anymore in v6.

If a customTextRenderer is defined (even with the example provided under Page -> Props) the text elements are wrongly positioned and there are a lot elements with the content undefined:

<span style="left: 101.687px; top: 100.54px; font-size: 2.16834px; font-family: sans-serif;" role="presentation" dir="ltr">undefined</span>

If the customTextRenderer is removed, everything works as expected and the text elements are correctly positioned.

Steps to reproduce

  1. Configure custom rendered:
<Page
  customTextRenderer={
    ({ str, itemIndex }) => {
      return `<mark>${str}</mark>`;
    }
  }
  ...
/>
  1. Check page and inspect elements

Expected behavior

Text elements via custom rendered should be positioned correctly and not include undefined values

Actual behavior

Text elements are wrongly positioned (clearly visible when using <mark>) and contains undefined values

Additional information

No response

Environment

  • Browser (if applicable): Firefox 106.0.5
  • React-PDF version: 6.0.2
  • React version: 18.2.0
  • Webpack version (if applicable): -
@paescuj paescuj added the bug Something isn't working label Nov 9, 2022
@wojtekmaj
Copy link
Owner

"not working" is a bit of an overstatement, but yes, the example provided wasn't very good and lacked a null check which was not necessary in React before. Fixed that. :)

@paescuj
Copy link
Contributor Author

paescuj commented Nov 10, 2022

"not working" is a bit of an overstatement [...]

I agree and I'd like to apologize for the way I expressed myself!

[...] but yes, the example provided wasn't very good and lacked a null check which was not necessary in React before. Fixed that. :)

Thank you for your quick response and also thank you for maintaining this awesome package ❤️

Unfortunately, I still think that the customTextRenderer functionality is not working "correctly" in v6.
I just submitted #1152 to make this better visible.

If the custom text renderer is activated, there are a lot of these elements with the value undefined:

Screenshot 2022-11-10 at 09 57 51

If the the custom text renderer is disabled, no such elements will show up:

Screenshot 2022-11-10 at 09 57 33

You will also notice that without the custom text renderer, the text is perfectly selectable (whole line):

Screenshot 2022-11-10 at 09 58 28

Whereas with the custom text renderer, it is not (this used to work pre-v6):

Screenshot 2022-11-10 at 09 58 16

@wojtekmaj
Copy link
Owner

Yup, that is a valid bug - thank you for noticing this!

@wojtekmaj wojtekmaj reopened this Nov 10, 2022
wojtekmaj added a commit that referenced this issue Nov 10, 2022
@paescuj paescuj changed the title customTextRenderer not working in v6 customTextRenderer not working correctly in v6 Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants