Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): ChatView joins the strict React Compiler list #20418

Mergedjuliusmarmingemerged 3 commits intochatview-split/timeline-compiles fromrefs/pull/20418/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

ChatView compiled but sat on REACT_COMPILED_FILES_PENDING_LINT, still carrying 69 manual memos and 16 effects that copied props into state. That only got it compiling. This PR makes the component itself better, and ChatView joins the strict list, where lint holds it to no manual memoization and none of the compiler's effect rules.

Manual memoization: 72 → 0. I diffed the compiled output before and after. No value that reaches a prop, a context, or a hook dependency lost its cache. The values that are now recomputed each render are plain derivations, such as lookups and labels, that nothing downstream keys on.

State-sync effects became render-time logic or keyed state:

BeforeAfter
Two effects cleared the pending env mode and branch override on thread switch and when overriding became impossibleEach override carries its thread id, so it simply stops applying on another thread. One render-time reset covers the "can't override" case.
Three effects cleared the terminal launch context (thread switch, drawer closed, location caught up)One render-time check with the reason written next to it
Mounted terminal threads reconciled in an effectReconciled during render, set only when the list actually changes
Branch-mismatch reveal, timeline anchor release, provider banner dismissal, workspace drag resetAdjusted during render
Thread switch reset follow-state in an effectState resets during render; the refs the scroll handlers read catch up in an effect keyed on that reset
Optimistic messages cleared in an effectRetired during render; their blob URLs are revoked after commit
A draft's error moved to its server thread in an effectMoved during render
An environment change was cancelled by an effect cleanupThe request carries the draft/project scope it started in and is ignored once that scope moves on
"Work locally" cleared its marker inside the resend effectA one-shot stable callback clears it and sends

Three effects keep a dependency the rule calls extra, each annotated with the reason:

  • A thread switch re-measures the composer overlay.
  • A thread switch remounts the timeline's scroll node, so the scroll listeners reattach.
  • The scroll-to-bottom button changes the overlay's height before the observed node resizes.

Also in this PR:

  • useOpenChangeRequestLink reads the environment config map when a link is clicked instead of subscribing to it. Before, every provider status push gave every markdown block a new click handler and re-rendered every reply.

Measured in the dev app with the long project thread, counting React renders per interaction:

InteractionRenders
Idle 20s0
Type 19 chars747
Scroll timeline up 3,600px0
Agent streams a 20-line reply6,241 (178 commits)

No console errors or update loops appeared during the pass. Typecheck, lint, and the ChatView, Sidebar, MessagesTimeline and reactCompiledFiles tests pass (689).

Stack progress

LayerChatView linesChatView component bodyCompiler on ChatViewFiles held to strict compiler lint
main11,66010,007crashes (internal error)0
#20161 pending approvals and questions hook11,2229,624crashes (internal error)0
#20164 terminal drawer and panel file10,6149,624crashes (internal error)0
#20289 one terminal open/close hook10,4669,481crashes (internal error)0
#20292 compile-required lint list10,4669,481crashes (internal error)2
#20294 pending hook compiles10,4669,481crashes (internal error)3
#20296 /usage-limits panel hook10,3979,416crashes (internal error)4
#20304 queued-message editing hook10,1729,200crashes (internal error)5
#20308 linked pull request hook10,0789,106crashes (internal error)6
#20309 proactive panel hook9,9508,984crashes (internal error)7
#20312 agent-opened previews hook9,8558,890crashes (internal error)8
#20315 right panel close hook9,7438,779crashes (internal error)9
#20316 worktree setup hook9,6608,695crashes (internal error)10
#20321 two onSend phases split out9,6608,613crashes (internal error)10
#20340 compiler no longer crashes on ChatView9,6478,599skips (32 reasons)10
#20379 ChatView compiles9,6168,469compiles11
#20380 re-render fixes from profiling9,6618,514compiles11
#20392 provider pushes keep identity9,6288,481compiles11
#20393 keyboard shortcuts command map9,3408,265compiles13
#20396 Sidebar compiles, no manual memos9,3408,265compiles14
#20397 ChatComposer compiles9,3408,265compiles14
#20401 project script editing hook9,1108,049compiles15
#20402 MessagesTimeline compiles9,1108,049compiles16
→ #20418 ChatView strict: no memos, no sync effects8,9017,855compiles17

Measured with the native React Compiler (oxc-transform-react) on each layer's ChatView.tsx. "Crashes" means it hit an internal codegen error and left ChatView uncompiled; "skips" means it reported reasons it could not compile it. Strict files must compile with no bailouts, no manual memoization and no effect-rule violations; lint and reactCompiledFiles.test.ts enforce it.

