[internal] Fix failing React 18 unit tests#22846
Conversation
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
ff836c9 to
3c5a74d
Compare
7b77bc8 to
13f9577
Compare
7f51561 to
43f2986
Compare
d974734 to
d6b3500
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Heyy @brijeshb42 👋 I've been looking into this with Claude because I wanted to understand why our Main idea: the What I saw:
So while the override was broken, the react_18 job was green but wrong for the whole repo, so there may be more React 18 failures hidden somewhere. Does this match what you saw? |
d6b3500 to
0aa830e
Compare
👍 Correct, but with the addition that this problem was only recent. It got introduced by pnpm 11 migration (cc @LukasTy) 2 weeks ago and fixed yesterday by mui/mui-public#1549. So there could be other issues, but likely only in code that was introduced over the last two weeks. |
React 18 StrictMode resets a render-mutated ref between double-render passes, so the useDisposable factory runs twice. Guard the affected assertions by React major version.
React 18 logs render-throws and ref-on-function-component warnings via console.error, tripping vitest-fail-on-console. Mock console.error for the throw test and forwardRef the slot probe.
BasePopper read ref from props but was not a forwardRef component, so React 18 warned "Function components cannot be given refs" when the multiSelect edit Modal passed a ref, tripping vitest-fail-on-console and cascading into a teardown crash. Wrap it in forwardRef like the sibling Base* components.
Passing the unkeyed getActions array as children triggered React 18's missing-key warning, tripping vitest-fail-on-console in the actions cell tests.
0aa830e to
323b611
Compare
323b611 to
ae821ae
Compare
LukasTy
left a comment
There was a problem hiding this comment.
LGTM. 👍
Thanks for addressing this. 🙏
|
Should be cherry-picked to v8? Noticed React 18 tests failing in #22860 |
| it('throws outside a ChatProvider when called without the optional flag', () => { | ||
| // React 18 logs the render-time throw via `console.error`, which trips | ||
| // `vitest-fail-on-console` in the browser runner; silence it for this case. | ||
| const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); |
There was a problem hiding this comment.
To not that this silences all console errors, even unintended ones.
There was a problem hiding this comment.
True. But there's not much to silence in this particular test.
Summary
Makes the unit and browser test suites pass under React 18 (the
test_*_react_18CI jobs), plus a couple of fixes to genuinely flaky/infra failures surfaced along the way. React 18 differs from React 19 in ways several tests implicitly relied on:console.error, whichvitest-fail-on-consoleturns into failures.keydev warning for unkeyed array children (React 19 dropped it).Changes
React 18 test compatibility
useDisposable: guard the StrictMode-sensitive assertions by React major version.x-chat/x-chat-headless: mockconsole.errorfor the render-throw test and adjust the slot probes so they work under React 18 browser mode.BasePopper(x-data-grid/material): wrap inforwardRefso the ref is forwarded instead of read offprops.ref(avoids the React 18 ref-on-function-component warning). (only non-test source change)Missing-
keywarnings in actions-cell testskeyprops to every action element passed togetActionsacrossrows,keyboard,events, andexportExceltests. Fixed at the call sites; no production code change.Flaky / infra fixes
ChatCodeBlockclipboard-failure test: skipped on jsdom since it doesn'texecCommand.DataGridProcolumn-resize test: flush therowsSetrequestAnimationFrame(which refreshes the resize hook's cell refs) before resizing again, removing a race with the pointer move.