perf(web): ChatView joins the strict React Compiler list #20418
chatview-split/timeline-compiles fromrefs/pull/20418/head·merged by juliusmarminge View on GitHubChatView 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:
| Before | After |
|---|---|
| Two effects cleared the pending env mode and branch override on thread switch and when overriding became impossible | Each 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 effect | Reconciled during render, set only when the list actually changes |
| Branch-mismatch reveal, timeline anchor release, provider banner dismissal, workspace drag reset | Adjusted during render |
| Thread switch reset follow-state in an effect | State resets during render; the refs the scroll handlers read catch up in an effect keyed on that reset |
| Optimistic messages cleared in an effect | Retired during render; their blob URLs are revoked after commit |
| A draft's error moved to its server thread in an effect | Moved during render |
| An environment change was cancelled by an effect cleanup | The 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 effect | A 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:
useOpenChangeRequestLinkreads 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:
| Interaction | Renders |
|---|---|
| Idle 20s | 0 |
| Type 19 chars | 747 |
| Scroll timeline up 3,600px | 0 |
| Agent streams a 20-line reply | 6,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#
| Layer | ChatView lines | ChatView component body | Compiler on ChatView | Files held to strict compiler lint |
|---|---|---|---|---|
| main | 11,660 | 10,007 | crashes (internal error) | 0 |
| #20161 pending approvals and questions hook | 11,222 | 9,624 | crashes (internal error) | 0 |
| #20164 terminal drawer and panel file | 10,614 | 9,624 | crashes (internal error) | 0 |
| #20289 one terminal open/close hook | 10,466 | 9,481 | crashes (internal error) | 0 |
| #20292 compile-required lint list | 10,466 | 9,481 | crashes (internal error) | 2 |
| #20294 pending hook compiles | 10,466 | 9,481 | crashes (internal error) | 3 |
| #20296 /usage-limits panel hook | 10,397 | 9,416 | crashes (internal error) | 4 |
| #20304 queued-message editing hook | 10,172 | 9,200 | crashes (internal error) | 5 |
| #20308 linked pull request hook | 10,078 | 9,106 | crashes (internal error) | 6 |
| #20309 proactive panel hook | 9,950 | 8,984 | crashes (internal error) | 7 |
| #20312 agent-opened previews hook | 9,855 | 8,890 | crashes (internal error) | 8 |
| #20315 right panel close hook | 9,743 | 8,779 | crashes (internal error) | 9 |
| #20316 worktree setup hook | 9,660 | 8,695 | crashes (internal error) | 10 |
| #20321 two onSend phases split out | 9,660 | 8,613 | crashes (internal error) | 10 |
| #20340 compiler no longer crashes on ChatView | 9,647 | 8,599 | skips (32 reasons) | 10 |
| #20379 ChatView compiles | 9,616 | 8,469 | compiles | 11 |
| #20380 re-render fixes from profiling | 9,661 | 8,514 | compiles | 11 |
| #20392 provider pushes keep identity | 9,628 | 8,481 | compiles | 11 |
| #20393 keyboard shortcuts command map | 9,340 | 8,265 | compiles | 13 |
| #20396 Sidebar compiles, no manual memos | 9,340 | 8,265 | compiles | 14 |
| #20397 ChatComposer compiles | 9,340 | 8,265 | compiles | 14 |
| #20401 project script editing hook | 9,110 | 8,049 | compiles | 15 |
| #20402 MessagesTimeline compiles | 9,110 | 8,049 | compiles | 16 |
| → #20418 ChatView strict: no memos, no sync effects | 8,901 | 7,855 | compiles | 17 |
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)
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge changed the title
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -2056,5 +1967,4 @@20561967 reconnectWarningGraceElapsedEnvironmentId,20571968 );20581969 useEffect(() => {2059- setReconnectWarningGraceElapsedEnvironmentId(null);20601970 if (activeReconnectingEnvironmentId === null) return;
🟡 Medium
components/ChatView.tsx:1969After a reconnect has exceeded the grace period, the next reconnect to the same environment shows the unavailable banner immediately, even if it is transient.
reconnectWarningGraceElapsedEnvironmentIdis never cleared when the environment reconnects successfully; reset it when the reconnect state changes so each attempt gets its own grace period.Suggested change1969- 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;344232873443- 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(() => {🟠 High
components/ChatView.tsx:3295If a draft
ChatViewunmounts whileopenScratchProject()is pending, its completion still passesretarget'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 auseLayoutEffectcleanup keyed byenvironmentChangeScope.🚀 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`. 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.tsapps/web/src/components/ChatView.tsxapps/web/src/lib/openPullRequestLink.tsapps/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.tsChatView 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.tsxRoute, 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.tsxTimeline 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.tsThe 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:
3 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Description check 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 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 checks: 3 passed-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The 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
-
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
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).9d82388. Prior analysis still applies.juliusmarminge merged thisa09394e
juliusmarminge closed this
Sign in to join this conversation.
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.