Repository navigation
Resolve React Compiler diagnostics - #4162
Merged
Merged
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4162 +/- ##
==========================================
+ Coverage 98.96% 99.13% +0.16%
==========================================
Files 46 46
Lines 2030 2185 +155
Branches 792 962 +170
==========================================
+ Hits 2009 2166 +157
+ Misses 21 19 -2
🚀 New features to boost your workflow:
|
nstepien
marked this pull request as draft
August 29, 2026 16:02
nstepien
force-pushed
the
react-compiler-diagnostics
branch
from
August 31, 2026 18:30
d62c1db to
5b5e866
Compare
nstepien
force-pushed
the
react-compiler-diagnostics
branch
from
September 1, 2026 15:01
5b5e866 to
85c3508
Compare
`tsdown` now logs 21 React Compiler diagnostics, each one causing the compiler to skip optimizing the enclosing component or hook. Unsupported syntax: - `useColumnWidths`: replace `||=` with an `if` statement. Note that `hasChanges = hasChanges || …` would trip `eslint/logical-assignment-operators`. - `useCalculatedColumns`/`useViewportRows`: replace `x++` on variables captured within lambdas with `x += 1`. - `useViewportColumns`/`DataGrid`: generators cannot be lowered at all, so hoist every `function*` out of the hook/component body to module scope and pass what they used to close over as parameters. Two now-unused `react/memo-dependencies` suppressions are dropped, as the compiler was previously bailing on the whole file. Immutability: - `GroupRow`: `let idx` was mutated inside the render `.map()`. The increment only ever depended on whether the first rendered column is the select column, so materialize the columns once and compute `groupColumnIndex` as a constant before the JSX. - `DataGrid`: `setPosition` was read by `useImperativeHandle`/`useLatestFunc` before its declaration, so move the declaration above the `Misc hooks` block. Invariant: - `EditCell`: `cancelTask` was a hoisted function referenced by an effect declared above it. Extract it to module scope taking the three refs, which keeps the effect's `[commitOnOutsideClick]` dependency list correct — adding a component-body `cancelTask` as a dependency would make the effect tear down between re-renders, which the comment there explicitly guards against. `onClose` also moves above the `useEffectEvent` that calls it. Unreachable hoisted declaration: - `TreeDataGrid`: `isGroupRow` was declared after a `return`, so move it above the early return. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019NZmYxgysVEbw12FnbAf7x
nstepien
force-pushed
the
react-compiler-diagnostics
branch
from
September 4, 2026 12:08
85c3508 to
831245c
Compare
…stics # Conflicts: # src/DataGrid.tsx # src/EditCell.tsx # src/GroupedRow.tsx # src/TreeDataGrid.tsx # src/hooks/useViewportColumns.ts
- `GroupedRow`: instead of incrementing `idx` in the `mapViewportColumns` callback, compare each column with the `groupBy` key of the row's level, and pass `isLevelMatching` to `GroupCell`. The group-by columns follow the select column in `groupBy` order, so this is equivalent to the column index check, without depending on whether the select column is rendered. - `EditCell`: move `cancelTask` to module scope, taking the two refs, so the `useLayoutEffect` cleanup can call it without depending on it, and declare `onClose` before the `useEffectEvent` that calls it. - `DataGrid`: the imperative handle exposes `setPositionLatest` instead of `setPosition`. Reading the hoisted `setPosition` in the `useImperativeHandle` callback is what stopped the compiler, and the handle's `setActivePosition` is now stable across renders. - Enable `react/todo`, so oxlint reports the syntax React Compiler doesn't support yet, like `||=` and `x++` on variables captured by nested functions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…React Compiler diagnostics
- One `react()` instance now serves both Vite and `vp pack`: it produces
identical `lib/` and website builds, and the same dev-server modules.
Vite and `vp pack` never run in the same process, so the plugin's
per-run state isn't shared.
- Keep excluding `.d.ts` files: `vp pack` passes the declaration files it
generates through the plugin, and without the exclusion, `lib/index.d.ts`
becomes `export {}`. `node_modules` stays excluded, as replacing the
default `exclude` would otherwise compile dependencies in Vite.
- `reportDiagnostics: true` turns the code React Compiler skips into plugin
warnings, which fail `vp pack` in CI and agent sessions through
`failOnWarn`, and are logged by `vp dev`, `vp build`, and `vp test`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…EffectEvent` `cancelTask` no longer needs to live outside the component and take the refs as arguments: as an Effect Event, it isn't an effect dependency, so the effect still doesn't clean up between re-renders. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nstepien
marked this pull request as ready for review
October 25, 2026 18:15
nstepien
added a commit
that referenced
this pull request
Oct 26, 2026
Since 7.0.0-beta.63, every render of `DataGrid`, e.g., for a scroll, an active cell change, or a keystroke in an editor, can call `rowKeyGetter` for every row to compute the state of the select-all checkbox. It happens when the first unselected row is far down, e.g., after selecting all the rows. With 100,000 rows, a scroll by one row takes 2.5 ms instead of 0.4 ms in 7.0.0-beta.62, and the time grows with the number of rows. ### Cause #4162 made React Compiler compile `DataGrid`, which it skipped before. The loop that computes the state of the select-all checkbox is in `useMemo`, but it only produces booleans, so the compiler caches the object that holds them, keyed on the booleans, and runs the loop on every render. The compiler doesn't report it. In the published 7.0.0-beta.62, `DataGrid` isn't compiled, and `useMemo` caches the loop: ```js const headerSelectionValue = useMemo(() => { let hasSelectedRow = false; let hasUnselectedRow = false; if (rowKeyGetter != null && selectedRows != null && selectedRows.size > 0) for (const row of rows) { // … } return { isRowSelected: hasSelectedRow && !hasUnselectedRow, isIndeterminate: hasSelectedRow && hasUnselectedRow }; }, [rows, selectedRows, rowKeyGetter]); ``` In the published 7.0.0-beta.63, the loop is outside of any memo block: ```js let hasSelectedRow = false; let hasUnselectedRow = false; if (rowKeyGetter != null && selectedRows != null && selectedRows.size > 0) for (const row of rows) { // … } const t8 = hasSelectedRow && !hasUnselectedRow; const t9 = hasSelectedRow && hasUnselectedRow; let t10; if ($[28] !== t8 || $[29] !== t9) { t10 = { isRowSelected: t8, isIndeterminate: t9 }; // … } ``` The loop stops once it has found both a selected and an unselected row, which is why the benchmarks of #4162, with at most one selected row, didn't show it. The other `useMemo` calls in `src` are memoized: their loops create objects, so the loops stay in the memo blocks. ### Changes - The loop moves out of `useMemo`, to the top level of `DataGrid`, where the compiler memoizes it on `rows`, `selectedRows`, and `rowKeyGetter`: ```js let hasSelectedRow; let hasUnselectedRow; if ($[28] !== rowKeyGetter || $[29] !== rows || $[30] !== selectedRows) { hasSelectedRow = false; hasUnselectedRow = false; // … $[31] = hasSelectedRow; $[32] = hasUnselectedRow; } else { hasSelectedRow = $[31]; hasUnselectedRow = $[32]; } ``` - A comment says to keep the loop out of `useMemo`. - `useMemo` only creates the object, from the two booleans, so it keeps its identity while the state of the select-all checkbox doesn't change. Selecting another row while the checkbox stays indeterminate no longer renders it again. - A test selects all the rows of a grid with 1,000 rows, moves the active cell, and checks that `rowKeyGetter` was called for fewer rows than the grid has. It fails on `main` in all three browsers. ### Performance Mean wall-clock time per update in Chromium with React's production build, for a `DataGrid` with 100,000 rows and 11 columns, all of them selected. Each value is the mean of 2 runs of 200 updates, alternating between the four builds: | Update | 7.0.0-beta.62 | 7.0.0-beta.63 | `main` | This PR | | -------------------------------------- | ------------: | ------------: | -----: | ------: | | Scroll down by one row | 0.39 ms | 2.5 ms | 1.6 ms | 0.33 ms | | Move the active cell with an arrow key | 0.35 ms | 2.6 ms | 1.6 ms | 0.36 ms | Until #4242, `DataGrid` rendered twice per update. With 7.0.0-beta.63, each of these updates calls `rowKeyGetter` about 200,000 times, twice per row, and on `main`, about 100,000 times. With this PR, it calls it 21–25 times, for the rendered rows, and twice as often with 7.0.0-beta.62. In a `TreeDataGrid` with 1,000,000 rows, all of them selected, a scroll by one row takes 36 ms on `main`, and 0.28 ms with this PR. `vp run ci` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vp packcompilessrc/with React Compiler, which skips every component or hook it can't compile. Onmain, it skipsDataGrid,EditCell,GroupedRow,useCalculatedColumns,useColumnWidths, anduseViewportRows. After this PR, all of them are compiled, and if a bail-out comes back, oxlint reports it andvp packfails in CI.Unsupported syntax
useColumnWidths: replace||=with anifstatement.hasChanges = hasChanges || …would tripeslint/logical-assignment-operators.useCalculatedColumns/useViewportRows: replacex++on variables captured by nested functions withx += 1.react/todo, which reports both. It was turned off in oxlint: configure react rules #4155, before React Compiler was set up, while the generators couldn't be compiled either. ReplaceiterateOverViewportColumnsForRowwithmapViewportColumns, and fix cells hidden bycolSpan#4225 removed them.Immutability
GroupedRow:let idxwas incremented in themapViewportColumnscallback when the first rendered column was the select column, andGroupCellcompared it withcolumn.idx. The group-by columns follow the select column ingroupByorder, soGroupedRownow compares each column's key withgroupBy[row.level]and passes the result toGroupCellasisLevelMatching.Hoisted functions
DataGrid: theuseImperativeHandlecallback readsetPosition, which is declared further down. The handle now exposessetPositionLatest, which also keeps itssetActivePositionstable across renders, and thereact/immutabilitysuppression is gone.EditCell: theuseLayoutEffectcleanup calledcancelTask, which was declared after the effect. It's now declared before the effect, and the cleanup calls it throughuseEffectEvent, likecommitOnOutsideMouseDown. A plain call would make it an effect dependency, and the effect must not clean up between re-renders, as the comment there explains.onClosealso moves above theuseEffectEventthat calls it. TheTODO: report React Compiler bugnote and itsreact/invariantsuppression are gone.Build
compiler: { reportDiagnostics: true }turns the code React Compiler skips into plugin warnings.vp packalready fails on warnings in CI and agent sessions (failOnWarn: isAgent || 'ci-only'), andvp dev,vp build, andvp testlog them. Unlike lint, a suppression comment doesn't hide them.panicThreshold: 'all_errors'would fail every build, including the dev server and tests while code is being edited, and'critical_errors'misses unsupported syntax likex++.react()instance now serves both Vite andvp pack. It produces identicallib/and website builds, and the same dev-server modules.vp packcan't uselazyPlugins, so its plugins were already created on every config load. The plugin keeps some per-run state, like whether to emit development JSX, which is fine because Vite andvp packnever run in the same process..d.tsfiles stay excluded:vp packpasses the declaration files it generates through the plugin, and without the exclusion,lib/index.d.tsbecomesexport {}, which publint doesn't catch.node_modulesstays excluded too, as settingexcludereplaces the plugin's default.vp packfails on code React Compiler can't compile.Performance
The differences are small, and only a few hold in at least 4 of the 5 rounds:
main, this PR makes typing in an editor about 10% faster (4 of 5 rounds) and collapsing or expanding a group about 8% faster (5 of 5).EditCellandGroupedRoware among the components it now compiles. Moving the active cell is about 9% slower (5 of 5).DataGridis about 7% faster (5 of 5) and re-rendering it with the same props about 11% faster (4 of 5). MountingTreeDataGridis about 8% slower (5 of 5), and typing in an editor about 11% slower (4 of 5).mainDataGrid: mountDataGrid: parent re-render, same propsDataGrid: toggle row selectionDataGrid: move the active cellDataGrid: type in an editorDataGrid: scroll down by 4pxDataGrid: scroll down by one rowDataGrid: scroll right by 4pxDataGrid: scroll right by one columnTreeDataGrid: mountTreeDataGrid: scroll down by one rowTreeDataGrid: collapse or expand a groupSelectColumn, then 40 columns withrenderTextEditor, the first of which is frozen.TreeDataGridalso has two columns that group the rows, with all 110 groups expanded. The app around the grid isn't compiled, so each of its re-renders passes a newstyleobject.NODE_ENV=production,react-dom/client).performance.now()around aflushSynccall. That covers React's render and commit, including layout effects. It doesn't cover the browser's layout and paint after the commit, and the scroll scenarios lay out before starting the timer. Chromium roundsperformance.now()to 0.1 ms, hence the means.memo,useMemo,useLatestFunc). React Compiler adds a memo cache to each component, which a mount allocates and fills. InDataGrid, most memoized values still change on every render, so its cache mostly adds comparisons. Declare functions before passing them to hooks, so React Compiler memoizesDataGrid#4236 fixes that.vp run cipasses.🤖 Generated with Claude Code