Skip to content

Commit 09059c5

Browse files
committed
Rename Chunk constructor to ReactPromise
When printing these in DevTools they show up as the name of the constructor so then you pass a Promise to the client it logs as "Chunk" which is confusing. Ideally we'd probably just name this Promise but 1) there's a slight difference in the .then method atm 2) it's a bit tricky to name a variable.
1 parent 6ebfd5b commit 09059c5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type SomeChunk<T> =
190190
| ErroredChunk<T>;
191191

192192
// $FlowFixMe[missing-this-annot]
193-
function Chunk(status: any, value: any, reason: any, response: Response) {
193+
function ReactPromise(status: any, value: any, reason: any, response: Response) {
194194
this.status = status;
195195
this.value = value;
196196
this.reason = reason;
@@ -200,9 +200,9 @@ function Chunk(status: any, value: any, reason: any, response: Response) {
200200
}
201201
}
202202
// We subclass Promise.prototype so that we get other methods like .catch
203-
Chunk.prototype = (Object.create(Promise.prototype): any);
203+
ReactPromise.prototype = (Object.create(Promise.prototype): any);
204204
// TODO: This doesn't return a new Promise chain unlike the real .then
205-
Chunk.prototype.then = function <T>(
205+
ReactPromise.prototype.then = function <T>(
206206
this: SomeChunk<T>,
207207
resolve: (value: T) => mixed,
208208
reject?: (reason: mixed) => mixed,
@@ -303,20 +303,20 @@ export function getRoot<T>(response: Response): Thenable<T> {
303303

304304
function createPendingChunk<T>(response: Response): PendingChunk<T> {
305305
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
306-
return new Chunk(PENDING, null, null, response);
306+
return new ReactPromise(PENDING, null, null, response);
307307
}
308308

309309
function createBlockedChunk<T>(response: Response): BlockedChunk<T> {
310310
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
311-
return new Chunk(BLOCKED, null, null, response);
311+
return new ReactPromise(BLOCKED, null, null, response);
312312
}
313313

314314
function createErrorChunk<T>(
315315
response: Response,
316316
error: Error | Postpone,
317317
): ErroredChunk<T> {
318318
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
319-
return new Chunk(ERRORED, null, error, response);
319+
return new ReactPromise(ERRORED, null, error, response);
320320
}
321321

322322
function wakeChunk<T>(listeners: Array<(T) => mixed>, value: T): void {
@@ -390,31 +390,31 @@ function createResolvedModelChunk<T>(
390390
value: UninitializedModel,
391391
): ResolvedModelChunk<T> {
392392
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
393-
return new Chunk(RESOLVED_MODEL, value, null, response);
393+
return new ReactPromise(RESOLVED_MODEL, value, null, response);
394394
}
395395

396396
function createResolvedModuleChunk<T>(
397397
response: Response,
398398
value: ClientReference<T>,
399399
): ResolvedModuleChunk<T> {
400400
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
401-
return new Chunk(RESOLVED_MODULE, value, null, response);
401+
return new ReactPromise(RESOLVED_MODULE, value, null, response);
402402
}
403403

404404
function createInitializedTextChunk(
405405
response: Response,
406406
value: string,
407407
): InitializedChunk<string> {
408408
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
409-
return new Chunk(INITIALIZED, value, null, response);
409+
return new ReactPromise(INITIALIZED, value, null, response);
410410
}
411411

412412
function createInitializedBufferChunk(
413413
response: Response,
414414
value: $ArrayBufferView | ArrayBuffer,
415415
): InitializedChunk<Uint8Array> {
416416
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
417-
return new Chunk(INITIALIZED, value, null, response);
417+
return new ReactPromise(INITIALIZED, value, null, response);
418418
}
419419

420420
function createInitializedIteratorResultChunk<T>(
@@ -423,7 +423,7 @@ function createInitializedIteratorResultChunk<T>(
423423
done: boolean,
424424
): InitializedChunk<IteratorResult<T, T>> {
425425
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
426-
return new Chunk(INITIALIZED, {done: done, value: value}, null, response);
426+
return new ReactPromise(INITIALIZED, {done: done, value: value}, null, response);
427427
}
428428

429429
function createInitializedStreamChunk<
@@ -436,7 +436,7 @@ function createInitializedStreamChunk<
436436
// We use the reason field to stash the controller since we already have that
437437
// field. It's a bit of a hack but efficient.
438438
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
439-
return new Chunk(INITIALIZED, value, controller, response);
439+
return new ReactPromise(INITIALIZED, value, controller, response);
440440
}
441441

442442
function createResolvedIteratorResultChunk<T>(
@@ -448,7 +448,7 @@ function createResolvedIteratorResultChunk<T>(
448448
const iteratorResultJSON =
449449
(done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
450450
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
451-
return new Chunk(RESOLVED_MODEL, iteratorResultJSON, null, response);
451+
return new ReactPromise(RESOLVED_MODEL, iteratorResultJSON, null, response);
452452
}
453453

454454
function resolveIteratorResultChunk<T>(
@@ -1760,7 +1760,7 @@ function startAsyncIterable<T>(
17601760
if (nextReadIndex === buffer.length) {
17611761
if (closed) {
17621762
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
1763-
return new Chunk(
1763+
return new ReactPromise(
17641764
INITIALIZED,
17651765
{done: true, value: undefined},
17661766
null,

0 commit comments

Comments
 (0)