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

window.getComputedStyle(this.target) wouldn't get correct width in iOS Safari sometimes #51

Closed
ke1vin4real opened this issue Jun 17, 2019 · 3 comments

Comments

@ke1vin4real
Copy link

ke1vin4real commented Jun 17, 2019

OS: iOS 12.3.1
Broswer: Safari
Library: "preact": "8.2.9", "react-lines-ellipsis": "0.14.1"
Code snippet:

componentDidMount() {
    window.setTimeout(() => {
      this.setState({ isMounted: true });
    }, 0)
}

...

render() {
    return (
      ...
      {isMounted && <LinesEllipsis {...props} />}
      ...
    );
}

The component wouldn't initialize properly sometimes.
In Android and PC broswer it works well.

Generally, window.getComputedStyle(this.target)would get an Object with property width width a certain value like 100px. But sometimes Safari would get a auto value of width in getComputedStyle(this.target), that led to no wrap in canvas and calcIndexes() got the wrong result of [0]. Not always, there's a chance that that would happen.

Could I get react-lines-ellipsis via cdn? I would provide a demo.

@ke1vin4real
Copy link
Author

I have tried .LinesEllipsis { width: 690px !important; } and set width in a inline style of parent Node.
It doesn't work

@ke1vin4real
Copy link
Author

ke1vin4real commented Jun 17, 2019

Oh, when I set a width in inlined style to parent node and use this.target.getBoundingClientRect().width in copyStyleToCanvas(), it will always get a certain correct width.
I believe there are some mechanisms in getComputedStyle when the component mounted.

@ke1vin4real ke1vin4real changed the title window.getComputedStyle(this.target) wouldn't get proper width in iOS Safari sometimes window.getComputedStyle(this.target) wouldn't get correct width in iOS Safari sometimes Jun 18, 2019
@xiaody
Copy link
Owner

xiaody commented May 20, 2024

Close due to inactivity.

@xiaody xiaody closed this as completed May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants