Genie React

Why did this React component re-render? Get the exact prop, hook, or context

One sidebar click re-rendered 35 components in a React 19 dashboard. Genie named the hook, prop, context and parent behind each render, and verify proved the fix.

Open a Genie window, do the interaction once, and run react_render_causes. It lists every render with the input that caused it, such as a changed prop, a state hook, a context value or a parent render, and grades each cause exact, inferred or unknown.

This page follows one real bug in apps/realworld-dashboard, a Vite and React 19 app in this repo with seeded bugs. Your agent drives the page with agent-browser and asks Genie what React did. Every output below comes from one run of Genie 1.1.0 on November 19, 2026, trimmed to selected fields. The full log is in the evidence file.

Collapsing the sidebar re-renders the stat cards

On the dashboard, click Collapse sidebar. Only the sidebar changes on screen. Genie sees more. The output is trimmed to 9 of its 35 rows:

npx genie-react call react_clear_renders '{}' --session upd-e
agent-browser --session upd-e find role button click --name 'Collapse sidebar'
npx genie-react call devtools_wait '{"condition":"settled","domains":["react","query","router"],"timeoutMs":10000}' --fail-on-result-error --session upd-e
npx genie-react call react_get_renders '{"limit":40}' --session upd-e --fields name,renders,necessity,necessityReason
[35]:
  each: {renders:1}
  - {name:AppShell,necessity:necessary,necessityReason:dom-changed}
  - {name:PreferencesProvider,necessity:necessary,necessityReason:dom-changed}
  - {name:SidebarNav,necessity:necessary,necessityReason:dom-changed}
  - {name:TopBar,necessity:unnecessary,necessityReason:inputs-unchanged}
  - {name:UserMenu,necessity:unknown,necessityReason:callbacks-changed}
  - {name:StatCard,necessity:unnecessary,necessityReason:output-unchanged}
  - {name:StatCard,necessity:unnecessary,necessityReason:output-unchanged}
  - {name:StatCard,necessity:unnecessary,necessityReason:output-unchanged}
  - {name:StatCard,necessity:unnecessary,necessityReason:output-unchanged}

The same read with "limit":200 also returned 35 rows. One click rendered 35 app components. The four StatCard components are wrapped in memo and show revenue and order numbers that did not change. Genie 1.0.2 also listed the sidebar's six TanStack Router Link elements under the name sidebar-nav.tsx, for 41 rows, and 1.1.0 hides them as library code.

One read names four kinds of cause

npx genie-react call react_render_causes '{"limit":100}' --session upd-e

Trimmed to five of the 35 events:

  AppShell #7787564236851 {…,necessity:necessary,necessityReason:dom-changed,…,source:{location:/src/routes/_app.tsx:21:9,ownership:app}}
    ← state exact "state[0]"
  PreferencesProvider #7787564236852 {…,source:{location:/src/layout/app-shell.tsx:36:5,ownership:app}}
    ← parent inferred AppShell
    ← children exact
  SidebarNav #7787564236855 {…,source:{location:/src/layout/app-shell.tsx:38:9,ownership:app}}
    ← parent inferred PreferencesProvider {origin:AppShell}
    ← props exact collapsed
  TopBar #7787564236857 {…,necessity:unnecessary,necessityReason:inputs-unchanged,…}
    ← parent inferred PreferencesProvider {origin:AppShell}
  StatCard #7787564237028 {…,necessity:unnecessary,necessityReason:output-unchanged,…,source:{location:/src/features/dashboard/dashboard-page.tsx:55:9,ownership:app}}
    ← context exact "Context(PreferencesProvider)" {contextIndex:0}

Each ← line is one cause: its kind, its grade and its name. AppShell rendered because its first useState changed. That hook holds collapsed. SidebarNav rendered because its collapsed prop changed. TopBar had no input change and rendered because its parent did. Its origin names AppShell as the component whose own update started the cascade.

The StatCard line is the bug. It rendered because the value of the context that PreferencesProvider provides changed. Nine renders in this click carry that cause: the four StatCards, UserMenu, NotificationsDrawer and three dashboard cards.

A context value rebuilt on every render

The full view shows what changed inside the context value:

npx genie-react call react_render_causes '{"component":"StatCard","limit":1,"view":"full"}' --session upd-e
    ← context exact "Context(PreferencesProvider)" {contextIndex:0,contextId:context:1,provider:{componentId:7787564236852,componentName:PreferencesProvider},…,deepDiff:{changes:[{kind:identity-changed-uninspected,path:/setTheme},{kind:identity-changed-uninspected,path:/setLocale}],visited:13,truncated:true}}

Theme, locale and the formatters kept their values. Only setTheme and setLocale are new functions. PreferencesProvider sits inside AppShell, so the sidebar state change re-renders it, and it builds both functions and the value object again:

apps/realworld-dashboard/src/app/preferences.tsx
const setTheme = (next: Theme) => {
  window.localStorage.setItem(THEME_KEY, next)
  setThemeState(next)
}
// setLocale is built the same way.

const value: PreferencesContextValue = {
  ...formatters,
  theme,
  resolvedTheme,
  locale,
  setTheme,
  setLocale,
}

A new value object makes every usePreferences() consumer render. A memoized component still re-renders when a context it uses changes.

The fix keeps the value stable

This is the reference fix from the app's answer key. It was applied for the "after" run and then reverted, so the bug stays in the repo for other runs:

