Skip to content

Commit f724a9f

Browse files
committed
fix value formatting of proxies of class instances
For Hookstate Proxies of classes, `data.constructor.name` returns `Proxy({})`, so use `Object.getPrototypeOf(data).constructor.name` instead in that case.
1 parent d814852 commit f724a9f

File tree

1 file changed

+19
-1
lines changed
  • packages/react-devtools-shared/src

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,25 @@ export function formatDataForPreview(
915915
case 'date':
916916
return data.toString();
917917
case 'class_instance':
918-
return data.constructor.name;
918+
try {
919+
let resolvedConstructorName = data.constructor.name;
920+
if (typeof resolvedConstructorName === 'string') {
921+
return resolvedConstructorName;
922+
}
923+
924+
resolvedConstructorName = Object.getPrototypeOf(data).constructor.name;
925+
if (typeof resolvedConstructorName === 'string') {
926+
return resolvedConstructorName;
927+
}
928+
929+
try {
930+
return truncateForDisplay(String(data));
931+
} catch (error) {
932+
return 'unserializable';
933+
}
934+
} catch (error) {
935+
return 'unserializable';
936+
}
919937
case 'object':
920938
if (showFormattedValue) {
921939
const keys = Array.from(getAllEnumerableKeys(data)).sort(alphaSortKeys);

0 commit comments

Comments
 (0)