🤖 Generated with Claude Code (Claude Opus 5.5)


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge changed the title

    3. juliusmarminge added labelsmacroscope-review

    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ⚠️ The latest CI run did not produce a thread transfer result for 9d82388.

      This comment will update automatically after the next completed run.

    5. @@ -2056,5 +1967,4 @@
      20561967 reconnectWarningGraceElapsedEnvironmentId,
      20571968 );
      20581969 useEffect(() => {
      2059- setReconnectWarningGraceElapsedEnvironmentId(null);
      20601970 if (activeReconnectingEnvironmentId === null) return;

      🟡 Medium components/ChatView.tsx:1969

      After a reconnect has exceeded the grace period, the next reconnect to the same environment shows the unavailable banner immediately, even if it is transient. reconnectWarningGraceElapsedEnvironmentId is never cleared when the environment reconnects successfully; reset it when the reconnect state changes so each attempt gets its own grace period.

      Suggested change
      1969- useEffect(() => {
      1970- if (activeReconnectingEnvironmentId === null) return;
      1969+ useEffect(() => {
      1970+ setReconnectWarningGraceElapsedEnvironmentId(null);
      1971+ if (activeReconnectingEnvironmentId === null) return;
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/ChatView.tsx around lines 1969-1970:
      
      After a reconnect has exceeded the grace period, the next reconnect to the same environment shows the unavailable banner immediately, even if it is transient. `reconnectWarningGraceElapsedEnvironmentId` is never cleared when the environment reconnects successfully; reset it when the reconnect state changes so each attempt gets its own grace period.
      @@ -3440,6 +3285,11 @@
      34403285 : "Auto balance"
      34413286 : undefined;
      34423287
      3443- const environmentChangeRef = useRef<{ readonly environmentId: EnvironmentId } | null>(null);
      3444- const [isEnvironmentChanging, setIsEnvironmentChanging] = useState(false);
      3288+ // A change in flight belongs to the draft and project it started on.
      3289+ const environmentChangeScope = `${draftId ?? ""}:${activeProjectKey ?? ""}`;
      3290+ const environmentChangeRef = useRef<{
      3291+ readonly environmentId: EnvironmentId;
      3292+ readonly scope: string;
      3293+ } | null>(null);
      3294+ const environmentChangeScopeRef = useRef("");
      34453295 useLayoutEffect(() => {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High components/ChatView.tsx:3295

      If a draft ChatView unmounts while openScratchProject() is pending, its completion still passes retarget's checks and rewrites the original draft's machine/project. The scope ref remains unchanged after unmount, and no cleanup invalidates the request; clear the matching request in a useLayoutEffect cleanup keyed by environmentChangeScope.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/ChatView.tsx around line 3295:
      
      If a draft `ChatView` unmounts while `openScratchProject()` is pending, its completion still passes `retarget`'s checks and rewrites the original draft's machine/project. The scope ref remains unchanged after unmount, and no cleanup invalidates the request; clear the matching request in a `useLayoutEffect` cleanup keyed by `environmentChangeScope`.
    6. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 88891ba8-3fe3-4e77-b861-c314c9f1d97c
      📥 Commits

      Reviewing files that changed from the base of the PR and between 4ede1f4d3d87a2120df94bd60b4eb34f168012e7 and ab6146f0450d3be55229b9474b8e650b7abb920d.

      📒 Files selected for processing: 4
      • apps/web/reactCompiledFiles.ts
      • apps/web/src/components/ChatView.tsx
      • apps/web/src/lib/openPullRequestLink.ts
      • apps/web/src/reactCompiledFiles.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

      📝 Walkthrough

      ChatView replaces many memoized calculations with direct render-time calculations and changes how thread, environment, timeline, and composer state is reconciled. The pull-request link handler reads server configuration when invoked. ChatView is added to React Compiler coverage.

      Changes: ChatView render and state updates

      Layer / File(s)Summary
      Render-derived values and compiler coverage
      apps/web/src/components/ChatView.tsx, apps/web/reactCompiledFiles.ts, apps/web/src/reactCompiledFiles.test.ts
      ChatView computes derived values, banners, and controls directly during render. React Compiler coverage now includes ChatView, and the pending-lint export and corresponding test coverage are removed.
      Thread and environment state reconciliation
      apps/web/src/components/ChatView.tsx
      Route, timeline, terminal, and banner state is reconciled during render. Environment changes are scoped to the active draft and project, and server-thread overrides are keyed by thread ID.
      Timeline and composer interactions
      apps/web/src/components/ChatView.tsx
      Timeline handlers use a captured composer reference. Optimistic messages are retired on thread changes, and Work locally resend uses a one-shot callback.

      Pull-request link configuration lookup

      Layer / File(s)Summary
      Click-time server configuration lookup
      apps/web/src/lib/openPullRequestLink.ts
      The click callback reads server configurations from the atom registry instead of using the value captured by a hook.

      Priority: ⬇️ Low

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Refactor

      Suggested reviewers: maria-rcks

      Merge Risk: ⚪ Minimal · up to ab614

      Returning to a draft cannot trigger the previously pending resend. The change is mergeable after normal checks.

      Pre-merge checks: Passed 3 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Description checkWarningThe description provides detailed problem, implementation, and verification information, but it does not follow the required template. It omits the Problem, Change, Scope and approval, and Verificatio…Reorganize the existing content under the required Problem, Change, Scope and approval, and Verification headings. Add the triaged issue or explicit maintainer approval, or explain why this focused change qualifies for an exemption. Include…
      Passed Passed checks: 3 passed
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title clearly identifies the main change: ChatView joins the strict React Compiler list.
      Full details: Description check

      Explanation

      The description provides detailed problem, implementation, and verification information, but it does not follow the required template. It omits the Problem, Change, Scope and approval, and Verification headings, lacks issue or maintainer approval details, and does not include the required UI evidence or a clear model-and-harness footer.

      Resolution

      Reorganize the existing content under the required Problem, Change, Scope and approval, and Verification headings. Add the triaged issue or explicit maintainer approval, or explain why this focused change qualifies for an exemption. Include focused test commands and observed results, state anything not checked, and add before/after screenshots for the UI changes. End with the model and harness used, as required.

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    7. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — This PR is a broad production ChatView lifecycle refactor with many render-time state and cleanup changes, not just compiler bookkeeping. It also adds lint-suppression directives, and the supplied findings identify reconnect-state and unmount-time async risks requiring human attention.

      Needs human approval because:

      • 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity

      No code changes detected at 9d82388. Prior analysis still applies.

      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    8. juliusmarminge merged thisa09394e

    9. juliusmarminge closed this

Sign in to join this conversation.