Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does React split DOM updates and browser paints?

Tags:

reactjs

This is the sequence of tasks as I understand:

  1. render,
  2. reconcile,
  3. update DOM,
  4. call layout effects
  5. browser paint
  6. call effects

When I make a change to the DOM like titleRef.current.innerText = 'Hello', the change seems to instantaneous on the browser. There seems to be no difference between a DOM update and a browser paint.

So, how does React split a DOM update from a browser paint? Looked at the source code but could not understand much.

like image 227
vijayst Avatar asked Sep 06 '25 03:09

vijayst


1 Answers

Here is the lifecycle of a react component:

  1. Run lazy initializers
  2. Run rest of the code other than hooks.
  3. Create or update virtual dom (here the virtual dom is updated)
  4. cleanup of useLayouteffect (unmount stage)
  5. useLayoutEffect().
  6. Browser paints the screen (real dom is updated)
  7. cleanup of useEffect (unmount stage)
  8. useEffect(). enter image description here

FlowChart Link: https://github.com/donavon/hook-flow

like image 164
Gilbish Kosma Avatar answered Sep 07 '25 21:09

Gilbish Kosma