Sub topic 10
Limitations and Common Pitfalls
This chapter assumes you know useTransition, startTransition and useDeferredValue from the earlier chapters. It also assumes you are comfortable with useState, React.memo and the idea that React re-renders children when a parent renders. Transitions are easy to add and easy to get wrong without seeing an error. Each pitfall below fails silently: the app runs, but the UI is still slow.
A transition makes rendering interruptible, not faster
A transition does not reduce the work React does. It lets React pause the slow render when an urgent update arrives, then restart it afterward. If a single component takes 300 ms to render, the browser still cannot respond while that component renders. Fix the cost with memoization, smaller component trees or virtualization. Use transitions to keep the rest of the UI responsive while that work happens.
Controlled inputs cannot be transitions
A controlled input must show the typed character in the same frame. If you put its state setter inside startTransition, React treats the update as non-urgent and the input lags or drops characters. Keep two state values instead: one urgent value for the input and one transition value for the expensive part.
import { useState, useTransition } from 'react';
function Search({ items }) {
const [text, setText] = useState('');
const [filter, setFilter] = useState('');
const [, startTransition] = useTransition();
function handleChange(e) {
const value = e.target.value;
setText(value); // urgent: the input stays in sync
startTransition(() => {
setFilter(value); // non-urgent: the list may lag behind
});
}
const shown = items.filter((item) => item.includes(filter));
return (
<>
<input value={text} onChange={handleChange} />
<ul>
{shown.map((item) => (
<li key={item}>{item}</li>
))}
</ul>
</>
);
}Only updates called synchronously are marked
React marks a state update as a transition only if the setter runs while the startTransition callback is executing. An update scheduled later is a normal urgent update.
import { useState, useTransition } from 'react';
function Page() {
const [tab, setTab] = useState('home');
const [isPending, startTransition] = useTransition();
function wrong(next) {
startTransition(() => {
// Runs after the callback returns, so this is NOT a transition.
setTimeout(() => setTab(next), 100);
});
}
function right(next) {
setTimeout(() => {
startTransition(() => {
setTab(next);
});
}, 100);
}
return (
<div style={{ opacity: isPending ? 0.6 : 1 }}>
<button onClick={() => wrong('a')}>Wrong</button>
<button onClick={() => right('b')}>Right</button>
<p>Current tab: {tab}</p>
</div>
);
}The same rule applies after an await. In React 18, the callback must be synchronous. In React 19 it can be async, but any setter called after an await needs its own startTransition, as shown in the async transitions chapter.
Other limits to remember
- External stores: Updates from stores read with
useSyncExternalStorealways render synchronously. A transition cannot defer them. - Pending flag scope:
isPendingfromuseTransitionistruewhile any transition started by that hook is in progress. Components that need a flag for a different transition need their own hook. - No
isPendingoutside components: The standalonestartTransitionimport works anywhere, such as in a data library, but gives you no pending flag. - Several transitions: If a newer transition updates the same state before an older one finishes, React may abandon the old render. Do not rely on every intermediate value being shown.
- Suspended content: If a transition suspends on content that is not yet visible, React keeps the old UI instead of showing a fallback. If the content never resolves, the user sees the old UI for a long time. Always give a way out, such as an error boundary.
Deferred value pitfalls
useDeferredValue compares values with Object.is. If you pass a new object or array created during render, the deferred value looks different on every render, so React keeps scheduling background work. Pass primitives, or objects created outside render or memoized with useMemo.
The deferred value also does nothing unless the slow child skips re-rendering for the old value. Wrap that child in memo, or the urgent render will still do all the slow work. A deferred value is also not a delay. It has no timer, and it updates as soon as React has time, so it does not reduce the number of network requests the way debouncing does.
Exercise
A developer writes startTransition(() => { setQuery(e.target.value); }) for a controlled text input, and typing feels worse than before. What is wrong, and how do you fix it?
Show answer
The input's own state is now a non-urgent update, so React may delay or interrupt it and the input lags. Keep an urgent state for the input value (setText) and move only the expensive derived state (such as setFilter) into startTransition.
Exercise
You call useDeferredValue(items.filter(isVisible)) in a component and the slow child still re-renders on every keystroke. Give two possible causes.
Show answer
The filtered array is a new reference on every render, so the deferred value always looks changed. Compute it with useMemo, or defer the primitive value and filter inside the child. Also, the slow child may not be wrapped in memo, so it re-renders for every parent render.