16
setInObject,
17
} from 'react-devtools-shared/src/utils';
18
19
+import {REACT_LEGACY_ELEMENT_TYPE} from 'shared/ReactSymbols';
20
+
21
import type {
22
DehydratedData,
23
InspectedElementPath,
190
type,
191
};
192
191
- // React Elements aren't very inspector-friendly,
192
- // and often contain private fields or circular references.
193
- case 'react_element':
194
- cleaned.push(path);
195
- return {
196
- inspectable: false,
193
+ case 'react_element': {
194
+ isPathAllowedCheck = isPathAllowed(path);
195
+
196
+ if (level >= LEVEL_THRESHOLD && !isPathAllowedCheck) {
197
+ cleaned.push(path);
198
+ return {
199
+ inspectable: true,
200
+ preview_short: formatDataForPreview(data, false),
201
+ preview_long: formatDataForPreview(data, true),
202
+ name: getDisplayNameForReactElement(data) || 'Unknown',
203
+ type,
204
+ };
205
+ }
206
+
207
+ const unserializableValue: Unserializable = {
208
+ unserializable: true,
209
+ type,
210
+ readonly: true,
211
preview_short: formatDataForPreview(data, false),
212
preview_long: formatDataForPreview(data, true),
213
name: getDisplayNameForReactElement(data) || 'Unknown',
200
- type,
214
};
215
+ // TODO: We can't expose type because that name is already taken on Unserializable.
216
+ unserializableValue.key = dehydrate(
217
+ data.key,
218
+ cleaned,
219
+ unserializable,
220
+ path.concat(['key']),
221
+ isPathAllowed,
222
+ isPathAllowedCheck ? 1 : level + 1,
223
+ );
224
+ if (data.$$typeof === REACT_LEGACY_ELEMENT_TYPE) {
225
+ unserializableValue.ref = dehydrate(
226
+ data.ref,
227
+ cleaned,
228
+ unserializable,
229
+ path.concat(['ref']),
230
+ isPathAllowed,
231
+ isPathAllowedCheck ? 1 : level + 1,
232
+ );
233
+ }
234
+ unserializableValue.props = dehydrate(
235
+ data.props,
236
+ cleaned,
237
+ unserializable,
238
+ path.concat(['props']),
239
+ isPathAllowed,
240
+ isPathAllowedCheck ? 1 : level + 1,
241
+ );
242
243
+ unserializable.push(path);
244
+ return unserializableValue;
245
+ }
246
+ case 'react_lazy': {
247
+ isPathAllowedCheck = isPathAllowed(path);
248
+
249
+ const payload = data._payload;
250
+
251
+ if (level >= LEVEL_THRESHOLD && !isPathAllowedCheck) {
252
+ cleaned.push(path);
253
+ const inspectable =
254
+ payload !== null &&
255
+ typeof payload === 'object' &&
256
+ (payload._status === 1 ||
257
+ payload._status === 2 ||
258
+ payload.status === 'fulfilled' ||
259
+ payload.status === 'rejected');
260
+ return {
261
+ inspectable,
262
+ preview_short: formatDataForPreview(data, false),
263
+ preview_long: formatDataForPreview(data, true),
264
+ name: 'lazy()',
265
+ type,
266
+ };
267
+ }
268
+
269
+ const unserializableValue: Unserializable = {
270
+ unserializable: true,
271
+ type: type,
272
+ preview_short: formatDataForPreview(data, false),
273
+ preview_long: formatDataForPreview(data, true),
274
+ name: 'lazy()',
275
+ };
276
+ // Ideally we should alias these properties to something more readable but
277
+ // unfortunately because of how the hydration algorithm uses a single concept of
278
+ // "path" we can't alias the path.
279
+ unserializableValue._payload = dehydrate(
280
+ payload,
281
+ cleaned,
282
+ unserializable,
283
+ path.concat(['_payload']),
284
+ isPathAllowed,
285
+ isPathAllowedCheck ? 1 : level + 1,
286
+ );
287
+ unserializable.push(path);
288
+ return unserializableValue;
289
+ }
290
// ArrayBuffers error if you try to inspect them.
291
case 'array_buffer':
292
case 'data_view':
396
isPathAllowedCheck = isPathAllowed(path);
397
398
if (level >= LEVEL_THRESHOLD && !isPathAllowedCheck) {
399
+ cleaned.push(path);
400
return {
401
inspectable:
402
data.status === 'fulfilled' || data.status === 'rejected',