GeezerVison is showing github.com — DevTools bug fix: Proxied methods should be safely dehydrated for dis… · react/react@b6e1d08
File treeExpand file treeCollapse file tree Open diff view settings react-devtools-extensions/src react-devtools-shared/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-extensions/src/backend.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,7 +72,7 @@ function setup(hook) { | 72 | 72 | initBackend(hook, agent, window); | 73 | 73 |
| 74 | 74 | // 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. | 76 | 76 | bridge.send('extensionBackendInitialized'); | 77 | 77 |
| 78 | 78 | // Setup React Native style editor if a renderer like react-native-web has injected it. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/__snapshots__/inspectedElementContext-test.js.snap +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -541,6 +541,7 @@ exports[`InspectedElementContext should support complex data types: 1: Inspected | 541 | 541 | "object_of_objects": { | 542 | 542 | "inner": {} | 543 | 543 | }, | | 544 | + "proxy": {}, | 544 | 545 | "react_element": {}, | 545 | 546 | "regexp": {}, | 546 | 547 | "set": { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/__tests__/inspectedElementContext-test.js +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -549,6 +549,14 @@ describe('InspectedElementContext', () => { | 549 | 549 | } | 550 | 550 | const instance = new Class(); | 551 | 551 |
| | 552 | + const proxyInstance = new Proxy(() => {}, { | | 553 | + get: function(_, name) { | | 554 | + return function() { | | 555 | + return null; | | 556 | + }; | | 557 | + }, | | 558 | + }); | | 559 | + | 552 | 560 | const container = document.createElement('div'); | 553 | 561 | await utils.actAsync(() => | 554 | 562 | ReactDOM.render( | @@ -567,6 +575,7 @@ describe('InspectedElementContext', () => { | 567 | 575 | map={mapShallow} | 568 | 576 | map_of_maps={mapOfMaps} | 569 | 577 | object_of_objects={objectOfObjects} | | 578 | + proxy={proxyInstance} | 570 | 579 | react_element={<span />} | 571 | 580 | regexp={/abc/giu} | 572 | 581 | set={setShallow} | @@ -619,6 +628,7 @@ describe('InspectedElementContext', () => { | 619 | 628 | map, | 620 | 629 | map_of_maps, | 621 | 630 | object_of_objects, | | 631 | + proxy, | 622 | 632 | react_element, | 623 | 633 | regexp, | 624 | 634 | set, | @@ -722,6 +732,12 @@ describe('InspectedElementContext', () => { | 722 | 732 | ); | 723 | 733 | expect(object_of_objects.inner[meta.preview_short]).toBe('{…}'); | 724 | 734 |
| | 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 | + | 725 | 741 | expect(react_element[meta.inspectable]).toBe(false); | 726 | 742 | expect(react_element[meta.name]).toBe('span'); | 727 | 743 | expect(react_element[meta.type]).toBe('react_element'); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/hydration.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -151,7 +151,10 @@ export function dehydrate( | 151 | 151 | inspectable: false, | 152 | 152 | preview_short: formatDataForPreview(data, false), | 153 | 153 | preview_long: formatDataForPreview(data, true), | 154 | | - name: data.name || 'function', | | 154 | + name: | | 155 | + typeof data.name === 'function' || !data.name | | 156 | + ? 'function' | | 157 | + : data.name, | 155 | 158 | type, | 156 | 159 | }; | 157 | 160 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/utils.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -539,7 +539,9 @@ export function formatDataForPreview( | 539 | 539 | case 'html_element': | 540 | 540 | return `<${truncateForDisplay(data.tagName.toLowerCase())} />`; | 541 | 541 | case 'function': | 542 | | - return truncateForDisplay(`ƒ ${data.name}() {}`); | | 542 | + return truncateForDisplay( | | 543 | + `ƒ ${typeof data.name === 'function' ? '' : data.name}() {}`, | | 544 | + ); | 543 | 545 | case 'string': | 544 | 546 | return `"${data}"`; | 545 | 547 | case 'bigint': | |
|