Reconciliation is the process React uses to efficiently update the DOM by comparing changes in the Virtual DOM and only applying necessary updates to the real DOM.
Reconciliation Algorithms
- Stack Reconciliation (react < 16.8)
- Fiber Reconciliation (react >= 16.8)
Fiber Reconciliation
Why Fiber ?
- split work into chunks and prioritize tasks
- pause work and come back to it later
- reuse work or abort it if it's not needed
- Fiber is asynchronous (render phase)
2 phases
- render phase(asynchronous)
- commit phase(synchronous)
Works
- Fiber Root會維持兩個樹的結構(current, workInProgress)
- current(Browser上目前的樣子)
- 在背後的更新會在workInProgress上(render phase)
- 當workInProgress更新好後,進入commit phase
- Fiber Root會指向workInProgress並更新為current
- 原本的current就變為workInProgress