137
138
import {SuspenseException, getSuspendedThenable} from './ReactFlightThenable';
139
140
+// DEV-only set containing internal objects that should not be limited and turned into getters.
141
+const doNotLimit: WeakSet<Reference> = __DEV__ ? new WeakSet() : (null: any);
142
+
143
function defaultFilterStackFrame(
144
filename: string,
145
functionName: string,
2156
): string {
2157
// Like serializeMap but for renderConsoleValue.
2158
const entries = Array.from(map);
2159
+ // The Map itself doesn't take up any space but the outlined object does.
2160
+ counter.objectLimit++;
2161
+ for (let i = 0; i < entries.length; i++) {
2162
+ // Outline every object entry in case we run out of space to serialize them.
2163
+ // Because we can't mark these values as limited.
2164
+ const entry = entries[i];
2165
+ doNotLimit.add(entry);
2166
+ const key = entry[0];
2167
+ const value = entry[1];
2168
+ if (typeof key === 'object' && key !== null) {
2169
+ doNotLimit.add(key);
2170
+ }
2171
+ if (typeof value === 'object' && value !== null) {
2172
+ doNotLimit.add(value);
2173
+ }
2174
+ }
2175
const id = outlineConsoleValue(request, counter, entries);
2176
return '$Q' + id.toString(16);
2177
}
2183
): string {
2184
// Like serializeMap but for renderConsoleValue.
2185
const entries = Array.from(set);
2186
+ // The Set itself doesn't take up any space but the outlined object does.
2187
+ counter.objectLimit++;
2188
+ for (let i = 0; i < entries.length; i++) {
2189
+ // Outline every object entry in case we run out of space to serialize them.
2190
+ // Because we can't mark these values as limited.
2191
+ const entry = entries[i];
2192
+ if (typeof entry === 'object' && entry !== null) {
2193
+ doNotLimit.add(entry);
2194
+ }
2195
+ }
2196
const id = outlineConsoleValue(request, counter, entries);
2197
return '$W' + id.toString(16);
2198
}
3405
parentPropertyName: string,
3406
value: ReactClientValue,
3407
): ReactJSONValue {
3379
- // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
3380
- // $FlowFixMe[incompatible-use]
3381
- const originalValue = parent[parentPropertyName];
3382
- if (
3383
- typeof originalValue === 'object' &&
3384
- originalValue !== value &&
3385
- !(originalValue instanceof Date)
3386
- ) {
3387
- }
3388
-
3408
if (value === null) {
3409
return null;
3410
}
3411
3412
+ // Special Symbol, that's very common.
3413
+ if (value === REACT_ELEMENT_TYPE) {
3414
+ return '$';
3415
+ }
3416
+
3417
if (typeof value === 'object') {
3418
if (isClientReference(value)) {
3419
// We actually have this value on the client so we could import it.
3445
return existingReference;
3446
}
3447
3424
- if (counter.objectLimit <= 0) {
3448
+ if (counter.objectLimit <= 0 && !doNotLimit.has(value)) {
3449
// We've reached our max number of objects to serialize across the wire so we serialize this
3450
// as a marker so that the client can error when this is accessed by the console.
3451
return serializeLimitedObject();
3465
if (element._debugStack != null) {
3466
// Outline the debug stack so that it doesn't get cut off.
3467
debugStack = filterStackTrace(request, element._debugStack, 1);
3444
- const stackId = outlineConsoleValue(
3445
- request,
3446
- {objectLimit: debugStack.length + 2},
3447
- debugStack,
3448
- );
3449
- request.writtenObjects.set(debugStack, serializeByValueID(stackId));
3468
+ doNotLimit.add(debugStack);
3469
+ for (let i = 0; i < debugStack.length; i++) {
3470
+ doNotLimit.add(debugStack[i]);
3471
+ }
3472
}
3473
+ doNotLimit.add(element.props);
3474
return [
3475
REACT_ELEMENT_TYPE,
3476
element.type,
3615
if (typeof value === 'string') {
3616
if (value[value.length - 1] === 'Z') {
3617
// Possibly a Date, whose toJSON automatically calls toISOString
3618
+ // Make sure that `parent[parentPropertyName]` wasn't JSONified before `value` was passed to us
3619
+ // $FlowFixMe[incompatible-use]
3620
+ const originalValue = parent[parentPropertyName];
3621
if (originalValue instanceof Date) {
3622
return serializeDateFromDateJSON(value);
3623
}
3706
);
3707
}
3708
3709
+ if (typeof model === 'object' && model !== null) {
3710
+ // We can't limit outlined values.
3711
+ doNotLimit.add(model);
3712
+ }
3713
+
3714
function replacer(
3715
this:
3716
| {+[key: string | number]: ReactClientValue}