odoo / owl

OWL: A web framework for structured, dynamic and maintainable applications
https://odoo.github.io/owl/
Other
1.11k stars 334 forks source link

Is there has a hook like the useLayoutEffect in react? #1571

Closed ChaoqiYin closed 6 months ago

ChaoqiYin commented 7 months ago

Sometimes we need to do some extra styling, but at the same time we need to avoid page flickering。

sdegueldre commented 6 months ago

useEffect in owl is invoked synchronously after patching so effectively all effects are layout effects. However since rendering in owl is asynchronous, you can't schedule a render during an effect and expect it to be patched again before the animation frame. But if you do any imperative manipulation of the DOM in an effect/onPatched there will be no flickering.

We have been evaluating allowing scheduling synchronous render/patch cycles in effects but as this is a major breaking change it's unlikely to land without an upgrade in major version.

Closing this issue as resolved but of course feel free to ask clarifying questions on this issue.