393
keyPath: null | string, // parent server component keys
394
implicitSlot: boolean, // true if the root server component of this sequence had a null key
395
thenableState: ThenableState | null,
396
+ environmentName: string, // DEV-only. Used to track if the environment for this task changed.
397
};
398
399
interface Reference {}
426
onError: (error: mixed) => ?string,
427
onPostpone: (reason: string) => void,
428
// DEV-only
428
- environmentName: string,
429
+ environmentName: () => string,
430
didWarnForKey: null | WeakSet<ReactComponentInfo>,
431
};
432
482
onError: void | ((error: mixed) => ?string),
483
identifierPrefix?: string,
484
onPostpone: void | ((reason: string) => void),
484
- environmentName: void | string,
485
+ environmentName: void | string | (() => string),
486
temporaryReferences: void | TemporaryReferenceSet,
487
) {
488
if (
532
533
if (__DEV__) {
534
this.environmentName =
534
- environmentName === undefined ? 'Server' : environmentName;
535
+ environmentName === undefined
536
+ ? () => 'Server'
537
+ : typeof environmentName !== 'function'
538
+ ? () => environmentName
539
+ : environmentName;
540
this.didWarnForKey = null;
541
}
542
const rootTask = createTask(this, model, null, false, abortSet);
549
onError: void | ((error: mixed) => ?string),
550
identifierPrefix?: string,
551
onPostpone: void | ((reason: string) => void),
547
- environmentName: void | string,
552
+ environmentName: void | string | (() => string),
553
temporaryReferences: void | TemporaryReferenceSet,
554
): Request {
555
// $FlowFixMe[invalid-constructor]: the shapes are exact here but Flow doesn't like constructors
1054
componentDebugInfo = (prevThenableState: any)._componentDebugInfo;
1055
} else {
1056
// This is a new component in the same task so we can emit more debug info.
1057
+ const componentDebugID = debugID;
1058
const componentName =
1059
(Component: any).displayName || Component.name || '';
1060
+ const componentEnv = request.environmentName();
1061
request.pendingChunks++;
1055
-
1056
- const componentDebugID = debugID;
1062
componentDebugInfo = ({
1063
name: componentName,
1059
- env: request.environmentName,
1064
+ env: componentEnv,
1065
owner: owner,
1066
}: ReactComponentInfo);
1067
if (enableOwnerStacks) {
1074
outlineModel(request, componentDebugInfo);
1075
emitDebugChunk(request, componentDebugID, componentDebugInfo);
1076
1077
+ // We've emitted the latest environment for this task so we track that.
1078
+ task.environmentName = componentEnv;
1079
+
1080
if (enableOwnerStacks) {
1081
warnForMissingKey(request, key, validated, componentDebugInfo);
1082
}
1652
request.writtenObjects.set(model, serializeByValueID(id));
1653
}
1654
}
1647
- const task: Task = {
1655
+ const task: Task = (({
1656
id,
1657
status: PENDING,
1658
model,
1705
return renderModel(request, task, parent, parentPropertyName, value);
1706
},
1707
thenableState: null,
1700
- };
1708
+ }: Omit<Task, 'environmentName'>): any);
1709
+ if (__DEV__) {
1710
+ task.environmentName = request.environmentName();
1711
+ }
1712
abortSet.add(task);
1713
return task;
1714
}
3263
}
3264
3265
// TODO: Don't double badge if this log came from another Flight Client.
3255
- const env = request.environmentName;
3266
+ const env = request.environmentName();
3267
const payload = [methodName, stackTrace, owner, env];
3268
// $FlowFixMe[method-unbinding]
3269
payload.push.apply(payload, args);
3431
// any future references.
3432
request.writtenObjects.set(resolvedModel, serializeByValueID(task.id));
3433
3434
+ if (__DEV__) {
3435
+ const currentEnv = request.environmentName();
3436
+ if (currentEnv !== task.environmentName) {
3437
+ // The environment changed since we last emitted any debug information for this
3438
+ // task. We emit an entry that just includes the environment name change.
3439
+ emitDebugChunk(request, task.id, {env: currentEnv});
3440
+ }
3441
+ }
3442
+
3443
// Object might contain unresolved values like additional elements.
3444
// This is simulating what the JSON loop would do if this was part of it.
3445
emitChunk(request, task, resolvedModel);
3448
// We don't need to escape it again so it's not passed the toJSON replacer.
3449
// $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do
3450
const json: string = stringify(resolvedModel);
3451
+
3452
+ if (__DEV__) {
3453
+ const currentEnv = request.environmentName();
3454
+ if (currentEnv !== task.environmentName) {
3455
+ // The environment changed since we last emitted any debug information for this
3456
+ // task. We emit an entry that just includes the environment name change.
3457
+ emitDebugChunk(request, task.id, {env: currentEnv});
3458
+ }
3459
+ }
3460
+
3461
emitModelChunk(request, task.id, json);
3462
}
3463