Commit f172fa7
authored
[Flight] Detriplicate Objects (#27537)
Now that we no longer support Server Context, we can now deduplicate
objects. It's not completely safe for useId but only in the same way as
it's not safe if you reuse elements on the client, so it's not a new
issue.
This also solves cyclic object references.
The issue is that we prefer to inline objects into a plain JSON format
when an object is not going to get reused. In this case the object
doesn't have an id. We could potentially serialize a reference to an
existing model + a path to it but it bloats the format and complicates
the client.
In a smarter flush phase like we have in Fizz we could choose to inline
or outline depending on what we've discovered so far before a flush. We
can't do that here since we use native stringify. However, even in that
solution you might not know that you're going to discover the same
object later so it's not perfect deduping anyway.
Instead, I use a heuristic where I mark previously seen objects and if I
ever see that object again, then I'll outline it. The idea is that most
objects are just going to be emitted once and if it's more than once
it's fairly likely you have a shared reference to it somewhere and it
might be more than two.
The third object gets deduplicated (or "detriplicated").
It's not a perfect heuristic because when we write the second object we
will have already visited all the nested objects inside of it, which
causes us to outline every nested object too even those weren't
reference more than by that parent. Not sure how to solve for that.
If we for some other reason outline an object such as if it suspends,
then it's truly deduplicated since it already has an id.1 parent 2eeb9f9 commit f172fa7
File tree
4 files changed
+282
-55
lines changed- packages
- react-client/src
- __tests__
- react-server-dom-webpack/src/__tests__
- react-server/src
4 files changed
+282
-55
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
94 | 102 | | |
95 | 103 | | |
96 | 104 | | |
| |||
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
| 133 | + | |
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
| |||
160 | 169 | | |
161 | 170 | | |
162 | 171 | | |
| 172 | + | |
163 | 173 | | |
164 | 174 | | |
165 | 175 | | |
| |||
211 | 221 | | |
212 | 222 | | |
213 | 223 | | |
| 224 | + | |
214 | 225 | | |
215 | 226 | | |
216 | 227 | | |
| |||
259 | 270 | | |
260 | 271 | | |
261 | 272 | | |
| 273 | + | |
262 | 274 | | |
263 | 275 | | |
264 | 276 | | |
| |||
365 | 377 | | |
366 | 378 | | |
367 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
368 | 391 | | |
369 | | - | |
| 392 | + | |
370 | 393 | | |
371 | 394 | | |
372 | 395 | | |
| |||
379 | 402 | | |
380 | 403 | | |
381 | 404 | | |
| 405 | + | |
382 | 406 | | |
383 | 407 | | |
384 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
385 | 412 | | |
386 | 413 | | |
387 | 414 | | |
| |||
491 | 518 | | |
492 | 519 | | |
493 | 520 | | |
| 521 | + | |
494 | 522 | | |
495 | 523 | | |
496 | 524 | | |
497 | 525 | | |
498 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
499 | 529 | | |
500 | 530 | | |
501 | | - | |
502 | | - | |
| 531 | + | |
| 532 | + | |
503 | 533 | | |
504 | 534 | | |
505 | 535 | | |
| |||
673 | 703 | | |
674 | 704 | | |
675 | 705 | | |
| 706 | + | |
676 | 707 | | |
677 | 708 | | |
678 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
679 | 715 | | |
680 | 716 | | |
681 | 717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
377 | | - | |
| 377 | + | |
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
| 383 | + | |
383 | 384 | | |
384 | 385 | | |
385 | 386 | | |
| |||
389 | 390 | | |
390 | 391 | | |
391 | 392 | | |
392 | | - | |
| 393 | + | |
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
| |||
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| 406 | + | |
405 | 407 | | |
406 | 408 | | |
407 | 409 | | |
408 | 410 | | |
409 | | - | |
| 411 | + | |
410 | 412 | | |
411 | 413 | | |
412 | 414 | | |
413 | 415 | | |
414 | 416 | | |
| 417 | + | |
415 | 418 | | |
416 | 419 | | |
417 | 420 | | |
418 | 421 | | |
419 | 422 | | |
420 | 423 | | |
421 | | - | |
| 424 | + | |
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
| |||
431 | 434 | | |
432 | 435 | | |
433 | 436 | | |
| 437 | + | |
434 | 438 | | |
435 | 439 | | |
436 | 440 | | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
437 | 458 | | |
438 | 459 | | |
439 | 460 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
186 | 245 | | |
187 | 246 | | |
188 | 247 | | |
| |||
0 commit comments