[Flight Reply] retain listeners when resolving models with existing listeners (#29207)
In #29201 a fix was made to ensure we don't "forget" about some listeners when handling cyclic chunks. In #29204 another fix was made for a special case when the chunk already has listeners before it first resolves. This implements the followup fix for Flight Reply which was originally missed in #29204 Co-authored-by: Janka Uryga <lolzatu2@gmail.com>
Josh Story committed
May 21, 2024 at 16:16 UTC
81c5ff2e040ee56b85b8bd27a2f8065661f17fee
1 file changed
+17
-2
packages/react-server/src/ReactFlightReplyServer.js
+17
-2
@@ -205,8 +205,23 @@ function wakeChunkIfInitialized<T>(
205
case PENDING:
206
case BLOCKED:
207
case CYCLIC:
208
- chunk.value = resolveListeners;
209
- chunk.reason = rejectListeners;
208
+ if (chunk.value) {
209
+ for (let i = 0; i < resolveListeners.length; i++) {
210
+ chunk.value.push(resolveListeners[i]);
211
+ }
212
+ } else {
213
+ chunk.value = resolveListeners;
214
+ }
215
+
216
+ if (chunk.reason) {
217
+ if (rejectListeners) {
218
+ for (let i = 0; i < rejectListeners.length; i++) {
219
+ chunk.reason.push(rejectListeners[i]);
220
+ }
221
+ }
222
+ } else {
223
+ chunk.reason = rejectListeners;
224
+ }
225
break;
226
case ERRORED:
227
if (rejectListeners) {