Hi Barry,
Thank you so much for your detailed feedback.
I absolutely agree that simply postponing expensive operations to optimize the INP metric does not truly address the main issue.
The primary goal of deferring updates is to handle slow tasks that are beyond our control,
such as client-side route changes that result in significant DOM changes or even injecting new CSS.
As DOM updates, CSS updates and also client-side routing are often controlled by library code it can be hard to solve the problem properly.
Furthermore you're absolutely right that long tasks which slowing down the main thread for a long time without
breaks can have a negative impact on the INP of other components. Unfortunately we are facing tricky problems like lazy loading.
Let's consider a product recommender on a shop page that we choose to render later due to a slow backend or to optimize LCP.
The lazy loading can significantly slow down the browser, especially on smartphones, and negatively affect the INP value of other components.
Those cases are hard to reproduce and to track as slow INPs will not be attributed to the slow component but to the interaction target.
Do you have any tips how we could try to track this?
By default react fiber already tries to split slow updates automatically. Also the hook returns the information that it will take time to update.
Here is an example which adds visual feedback after each click:
Stackblitz DemoAlso note that I split the useEffect into three side effects - that way react is able to detect the long tasks and tries to schedule them accordingly.
I don't know if you can see it in the recording but I am double clicking and although the main thread gets blocked for 1200ms in total my INP is "only" 288ms:
@Michal thanks for your feedback!
Yes it's a little bit confusing that the custom hook uses the same api like the react transition hook.
It is also possible to make use of useTransition in the custom
useTransitionForINP.ts hook but as you already mentioned it won't split a synchronous react rendering.
Best
Jan