← reports

#6542 · Sidebar context updates invalidate unrelated row consumers

BugPriority: MediumEffort: Mediumui · perf · partial-reproIssue2026-10-29 · base 3bacfac9ed69d42392076e5b3da2815bec822cd8

PARTIALLY REPRODUCED · Root-cause confidence: high for the two context invalidation paths.

1. TL;DR

Two real sidebar contexts notify rows whose data has not changed. In a twelve-consumer reproduction, three edits to one title caused 33 unrelated consumer renders, while changing the selected thread caused all twelve action consumers to render. Both results repeated in a second clean checkout of trusted main. These tests exercise the production providers and hooks, but do not measure browser paints, complete row components, or user-perceived latency. The command-palette latency and the issue's exact timing claims remain unverified, so the overall verdict is partial.

2. Claims vs findings

ClaimStatusEvidence and limit
A selection change invalidates unrelated rows.Verified at the context boundaryWith stable child elements and memoized consumers, changing only selectedThreadId rendered all twelve consumers; ten belonged to neither the old nor new selection. This is not a live mouse-click/paint measurement.
Each rename keystroke invalidates unrelated rows.Verified at the provider/hook boundaryThree real input change events caused three active-consumer renders and 33 unrelated-consumer renders. The editor displayed the final name correctly.
Visible search input lags with many threads; a particular fix gives a specific speedup.UnverifiedNo browser typing trace or timing comparison was performed. Static inspection finds local row building on the raw query, but the server-search hook already debounces requests.
The problem remains on main.Verified for context fan-outBoth checks used origin/main commit 3bacfac9ed69d42392076e5b3da2815bec822cd8; a later fetch found no newer changes in the relevant paths.
No related issue exists.Not establishedRelated sidebar scalability and rendering reports exist; none was established as an exact duplicate.

3. Environment

4. Minimal reproduction

  1. Clone the trusted repository, detach at the recorded commit, and build its existing dependencies:
    git clone --single-branch --branch main https://github.com/get-bb/bb.git /tmp/issue-6542-check-a
    cd /tmp/issue-6542-check-a
    git checkout --detach 3bacfac9ed69d42392076e5b3da2815bec822cd8
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Save the complete test below as plugins/thread-list/app/list/issue6542.repro.test.tsx. It was written from trusted repository evidence, not copied from the issue or linked branch.
  3. Run the focused probe. A nonzero exit is the expected reproduction result:
    pnpm exec turbo run test --filter=bb-plugin-thread-list -- app/list/issue6542.repro.test.tsx

Expected: the final edited value is New, twelve action buttons remain present, and unrelated consumers render zero times. Actual diagnostic output, identical in both checkouts:

{"probe":"rename","edits":3,"activeRenders":3,"unrelatedRenders":33}
{"probe":"selection","rowsRendered":12,"unrelatedRenders":10}
AssertionError: expected 33 to be +0 // Object.is equality
AssertionError: expected 10 to be +0 // Object.is equality
Test Files  1 failed (1)
     Tests  2 failed (2)

The tests count function renders after mount and after entering edit mode, not DOM mutations, browser paint events, or elapsed time. The two diagnostic assertions fail only after the editor-value and button-count checks pass. They deliberately use memoized consumers and stable children to exclude parent-prop churn.

Complete reproduction test

// @vitest-environment jsdom

import { memo } from "react";
import { Provider, createStore } from "jotai";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, expect, it } from "vitest";
import { installTestPluginRuntime } from "@get-bb/plugin-sdk/testing/app";
import {
  SidebarRenameProvider,
  useSidebarRename,
} from "../rows/SidebarInlineRename.js";
import { useCustomizeThreadRowActions } from "./customizeRowActionsContext.js";

installTestPluginRuntime();
const { ThreadListVisibility } = await import("./ThreadListVisibility.js");

afterEach(cleanup);

const rowIds = Array.from({ length: 12 }, (_, index) => `row-${index}`);
const saveName = async () => undefined;

