Skip to content

Commit 133ada7

Browse files
LoganDarkhoxyq
andauthored
Read constructor name more carefully (#29954)
## Summary Sometimes `constructor` happens to be the name of an unrelated property, or we may be dealing with a `Proxy` that intercepts every read. Verify the constructor is a function before using its name, and reset the name anyway if it turns out not to be serializable. Fixes some cases of the devtools crashing and becoming inoperable upon attempting to inspect components whose props are Hookstate `State`s. ## How did you test this change? Installed a patched version of the extension and confirmed that it solves the problem. --------- Co-authored-by: Ruslan Lesiutin <[email protected]>
1 parent 708d8f8 commit 133ada7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ function createDehydrated(
8484
preview_long: formatDataForPreview(data, true),
8585
preview_short: formatDataForPreview(data, false),
8686
name:
87-
!data.constructor || data.constructor.name === 'Object'
87+
typeof data.constructor !== 'function' ||
88+
typeof data.constructor.name !== 'string' ||
89+
data.constructor.name === 'Object'
8890
? ''
8991
: data.constructor.name,
9092
};
@@ -240,7 +242,9 @@ export function dehydrate(
240242
preview_short: formatDataForPreview(data, false),
241243
preview_long: formatDataForPreview(data, true),
242244
name:
243-
!data.constructor || data.constructor.name === 'Object'
245+
typeof data.constructor !== 'function' ||
246+
typeof data.constructor.name !== 'string' ||
247+
data.constructor.name === 'Object'
244248
? ''
245249
: data.constructor.name,
246250
};
@@ -332,7 +336,11 @@ export function dehydrate(
332336
readonly: true,
333337
preview_short: formatDataForPreview(data, false),
334338
preview_long: formatDataForPreview(data, true),
335-
name: data.constructor.name,
339+
name:
340+
typeof data.constructor !== 'function' ||
341+
typeof data.constructor.name !== 'string'
342+
? ''
343+
: data.constructor.name,
336344
};
337345

338346
getAllEnumerableKeys(data).forEach(key => {

0 commit comments

Comments
 (0)