Skip to content

Commit 49af889

Browse files
authored
Fix DevTools crash when inspecting document.all (#19619)
* Add html_all_collection type to correct typeof document.all * process HTMLAllCollection like HTMLElement + fix flow issue * fix lint * move flow fix comment * Make it work with iframes too * optimize how we get html_all_collection type * use once Object.prototype.toString.call
1 parent d6e4338 commit 49af889

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/react-devtools-shared/src/hydration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export function dehydrate(
222222
),
223223
);
224224

225+
case 'html_all_collection':
225226
case 'typed_array':
226227
case 'iterator':
227228
isPathAllowedCheck = isPathAllowed(path);

packages/react-devtools-shared/src/utils.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ export type DataType =
372372
| 'data_view'
373373
| 'date'
374374
| 'function'
375+
| 'html_all_collection'
375376
| 'html_element'
376377
| 'infinity'
377378
| 'iterator'
@@ -438,14 +439,26 @@ export function getDataType(data: Object): DataType {
438439
return 'iterator';
439440
} else if (data.constructor && data.constructor.name === 'RegExp') {
440441
return 'regexp';
441-
} else if (Object.prototype.toString.call(data) === '[object Date]') {
442-
return 'date';
442+
} else {
443+
const toStringValue = Object.prototype.toString.call(data);
444+
if (toStringValue === '[object Date]') {
445+
return 'date';
446+
} else if (toStringValue === '[object HTMLAllCollection]') {
447+
return 'html_all_collection';
448+
}
443449
}
444450
return 'object';
445451
case 'string':
446452
return 'string';
447453
case 'symbol':
448454
return 'symbol';
455+
case 'undefined':
456+
if (
457+
Object.prototype.toString.call(data) === '[object HTMLAllCollection]'
458+
) {
459+
return 'html_all_collection';
460+
}
461+
return 'undefined';
449462
default:
450463
return 'unknown';
451464
}

0 commit comments

Comments
 (0)