r/reactjs • • Aug 31 '26

Needs Help What does "rendering in background" in startTransition really mean?

So far, I understand that wrapping a function with startTransition tells React to treat it as a non‑urgent update. So if any urgent action occurs, React can respond to it immediately without blocking.

But here is where I got stuck. The docs say:

“useTransition is a React Hook that lets you render a part of the UI in the background.”

“The function passed to startTransition is called the Action. You can update state and (optionally) perform side effects within an Action, and the work will be done in the background without blocking user interactions.”

I don’t really get what “in the background” really means.

Looking at the example, I don’t understand why, with startTransition, the “Total” only renders once with the final "Total" after clicking “quantity” multiple times, instead of updating multiple times according to the number of times the “quantity” was clicked

Does “run in background” prevent multiple renders and only show the final result??

25 Upvotes

16 comments sorted by

View all comments

Show parent comment

1

u/Neat_Living_6765 Sep 01 '26

Could you add two console.log as below and run the code without StrictMode.

Increment quantity to 3 by clicking twice quickly. Below is the log I observed:

quantity: 1   // initial render
(2) quantity: 1   // rendered twice because setClientQuantity(newQuantity) was called twice due to double clicks
async done: 3   // setQuantity(3) is scheduled
quantity: 1 => ???   // I don’t understand why it logs 1 here
async done: 2   // setQuantity(2) is scheduled, so the render with quantity 3 is abandoned
quantity: 1 => ???   // again, I don’t understand why it logs 1 here
quantity: 2
===============
What I expected:
quantity:  1 
(2) quantity:  1 
async done:  3 
async done:  2
quantity:  2



export default function App() {
  const [quantity, setQuantity] = useState(1);
  const [isPending, startTransition] = useTransition();
  const [clientQuantity, setClientQuantity] = useState(1);

  console.log("quantity: ", quantity);

  const updateQuantityAction = (newQuantity) => {
    setClientQuantity(newQuantity);

    startTransition(async () => {
      const savedQuantity = await updateQuantity(newQuantity);
      startTransition(() => {
        console.log("async done: ", savedQuantity);
        setQuantity(savedQuantity);
      });
    });
  };

2

u/Tomus Sep 01 '26

Don't trust console.logs absolutely, just because something ran doesn't mean React actually flushed the update and rendered to the screen.

The easiest way to inspect what's going on is looking at Chrome devtools filmstrip view (it will show you very fast paints that you may miss with the your eyes) and React devtools timeline view.

Feel free to share a full code snippet (eg. stackblitz link) and I'll try to explain what's going on.

1

u/Neat_Living_6765 Sep 01 '26

Yes, actually, I used the Profiler and recorded the action when I increased the quantity to 3. Apart from the initial render, it showed two renders, as expected.

It’s just that whenever I notice something unusual in the console log, or even come across a term in the docs like “background,” my mind can’t stop thinking about it 😅😅

I’d appreciate it if you could explain why I shouldn’t completely trust the console log. I’ve never heard anyone say that before