Commit 7977aeb
committed
fix(rsc): pre-include React peers in client env optimizeDeps
The client environment only had `react-dom/client` and the React
Server DOM browser entry in `optimizeDeps.include`. React itself
and crawled React-peer packages were discovered lazily as the
browser requested modules, which re-runs the optimizer mid-load
and changes the `?v=` hash on already-served chunks. The browser
ends up with two distinct React module records, and `'use client'`
libraries that synchronously call hooks in providers hit the wrong
dispatcher (`React.H` is null), throwing `Invalid hook call`.
Mirror the SSR/RSC env behaviour by including `react`,
`react-dom`, `react/jsx-runtime`, `react/jsx-dev-runtime`, plus
the React-peer packages from `crawlFrameworkPkgs`. Filter that
list to packages with a client-resolvable entry so server-only
React peers (e.g. `@vitejs/test-dep-client-in-server`) don't
break dep optimization.1 parent 65d378f commit 7977aeb
1 file changed
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
114 | 128 | | |
115 | 129 | | |
116 | 130 | | |
| |||
517 | 531 | | |
518 | 532 | | |
519 | 533 | | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
520 | 538 | | |
521 | 539 | | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
522 | 545 | | |
523 | 546 | | |
524 | 547 | | |
| |||
0 commit comments