Loading content…
Loading content…
Understand React's internal Fiber architecture, reconciliation, render vs commit phases, and concurrent rendering
// A React Element is just a plain JS object!
{
type: 'button',
props: {
className: 'btn-primary',
children: 'Click me'
}
}
key prop.interface FiberNode {
type: any; // The component or HTML tag (e.g. 'div', Button)
key: null | string; // Unique key identifier
stateNode: any; // Reference to the actual DOM element or class instance
// Singly-linked list tree structure pointers
child: FiberNode; // Points to the first child
sibling: FiberNode; // Points to the next sibling
return: FiberNode; // Points to the parent fiber
memoizedState: any; // State currently rendered on the screen
updateQueue: any; // List of state changes waiting to be applied
}
React Fiber Reconciliation vs Commit PhaseCommon Pitfall
useEffect.import { useState, useTransition } from "react";
export const FilterList = ({ items }: { items: string[] }) => {
const [query, setQuery] = useState("");
const [filterText, setFilterText] = useState("");
const [isPending, startTransition] = useTransition();
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
// 1. Keep input response urgent!
setQuery(e.target.value);
// 2. Mark list filtering as low priority
startTransition(() => {
setFilterText(e.target.value);
});
};
const filteredItems = items.filter(item => item.includes(filterText));
return (
<div>
<input type="text" value={query} onChange={handleChange} placeholder="Search..." />
{isPending && <p className="text-gray-500">Loading list...</p>}
<ul>
{filteredItems.map(item => <li key={item}>{item}</li>)}
</ul>
</div>
);
};
import { useState, useDeferredValue } from "react";
import { BigList } from "./BigList";
export const SearchApp = () => {
const [query, setQuery] = useState("");
// Defer query updates for the heavy list rendering
const deferredQuery = useDeferredValue(query);
return (
<div>
<input value={query} onChange={e => setQuery(e.target.value)} />
{/* BigList will only re-render once browser is idle */}
<BigList query={deferredQuery} />
</div>
);
};
Senior Developer Wisdom
while (nextUnitOfWork !== null) { nextUnitOfWork = performUnitOfWork(nextUnitOfWork); }.
This allows React to inspect the nextUnitOfWork, check if the browser has remaining time in the current frame (using requestIdleCallback or scheduling libraries), and pause if necessary.Fiber Checklist
Marking it complete updates your roadmap progress percentage.