Skip to content
tezvyn:

Why is Fiber's render phase interruptible but commit is not?

Source: blog.ag-grid.comMediumHow cards are made

Why is Fiber's render phase interruptible but commit is not?
Summary

Knowledge that Fiber's render phase computes the workInProgress tree while commit applies side-effects.

Key points

Render calculates changes on invisible tree; commit runs DOM mutations and lifecycles synchronously.

What's really being asked

This question tests whether you understand the separation of concerns in the Fiber reconciliation algorithm between calculating changes and applying them. Specifically it checks if you know that React maintains a workInProgress tree during the render phase and only applies side-effects like DOM updates and lifecycle methods during the commit phase.

The full answer

Four things in order. First define the render phase as the work loop that traverses the fiber tree compares children updates props and builds out the workInProgress tree without touching the visible UI. Second define the commit phase as the stage where React flushes side-effects including pre-mutation lifecycle methods DOM mutations and post-mutation lifecycle methods like refs. Third explain that render is safe to interrupt because all work happens on the invisible workInProgress tree since no host environment mutations have occurred partial work can be discarded and restarted from the current tree. Fourth explain that commit is not safe to interrupt because it performs synchronous DOM updates and runs lifecycle methods that must complete atomically to keep the UI consistent with the internal state.

The mistakes people make

Saying that render mutates the DOM directly or that both phases can be interrupted. Another red flag is describing the render phase as only calling the render method without mentioning the work loop the comparison of children or the construction of the workInProgress tree. Claiming that commit is where React calculates props or diffs children is also incorrect because those activities belong to render.

What usually comes next

An interviewer might ask how the effects list is used to optimize the commit phase or what happens to the workInProgress tree after commit completes. They might also ask how Fiber handles different element types such as class components versus host components during the render phase or how the algorithm uses the linked list structure to enable the work loop to be broken into chunks.

A concrete example

Consider the sample ClickCounter component from the article. When setState increments count the render phase performs work by retrieving and comparing the children of ClickCounter updating props for the span element and building a workInProgress tree that reflects the new count value. None of this touches the browser DOM. Only during commit does React update the actual span text node and run any associated lifecycle methods which is why pausing mid-commit would leave the counter text partially updated and the component state inconsistent.

Interview question

What fundamental difference between Fiber's render and commit phases allows render to be interrupted but forces commit to run to completion?

  • a.Render constructs the workInProgress tree without host mutations, so partial work can be discarded, whereas commit flushes DOM updates and lifecycles that must remain atomic.Correct
  • b.Render performs calculations and DOM mutations on the invisible workInProgress tree, while commit only runs lifecycle methods and refs that must finish to keep state consistent.
  • c.Render only calls each component's render method to return elements, while commit diffs those elements, calculates prop updates, and applies them to the DOM.
  • d.Both phases could be interrupted without issues, but commit is synchronous to guarantee that refs and layout effects observe a fully consistent tree.
Why?

Render builds the workInProgress tree without any host environment side effects, so React can discard partial results and restart, whereas commit must atomically flush DOM mutations and lifecycles to prevent an inconsistent UI. Option C is tempting because it reflects an older virtual-DOM model, but Fiber performs child comparison and prop updates during render, not commit.

Just read this? Test yourself on what you have been reading.

Read the original → blog.ag-grid.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on react — each one lists the topics its interview covers.

See open roles