-  const setTheme = (next: Theme) => {
+  const setTheme = useCallback((next: Theme) => {
     window.localStorage.setItem(THEME_KEY, next)
     setThemeState(next)
-  }
-  const setLocale = (next: Locale) => {
+  }, [])
+  const setLocale = useCallback((next: Locale) => {
     window.localStorage.setItem(LOCALE_KEY, next)
     setLocaleState(next)
-  }
+  }, [])

-  const value: PreferencesContextValue = {
-    ...formatters,
-    theme,
-    resolvedTheme,
-    locale,
-    setTheme,
-    setLocale,
-  }
+  const value = useMemo<PreferencesContextValue>(
+    () => ({ ...formatters, theme, resolvedTheme, locale, setTheme, setLocale }),
+    [formatters, theme, resolvedTheme, locale, setTheme, setLocale],
+  )

The import line also gains useCallback.

Verify proves the fix

verify turns the finding into claims with an exit code. StatCard must not render, and SidebarNav must render at least once, so a click that missed the app fails:

npx genie-react verify begin --session upd-e --name 'collapse the sidebar' \
  --claim 'render StatCard max 0' --claim 'render SidebarNav min 1'
agent-browser --session upd-e find role button click --name 'Collapse sidebar'
npx genie-react verify end vfy_0114ae9d-1582-4057-99ea-f8ee11707ed8 --session upd-e

Before the fix, trimmed to the verdict and claim lines. The command exited with code 1:

fail vfy_0114ae9d-1582-4057-99ea-f8ee11707ed8 "collapse the sidebar"  1 commit, quiet after 1850 ms (react, query, router, network)
  1 fail render StatCard max 0  {renders:4,mounts:0,updates:4,remounts:0,semantics:exact,instances:4,activeInstances:4}
  2 pass render SidebarNav min 1  {renders:1,mounts:0,updates:1,remounts:0,semantics:exact,instances:1,activeInstances:1}

After the fix, the same claims and the same click. The command exited with code 0:

pass vfy_ffa99a24-d409-4586-bdbd-33356400cf85 "collapse the sidebar"  1 commit, quiet after 871 ms (react, query, router, network)
  1 pass render StatCard max 0  {renders:0,mounts:0,updates:0,remounts:0,semantics:exact,instances:4,activeInstances:4}
  2 pass render SidebarNav min 1  {renders:1,mounts:0,updates:1,remounts:0,semantics:exact,instances:1,activeInstances:1}

A fresh react_get_renders capture of the same click after the fix listed 10 renders instead of 35. Its only coverage gap was one component with unresolved ownership, and the same read with "appOnly":false reported complete: true with semantics: exact.

What exact, inferred and unknown mean in practice

exact means Genie saw the link directly. In the run above, it saw the state slot change, the collapsed prop change and the context value change, and it named the provider. Act on an exact cause.

A deferred render is exact too. Typing one character into Filter orders rendered OrdersPage twice:

  OrdersPage #8002295824437 {renderEventId:render:19:34,…,necessity:necessary,necessityReason:dom-changed,…}
    ← state exact useDeferredValue
  OrdersPage #8002295824437 {renderEventId:render:18:2,…,necessity:necessary,necessityReason:dom-changed,…}
    ← state exact "state[0]"

The earlier render, render:18:2, came from the term state. The second is React's deferred render for useDeferredValue(term). The full view gives its values and its hook:

    ← state exact useDeferredValue {before:"",after:x,…,hook:{index:10,stateIndex:null,kind:state}}

Genie 1.0.2 graded this deferred render unknown with unclassified-hook-changed. Genie needs a React development build to name the hook.

inferred means the link is likely but not proven. The parent causes above are inferred. Here is a second kind. On the Orders page, ticking one order's checkbox also rendered SidebarNav:

  SidebarNav #7017070592042 {…,necessity:unnecessary,necessityReason:output-unchanged,inputEvidence:none-observed,…}
    ← external-store inferred anonymous-external-store {changedFields:[selectedOrderIds]}

The default view names the store field that changed. The full view adds subscriptionFired:true and selector:null. SidebarNav does not show the selection, so confirm the lead in the code. src/layout/sidebar-nav.tsx calls useWorkspaceStore() without a selector, so it subscribes to the whole zustand store. That is another seeded bug in the same app.

unknown means Genie saw a render but cannot name its cause. This run had none. Every render in the sidebar, checkbox and filter captures carried an exact or inferred cause. When you do see one, read the cause's reason and the capture's coverage before you guess.

When this approach does not fit

Read coverage before you trust a missing cause. The sidebar capture reported complete: false with inputs-truncated on 9 fibers, because Genie compares functions by identity and does not look inside them. Causes it did report were still graded, but an absent cause proves nothing until coverage is complete. A budget that runs out drops renders from the read entirely. The same click in a window with fiberLimit:50, operationLimit:1000 and adaptive:false listed 3 events instead of 35, with skippedCommitFibers: 67, semantics: lower-bound and a budgetAdvice to clear with. Read evidence lists every gap and its fix.

necessity is not permission to delete a render. The full StatCard event says optimizationSafety: not-proven-safe, so check the screen with your driver after any change.

Render causes explain why React rendered, not how long it took. For time, use the timeline and repeated captures in Optimize a slow interaction. Genie needs a React 18 or newer development build. To lock in a fix, see Verify a fix.

On this page