Commit 91e8832
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 91e8832
1 file changed
Lines changed: 19 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 | + | |
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
| |||
517 | 529 | | |
518 | 530 | | |
519 | 531 | | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
520 | 536 | | |
521 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
522 | 541 | | |
523 | 542 | | |
524 | 543 | | |
| |||
0 commit comments