Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/react-devtools-shared/src/__tests__/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
getDisplayName,
getDisplayNameForReactElement,
isPlainObject,
parseElementDisplayNameFromBackend,
} from 'react-devtools-shared/src/utils';
import {ElementTypeMemo} from 'react-devtools-shared/src/frontend/types';
import {stackToComponentLocations} from 'react-devtools-shared/src/devtools/utils';
import {
formatConsoleArguments,
Expand Down Expand Up @@ -82,6 +84,21 @@ describe('utils', () => {
});
});

describe('parseElementDisplayNameFromBackend', () => {
it('should identify Forget inside HOC wrappers', () => {
expect(
parseElementDisplayNameFromBackend(
'Memo(Forget(Example))',
ElementTypeMemo,
),
).toEqual({
formattedDisplayName: 'Example',
hocDisplayNames: ['Memo'],
compiledWithForget: true,
});
});
});

describe('getDisplayNameForReactElement', () => {
// @reactVersion >= 16.0
it('should return correct display name for an element with function type', () => {
Expand Down
16 changes: 15 additions & 1 deletion packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,25 @@ export function parseElementDisplayNameFromBackend(
break;
}

let compiledWithForget = false;
if (hocDisplayNames !== null) {
const forgetIndex = hocDisplayNames.indexOf('Forget');
if (forgetIndex >= 0) {
compiledWithForget = true;
hocDisplayNames = hocDisplayNames.filter(
hocDisplayName => hocDisplayName !== 'Forget',
);
if (hocDisplayNames.length === 0) {
hocDisplayNames = null;
}
}
}

return {
// $FlowFixMe[incompatible-return]
formattedDisplayName: displayName,
hocDisplayNames,
compiledWithForget: false,
compiledWithForget,
};
}

Expand Down