Commit 3d58db8
committed
Commit pending hook state in options._render
`useReducer` installed two closures on every hook-using component: a
`shouldComponentUpdate` that both decided the bail-out and committed
`_nextValue` -> `_value`, and a `componentWillUpdate` that existed only to
run that same commit on the forced-update path, where core skips sCU. It did
so by temporarily nulling `prevScu` and re-entering the sCU, smuggling a
mutation through a predicate.
The commit belongs in neither. `options._render` runs immediately before
every render, forced or not, and already ran this exact loop for the
same-component re-render branch. Hoisting it out unconditionally makes
`componentWillUpdate` unnecessary and leaves sCU a pure predicate.
Clearing `_pendingArgs` unconditionally is safe because `options.diffed`
promotes them after every successful diff, so leftovers belong to a render
that never committed and this render recomputes them. On bail-out
`_nextValue` simply stays pending; the dispatcher already reads
`_nextValue[0]` when present.
hooks: 1387 -> 1331 B brotli (-4.0%). Also drops a closure per component
instance, and stops compat's UNSAFE_* accessor setter from running
`Object.defineProperty` on every hook component.
The forced-update path had no coverage, so add a test that drives it through
a context provider.1 parent 47110cb commit 3d58db8
2 files changed
Lines changed: 68 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | | - | |
62 | 60 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | 61 | | |
70 | 62 | | |
71 | 63 | | |
72 | | - | |
73 | 64 | | |
74 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
| |||
207 | 212 | | |
208 | 213 | | |
209 | 214 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
| 215 | + | |
227 | 216 | | |
228 | 217 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
242 | 227 | | |
243 | 228 | | |
244 | 229 | | |
245 | 230 | | |
246 | 231 | | |
247 | | - | |
248 | | - | |
| 232 | + | |
| 233 | + | |
249 | 234 | | |
250 | 235 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 236 | + | |
255 | 237 | | |
| 238 | + | |
256 | 239 | | |
257 | 240 | | |
258 | 241 | | |
| |||
262 | 245 | | |
263 | 246 | | |
264 | 247 | | |
265 | | - | |
266 | | - | |
267 | | - | |
| 248 | + | |
268 | 249 | | |
269 | 250 | | |
270 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
540 | 579 | | |
0 commit comments