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

useMeasure dimensions out of sync in react18 #2522

Open
TaiyabAashir opened this issue Sep 22, 2023 · 2 comments
Open

useMeasure dimensions out of sync in react18 #2522

TaiyabAashir opened this issue Sep 22, 2023 · 2 comments

Comments

@TaiyabAashir
Copy link

TaiyabAashir commented Sep 22, 2023

React version: 18

Due to automatic batching in react18, state updates in useMeasure's ResizeObserver may be applied after paint. This can cause visual glitches if we depend on useMeasure dimensions for visual updates.

Same issue is raised in react: facebook/react#24331

They are recommending that state updates in ResizeObserver should be wrapped in flushSync from ReactDOM.

Can we do this in useMeasure or at least add optional support for flushSync in useMeasure. So that consumers can opt-in if they are using the dimensions for visual update(For eg. in useLayoutEffect).

Link to code example: https://codesandbox.io/s/amazing-montalcini-j6lz46?file=/src/App.js

@agusterodin
Copy link

This library is great and works with React 18 https://www.npmjs.com/package/react-use-measure

@TaiyabAashir
Copy link
Author

Not sure about this, since same issue is reported there: pmndrs/react-use-measure#93
@streamich

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