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

fix: replace useEffect with useLayoutEffect for React 17 #305

Merged
merged 2 commits into from
Feb 10, 2021

Conversation

mxschmitt
Copy link
Contributor

@mxschmitt mxschmitt commented Feb 9, 2021

useEffect cleanup runs since React 17 asynchronously thats why it needs to be changed

We deployed this change to a web application with quite a lot of users and could verify that the Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'. errors were gone.

Fixes #259

cc @Andarist

@changeset-bot
Copy link

changeset-bot bot commented Feb 9, 2021

🦋 Changeset detected

Latest commit: 37eed99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
react-textarea-autosize Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Owner

@Andarist Andarist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also move usage of the useWindowResizeListener to this branch of the code?

if (typeof document !== 'undefined') {

It will avoid React warnings about using useLayoutEffect during SSR.

`useEffect` cleanup runs since React 17 asynchronously thats why it needs to be changed
Fixes Andarist#259
@mxschmitt
Copy link
Contributor Author

@Andarist like that?

@Andarist Andarist merged commit 49d7d04 into Andarist:master Feb 10, 2021
@Andarist
Copy link
Owner

Thanks!

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

Successfully merging this pull request may close these issues.

Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
2 participants