it("keeps unrelated rename consumers idle while another row's draft changes", () => {
  const renders = new Map<string, number>();
  const Row = memo(function Row({ id }: { id: string }) {
    renders.set(id, (renders.get(id) ?? 0) + 1);
    const rename = useSidebarRename({
      id,
      kind: "thread",
      name: "Initial",
      label: `${id} title`,
      ownerKey: id,
      onSave: saveName,
    });
    return (
      <div>
        <button onClick={rename.startEditing}>Edit {id}</button>
        {rename.editor}
      </div>
    );
  });
  render(
    <SidebarRenameProvider>
      {rowIds.map((id) => (
        <Row key={id} id={id} />
      ))}
    </SidebarRenameProvider>,
  );
  fireEvent.click(screen.getByRole("button", { name: "Edit row-0" }));
  const input = screen.getByRole("textbox", { name: "row-0 title" });
  renders.clear();
  for (const value of ["N", "Ne", "New"]) {
    fireEvent.change(input, { target: { value } });
  }
  const unrelatedRenders = rowIds
    .slice(1)
    .reduce((total, id) => total + (renders.get(id) ?? 0), 0);
  console.log(
    JSON.stringify({
      probe: "rename",
      edits: 3,
      activeRenders: renders.get("row-0"),
      unrelatedRenders,
    }),
  );
  expect(input.getAttribute("value")).toBe("New");
  expect(unrelatedRenders).toBe(0);
});

it("keeps unchanged action consumers idle when the selected thread changes", () => {
  const renders = new Map<string, number>();
  const Row = memo(function Row({ id }: { id: string }) {
    renders.set(id, (renders.get(id) ?? 0) + 1);
    const customize = useCustomizeThreadRowActions();
    return <button onClick={() => customize?.(id)}>Actions {id}</button>;
  });
  const children = rowIds.map((id) => <Row key={id} id={id} />);
  const store = createStore();
  const groups: never[] = [];
  const order: never[] = [];
  const onOrderChange = () => undefined;
  function List({ selectedThreadId }: { selectedThreadId: string }) {
    return (
      <Provider store={store}>
        <ThreadListVisibility
          groups={groups}
          order={order}
          onOrderChange={onOrderChange}
          label="Threads"
          selectedThreadId={selectedThreadId}
        >
          {children}
        </ThreadListVisibility>
      </Provider>
    );
  }
  const view = render(<List selectedThreadId="row-0" />);
  renders.clear();
  view.rerender(<List selectedThreadId="row-1" />);
  const unrelatedRenders = rowIds
    .slice(2)
    .reduce((total, id) => total + (renders.get(id) ?? 0), 0);
  console.log(
    JSON.stringify({
      probe: "selection",
      rowsRendered: renders.size,
      unrelatedRenders,
    }),
  );
  expect(screen.getAllByRole("button")).toHaveLength(12);
  expect(unrelatedRenders).toBe(0);
});

The public reports repository requires test source and evidence inline rather than committed test/log artifacts. Raw logs and the reusable test remain in private local thread storage; no ignored-directory exception was added.

5. Root cause

Rename: a whole-session value is broadcast to every consumer

useRenameController stores the session in React state. Its change handler replaces that session for every draft change and returns a new controller object:

const [session, setSession] = useState<RenameSession | null>(null);
return {
  session,
  start,
  save,
  cancel,
  change: (draft: string) => {
    const current = sessionRef.current;
    if (current && !current.pending) {
      update({ ...current, draft, error: null, cannotRetry: false });
    }
  },
};

SidebarRenameProvider publishes that controller directly, and useSidebarRename subscribes to the entire context. All rows using that hook are therefore notified even when only another row's draft changes. Returning a stable object alone would not be enough: the actual editing row and dialog must still receive draft, pending, and error changes through a correctly scoped subscription.

Selection: the row-action callback gets a new identity

ThreadListVisibility creates customizeRowActions on every render and passes it to CustomizeRowActionsContext:

const customizeRowActions = (threadId: string) => {
  setRowActionsThreadId(threadId);
};
<CustomizeRowActionsContext.Provider value={customizeRowActions}>

Changing selectedThreadId rerenders this provider even though the action callback's behavior is unchanged. A new function identity invalidates every subscriber; React.memo does not suppress a subscribed context update. The reproduction changes only that selected ID while keeping the store, group/order arrays, callback prop, and child elements stable. The separate visibility-state object is also recreated, but the probe isolates the action callback rather than attributing every invalidation to every shared object.

