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

TextLayerItem calculates element width incorrectly on component update #804

Closed
divpreet opened this issue Jul 5, 2021 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@divpreet
Copy link

divpreet commented Jul 5, 2021

Description

TextLayerItem calculates element width (actualWidth) incorrectly whenever componentDidUpdate is called. It uses element width after the transform: scaleX and sets the transform: scaleX to 1 because the targetWidth and actualWidth turn out to be the same. This causes the text layer to be incorrectly aligned to the canvas.

Steps to reproduce
Use Page with TextLayer enabled in a component that has state changes based on text selection.
On text selection, you will notice that the calculation happens again because of a re-render triggering the componentDidUpdate on TextLayerItem.

Expected behaviour

The calculation should exclude any transforms.

React-PDF version: 5.3.0

@wojtekmaj
Copy link
Owner

wojtekmaj commented Jul 9, 2021

I'm not able to reproduce this issue. Transforms are cleaned before TextLayerItem needs to recalculate them. Can you provide me with a CodeSandbox that shows the issue? TIA.

@divpreet
Copy link
Author

divpreet commented Jul 9, 2021

https://codesandbox.io/s/textlayeritem-re-render-v8vmw?file=/src/Child.js

Here is a very simplified implementation.

If you check the actual width calculation for a particular text node that happens the 2nd time (ie on a re-render), lets use the first span on the first page with text "Lorem Ipsum" for testing with the pdf attached (I generally use a conditional breakpoint with element.innerText.trim() === "Lorem Ipsum" on TextLayerItem line 141),
You will see, it calculates the width including the transform.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

@github-actions github-actions bot added the stale label Oct 11, 2021
@github-actions
Copy link
Contributor

This issue was closed because it has been stalled for 14 days with no activity.

@wojtekmaj wojtekmaj reopened this Oct 25, 2021
@wojtekmaj wojtekmaj removed the stale label Oct 25, 2021
@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 14 days.

@github-actions github-actions bot added the stale label Jan 24, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2022

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as completed Feb 7, 2022
@wojtekmaj wojtekmaj added bug Something isn't working fresh and removed stale labels Feb 9, 2022
@wojtekmaj wojtekmaj reopened this Feb 9, 2022
@wojtekmaj
Copy link
Owner

Resolved in #944

@wojtekmaj wojtekmaj removed the fresh label Jun 6, 2023
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