Repository navigation
perf(web): compile ChatPaneNotices with the React Compiler - #23899
bolichen97 merged 1 commit into
Conversation
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS No blocker. The only note is that the allowlist's first new check is a second form of a check the memo ratchet already makes. Notes
What this change shipsInventory (6 items) — 5 justifiedIntent: stop the chat pane's notices from re-rendering on every frame of a streaming reply. This is a perf FIX.
[FIRST-PRINCIPLES-REVIEWED] 3301a77 Description read[DESCRIPTION-READ] cce2699411293ff152bce519b77512e90989148ee8e8c8ff45c70bdf725ab246 That sha256 names the PR description this verdict read. Recompute it with |
UX Review (Opus 5.5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff adds and changes no user-visible control. Every notice renders the same strings and elements, with only the compiler memoization and the language-switch subscriptions added, so no screenshot is needed. [UX-REVIEWED] 3301a77 Description read[DESCRIPTION-READ] 516fd4c49af98d25c0af5827c281f9821bdbc4a25cfc063b20bbbf367b3753c5 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the stated problem is real, and threading the language generation into the compiled pane fixes the stale-language risk the opt-in creates. Notes
[DESIGN-REVIEWED] 3301a77 Description read[DESCRIPTION-READ] bed6ddcd57de944d021afe90fcaaf82a0bfed1ec51534f4ef1259ec02e4aa3f3 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
b883420 to
2500515
Compare
|
issue (blocking): Compiled notices retain the previous language. Fixed in 2500515.
|
|
issue (blocking): Compiled
|
|
thought (non-blocking): The allowlist check proves
|
2500515 to
ff6706a
Compare
|
issue (blocking): Cached child notices stop updating on language switches. Fixed in ff6706a.
|
|
issue (blocking): Child notices with unchanged props keep the previous language under the compiled pane. Fixed in ff6706a.
|
ff6706a to
4aa8729
Compare
|
issue (blocking): The compiled pane caches its
|
|
issue (non-blocking): Compiling the pane freezes the crash fallback's language. Fixed in 4aa8729, although adjudication downgraded it.
|
|
thought (non-blocking): The allowlist child check re-implements import scanning that the memo ratchet already exports.
|
|
issue (blocking): Set an explicit timeout for the lazy-boundary assertion. Fixed in 3301a77.
|
4aa8729 to
3301a77
Compare
|
thought (non-blocking): Each listed file must redo the language work, and the allowlist checks read one level of relative
|
bolichen97
left a comment
There was a problem hiding this comment.
[operator: bolichen97] Approved at 3301a77: readiness passed, PR Readiness success, mergeable, no open blocking requests.
Problem / Motivation
Goal: Stop the chat pane's notices from re-rendering on every frame of a streaming reply.
ChatPaneNoticespasses a newonDismissarrow to eachErrorNoticeon every render. While a reply streams into the open chat, that makesErrorNoticerender about 10,100 times in 30 s on desktop, and about 7,100 times on mobile at 4x CPU throttle.Why it matters
Those renders run on the main thread during the stream, the busiest time for the chat page. They change nothing on screen. This is the first component on the React Compiler opt-in list, so it also shows that the list, the bailout test and the per-file lint work on a real file.
Not a goal
TagPopoverProvidercontext value behindMdParagraph.What changed (motivation → approach → change)
The render-cause classifier in the render benchmark attributed 7,466 of 9,810
ErrorNoticerenders in the S2 stream scenario to a changedonDismissprop, and 5,432 of them toChatPaneNoticesas the parent.ChatPaneNotices.tsxalready compiles with no bailout, so this PR only adds it towebsite/react-compiler.config.mjs. The compiler then memoizes the handlers and the notice elements.Adding it to the list also turns on the bailout test for this file and the compiler-backed
react-hookslint rules, so a later edit that makes it bail fails CI.The compiler memoizes each value on the reactive inputs it reads.
i18nT()andfmtDate()read the active catalog without being inputs, so compiling the file as it was would keep a visible notice in the previous language after a language switch. The component now builds every translated string in onepaneCopy()call that takesuseLanguageGeneration()as an argument, so a switch rebuilds the strings. A compiled component also caches the elements it renders while their props are unchanged, so each child becomes a memo boundary on a language switch.ErrorNoticeandVoicePlaybackNotice(inwebsite/src/components/) andUnrestoredTabsNoticetranslate their own text, so each now callsuseLanguageGeneration(), the repository's existing subscription for memo boundaries. It schedules the child's own re-render on a switch without remounting it.ErrorBoundaryis a class component and cannot call the hook, so it gains an optionallanguageGenerationprop. The pane passes the generation, which changes the boundary element on a switch and re-renders a visible crash card without resetting it.The allowlist test gains two checks. A listed file that imports
i18n/tori18n/formatmust calluseLanguageGeneration(). Every relative.tsxmodule a listed file imports, statically or through a lazyimport(), that translates must call it too, apart fromui.tsx, whoseBtnrenders no catalog text. ForErrorBoundarythe check instead requires every<ErrorBoundary>in a listed file to passlanguageGeneration.Backwards compatibility
Compatible: the component's props and rendered output are unchanged. Its strings are built in one call, and its memoization changes.
Removes nothing: the diff adds one entry to the opt-in list, moves the pane's string building into one function, adds a language subscription to three notice components and an optional prop to
ErrorBoundary, and adds tests.Tests
src/test/reactCompilerAllowlist.test.tsnow compilesChatPaneNotices.tsxand fails on any bailout.src/test/ChatPaneNotices.languageSwitch.test.tsxrenders the compiled component, switches to zh-CN and re-renders with identical props. It expects the config notice and the pane's dismiss labels in Chinese, and the upload-errorErrorNoticedismiss label, whose props hold no translated string, in Chinese too. It fails with the pane's strings left as they were, and fails again withErrorNoticeunsubscribed. It passes here.src/test/ChatPaneNotices.crashCardLanguage.test.tsxmakes the lazy unrestored-tabs notice throw so the pane's crash card shows, switches to zh-CN with identical props, and expects the card heading in Chinese. It fails when the pane omitslanguageGenerationon the boundary and passes here.useLanguageGeneration(), and a translating child of a listed file that does not subscribe or, forErrorBoundary, is not passed the generation.ChatPaneNoticesrun against the compiled component: 44 tests across 5 files pass. The 140 test files that referenceErrorNotice,UnrestoredTabsNoticeorVoicePlaybackNoticepass, 4,728 tests. The 24 test files that referenceErrorBoundaryorChatPaneNoticespass with the new prop, 481 tests. The new tests passed 3 shuffled runs.Manual verification
Render benchmark (the P8 script from #23431), medians of 3 interleaved runs, 30 s windows. Column A is main with the opt-in list empty, column B is this PR.
ErrorNoticerendersErrorNoticerendersErrorNoticerendersTotal renders fall 2.1% on desktop S2 and 5.4% on mobile S2, with ranges that do not overlap. S1x5 total renders take the same two values in both variants, so that row is noise. Script time, dispatches and selector calls are unchanged within the spread. These numbers were measured before the language fix. It adds one
useSyncExternalStoresubscription per notice that only fires on a language switch, so it does not change when the notices re-render during a stream.Screenshots / video
Why no screenshot: the notices render the same elements; only how often they re-render changes.
Related Issues
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)