The real ThreadRow consumes the rename hook and the action callback context; it is memoized. This connects the measured context behavior to the production row without claiming the probe rendered the complete row.

Palette: scheduling suspicion, not a proven timing regression

Local result building runs in useMemo with raw query as a dependency. That is consistent with synchronous local work during input renders. However, useThreadSearch already debounces its server query. The claim must not be interpreted as proof that every keystroke immediately performs a server search. A browser scheduling/paint trace with a large synthetic list is still needed.

6. Proposed fix and simple-fix gate

No automated fix PR: the combined issue crosses the thread-list plugin, shared rename helper, and command-palette subsystem; palette latency is not yet reproduced. It therefore fails the one-existing-subsystem simple-fix gate. No production fix, new branch, commit, dependency, or push to get-bb/bb was made.

7. Linked PR review

#6546 — closed, unmerged; static inspection only

GitHub timeline metadata links this PR to the issue. It was closed and unmerged at inspection; no open linked PR was found. Its metadata reports eight files, 1,090 additions, and 61 deletions, already beyond this rule's five-file and fewer-than-500-line limits.

The untrusted diff stabilizes visibility callbacks, replaces broad rename-session context updates with selective external-store subscriptions, and defers palette result-query updates. Those changes target the independently verified context causes. The rename helper/controller contract and its plugin-registry copy also change, increasing the compatibility review scope. No linked-branch code, script, test, binary, or benchmark was checked out or executed.

Verdict: directionally relevant to the verified root causes, not runtime-verified. The reported palette speedup is not adopted as evidence. There is insufficient execution evidence to approve or reject that full implementation; re-run focused failure/recovery, focus/dialog, and browser scheduling coverage on an independently authored patch.

8. Related issues

9. Verification

The same agent repeated the test in a second fresh trusted clone, detached at the exact base commit, with its own frozen install, generated build outputs, and in-memory test state. Only the reproduction test was copied; no production file was edited. This was a second clean run, not an independent-agent check.

cd /tmp/issue-6542-check-b
git rev-parse HEAD
3bacfac9ed69d42392076e5b3da2815bec822cd8
git diff --name-only
(empty; only the new untracked reproduction test is present)
pnpm exec turbo run test --filter=bb-plugin-thread-list -- app/list/issue6542.repro.test.tsx
{"probe":"rename","edits":3,"activeRenders":3,"unrelatedRenders":33}
{"probe":"selection","rowsRendered":12,"unrelatedRenders":10}
Test Files  1 failed (1)
     Tests  2 failed (2)

No correction to the measured counts was necessary. The report deliberately narrows the original broad redraw claim to the production context boundary actually tested, and does not infer a millisecond speedup or live browser paint pattern.

10. Appendix

Existing functional coverage

pnpm exec turbo run test --filter=bb-plugin-thread-list -- app/rows/SidebarInlineRename.test.tsx app/list/ProjectRow.interactions.test.tsx
✓ app/rows/SidebarInlineRename.test.tsx (19 tests)
✓ app/list/ProjectRow.interactions.test.tsx (31 tests)
Test Files  2 passed (2)
     Tests  50 passed (50)

The existing tests pass while the new idle-consumer invariants fail. A jsdom navigation warning in the existing interaction suite is unrelated to either failing assertion. No production change was attempted, so there is no claimed post-fix pass.

Build and hygiene

pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
Tasks: 72 successful, 72 total
pnpm exec oxfmt plugins/thread-list/app/list/issue6542.repro.test.tsx
git diff --check

Both full builds succeeded. Formatting touched only the probe; check A ran the same test before formatting and check B ran its formatted equivalent. Source history and the relevant commit-pinned links were checked against the recorded base. There were no screenshots because no visual or latency claim was verified.

Untrusted-data handling

The issue and linked PR supplied hypotheses only. Issue-provided checkout commands, scripts, test branches, and external links were not followed. GitHub metadata and the linked diff were read as untrusted data; all executed code was trusted target origin/main plus this agent's small reproduction test. No real user instance or runtime data was accessed.

> AGENT GENERATED