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

Request for useLayoutEffect for the web renderer #2433

Open
xpe opened this issue May 20, 2024 · 1 comment
Open

Request for useLayoutEffect for the web renderer #2433

xpe opened this issue May 20, 2024 · 1 comment
Labels
enhancement New feature or request hooks Changes to built-in hook package

Comments

@xpe
Copy link
Contributor

xpe commented May 20, 2024

Background

I'm building a prototype Dioxus web app using absolute positioning. There are many divs that need to know their dimensions to prevent overlaps. (You could imagine that I'm using a force-directed layout if it helps visualize what I'm doing, but I'm not actually using that particular layout algorithm.) For this application, it would be ideal to wait until layout finishes but before painting starts. React has useLayoutEffect. If Dioxus had this, it would seem like the ideal thing to use.

Feature Request

Please add useLayoutEffect for the web renderer for Dioxus.

@ealmloff ealmloff added enhancement New feature or request hooks Changes to built-in hook package labels May 20, 2024
@xpe
Copy link
Contributor Author

xpe commented May 21, 2024

BTW, this article is amazingly clear and useful : https://webperf.tips/tip/layout-thrashing/

Layout Thrashing and Forced Reflows

The browser's style and layout process (also known as reflow) is responsible for assigning visual styles and geometry to elements of a web application. It is one of the most expensive computational operations performed during the lifecycle of a web application, yet many web developers introduce code that forces it to run more often than it needs to!

When JavaScript codepaths force the browser to perform the reflow process outside of its usual cadence, it's called a forced reflow. When codepaths perform a forced reflow multiple times in quick succession within a frame, it's known as layout thrashing.

In this tip, we'll discuss forced reflows, layout thrashing, how to spot it in your application, as well as techniques for mitigating the performance impact.

Next, I'll quote some advice that probably transfers to Dioxus:

React Development

By using React you are not protected from Layout Thrashing. All web applications can abuse the browser's layout engine, even those written in modern web frameworks.

React's declarative syntax adds a layer of indirection into when the actual DOM mutations (and Layout invalidations) occur. This can make spotting Layout Thrashing harder when reading through code.

In my experience, Layout Thrashing occurs in useEffect hooks trying to measure DOM nodes or other React components. Typical use cases for performing this type of measuring include positioning a Tooltip or restoring Scroll Position.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hooks Changes to built-in hook package
Projects
None yet
Development

No branches or pull requests

2 participants