Skip to content

Commit b6e1d08

Browse files
authored
DevTools bug fix: Proxied methods should be safely dehydrated for display
1 parent b8ed6a1 commit b6e1d08

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

packages/react-devtools-extensions/src/backend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function setup(hook) {
7272
initBackend(hook, agent, window);
7373

7474
// Let the frontend know that the backend has attached listeners and is ready for messages.
75-
// This covers the case of of syncing saved values after reloading/navigating while DevTools remain open.
75+
// This covers the case of syncing saved values after reloading/navigating while DevTools remain open.
7676
bridge.send('extensionBackendInitialized');
7777

7878
// Setup React Native style editor if a renderer like react-native-web has injected it.

packages/react-devtools-shared/src/__tests__/__snapshots__/inspectedElementContext-test.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ exports[`InspectedElementContext should support complex data types: 1: Inspected
541541
"object_of_objects": {
542542
"inner": {}
543543
},
544+
"proxy": {},
544545
"react_element": {},
545546
"regexp": {},
546547
"set": {

packages/react-devtools-shared/src/__tests__/inspectedElementContext-test.js

+16
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,14 @@ describe('InspectedElementContext', () => {
549549
}
550550
const instance = new Class();
551551

552+
const proxyInstance = new Proxy(() => {}, {
553+
get: function(_, name) {
554+
return function() {
555+
return null;
556+
};
557+
},
558+
});
559+
552560
const container = document.createElement('div');
553561
await utils.actAsync(() =>
554562
ReactDOM.render(
@@ -567,6 +575,7 @@ describe('InspectedElementContext', () => {
567575
map={mapShallow}
568576
map_of_maps={mapOfMaps}
569577
object_of_objects={objectOfObjects}
578+
proxy={proxyInstance}
570579
react_element={<span />}
571580
regexp={/abc/giu}
572581
set={setShallow}
@@ -619,6 +628,7 @@ describe('InspectedElementContext', () => {
619628
map,
620629
map_of_maps,
621630
object_of_objects,
631+
proxy,
622632
react_element,
623633
regexp,
624634
set,
@@ -722,6 +732,12 @@ describe('InspectedElementContext', () => {
722732
);
723733
expect(object_of_objects.inner[meta.preview_short]).toBe('{…}');
724734

735+
expect(proxy[meta.inspectable]).toBe(false);
736+
expect(proxy[meta.name]).toBe('function');
737+
expect(proxy[meta.type]).toBe('function');
738+
expect(proxy[meta.preview_long]).toBe('ƒ () {}');
739+
expect(proxy[meta.preview_short]).toBe('ƒ () {}');
740+
725741
expect(react_element[meta.inspectable]).toBe(false);
726742
expect(react_element[meta.name]).toBe('span');
727743
expect(react_element[meta.type]).toBe('react_element');

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ export function dehydrate(
151151
inspectable: false,
152152
preview_short: formatDataForPreview(data, false),
153153
preview_long: formatDataForPreview(data, true),
154-
name: data.name || 'function',
154+
name:
155+
typeof data.name === 'function' || !data.name
156+
? 'function'
157+
: data.name,
155158
type,
156159
};
157160

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,9 @@ export function formatDataForPreview(
539539
case 'html_element':
540540
return `<${truncateForDisplay(data.tagName.toLowerCase())} />`;
541541
case 'function':
542-
return truncateForDisplay(${data.name}() {}`);
542+
return truncateForDisplay(
543+
${typeof data.name === 'function' ? '' : data.name}() {}`,
544+
);
543545
case 'string':
544546
return `"${data}"`;
545547
case 'bigint':

0 commit comments

Comments
 (0)