Comments (2)
I can reproduce that when dragging the scrollbar in your simplified codesandboxes, there is more visual lag for the boxes to appear in the createRoot version, like in your video.
In the createRoot version, I tried replacing the forceRender call with
flushSync(() => { // imported from react-dom
forceRender({});
});
which forces React to perform that one update synchronously and that seems to make it behave similarly to the ReactDOM.render call, which you may be able to use as a workaround. (For example, you can use flushSync even once ReactDOM.render is removed – although it may not be fully compatible with new features like the use() Hook.) Note that the state update is performed immediately and cannot be batched with any state updates enqueued after the flushSync call, so in your current setup you need to edit the ref beforehand, and you need to be careful that you don't have other scroll event handlers that might rerender the same grid (or measure layout in an effect) to avoid possible performance issues.
Internally in React, when you trigger an update within a scroll event, the update is assigned the ContinuousEventPriority level, which is mapped to UserBlockingPriority in our scheduler. Unlike some other event types like click
, React does not force this to flush immediately, the idea being that continuing to respond to other user interaction (if any occurs) is more important than rerendering based on a scroll
event. So React may return control to the browser (vs for a click
event it will finish rerendering even if it means causing the page to freeze for a sec). However in my testing the rerender is not coming close to hitting the deadline; I tried adding an effect to Grid that logs the current time for every render and generally one happens every 16ms.
@acdlite Do you have any other insight to share on why this lags or what to do? (Is there a supported way to opt into DiscreteEventPriority from a scroll event?)
from react.
I have the same problem. I used the Chrome performance profiler on my own simple sample and zoomed in on a single frame. The results confirm the theory that React is returning control to the browser after SetState is called. The browser paints before the render is scheduled. The end result is that while scrolling, the browser paints using the DOM rendered for the previous frame. When using react-window, the control goes blank when you scroll fast because each frame you've scrolled past all the content react-window rendered for the previous frame.
The entire sequence shown here takes less than 5ms. The rest of the frame is idle. I think the browser is coalescing input events until just before the paint is due, then raising the scroll event. At this point anything scheduled for a callback will run after the paint. It doesn't matter how quick the render is, because it doesn't start until after the paint has happened. The same thing will happen for updates triggered using requestAnimationFrame.
Would it be possible to start processing UserBlockingPriority tasks before returning control to the event loop, while still allowing them to be interrupted if it takes more than 5ms? This is in keeping with the philosophy of not blocking renders while allowing fast updates to complete before the browser paints.
from react.
Related Issues (20)
- Fix gap between footer logo and links HOT 16
- Source is not showing HOT 7
- Bug: Hydration error due to <button> HOT 6
- Bug: Search functionality not working correctly on react.dev in Safari on iOS real device (iPhone 12 Pro) HOT 2
- Bug:
- Google Translate causing "Text content does not match server-rendered HTML" HOT 1
- Bug: useFormState formAction becomes null in strict mode HOT 1
- Bug: Source is not showing in 5.0.2 HOT 9
- Question and suggest: The official identifier of Server Compnoent and Client Component HOT 3
- Bug: when installing the application, the old version of "react-scripts" is installed HOT 1
- Bug: Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. HOT 4
- Bug: optimistic state (useOptimistic) shows both optimistic and returned from server data when running several async actions HOT 6
- [DevTools Bug]: React Profiler reports higher hook numbers than shown in Components HOT 2
- about the react performance (how to improve it) HOT 3
- Bug: use() hook HOT 4
- Bug: Flight (RSC) examples are not accessible HOT 1
- useMemo reruns when the dependencies not changed when memoised value is a fn HOT 3
- Bug: [Flight] Async server components in `ai/rsc` not rendered correctly HOT 1
- Bug: React Dev tools extension showing wrong source file path on inspection HOT 4
- Bug: Using the hook useDeferredValue - Suspense fallback didn't show the contents HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.