Skip to content

Commit dd2e36d

Browse files
bl00mberBrian Vaughn
and
Brian Vaughn
authored
Profiler: Skip reading element for imported data (#18913)
* skip reading element for imported data * rename nodes & enable store lookup for components tab * replace names * Added some more test coverage; reverted rename Co-authored-by: Brian Vaughn <bvaughn@fb.com>
1 parent 7c08090 commit dd2e36d

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,10 @@ describe('ProfilerContext', () => {
337337
await utils.actAsync(() => context.selectFiber(parentID, 'Parent'));
338338
expect(selectedElementID).toBe(parentID);
339339

340-
// We expect a "no element found" warning.
341-
// Let's hide it from the test console though.
342-
spyOn(console, 'warn');
343-
344340
// Select an unmounted element and verify no Components tab selection doesn't change.
345341
await utils.actAsync(() => context.selectFiber(childID, 'Child'));
346342
expect(selectedElementID).toBe(parentID);
347343

348-
expect(console.warn).toHaveBeenCalledWith(
349-
`No element found with id "${childID}"`,
350-
);
351-
352344
done();
353345
});
354346
});

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export function exportImportHelper(bridge: FrontendBridge, store: Store): void {
181181
expect(profilerStore.profilingData).not.toBeNull();
182182

183183
const profilingDataFrontendInitial = ((profilerStore.profilingData: any): ProfilingDataFrontend);
184+
expect(profilingDataFrontendInitial.imported).toBe(false);
184185

185186
const profilingDataExport = prepareProfilingDataExport(
186187
profilingDataFrontendInitial,
@@ -197,15 +198,18 @@ export function exportImportHelper(bridge: FrontendBridge, store: Store): void {
197198
const profilingDataFrontend = prepareProfilingDataFrontendFromExport(
198199
(parsedProfilingDataExport: any),
199200
);
201+
expect(profilingDataFrontend.imported).toBe(true);
200202

201203
// Sanity check that profiling snapshots are serialized correctly.
202-
expect(profilingDataFrontendInitial).toEqual(profilingDataFrontend);
204+
expect(profilingDataFrontendInitial.dataForRoots).toEqual(
205+
profilingDataFrontend.dataForRoots,
206+
);
203207

204208
// Snapshot the JSON-parsed object, rather than the raw string, because Jest formats the diff nicer.
205209
expect(parsedProfilingDataExport).toMatchSnapshot('imported data');
206210

207211
act(() => {
208-
// Apply the new exported-then-reimported data so tests can re-run assertions.
212+
// Apply the new exported-then-imported data so tests can re-run assertions.
209213
profilerStore.profilingData = profilingDataFrontend;
210214
});
211215
}

packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,24 @@ function ProfilerContextController({children}: Props) {
138138
selectFiberName(name);
139139

140140
// Sync selection to the Components tab for convenience.
141-
if (id !== null) {
142-
const element = store.getElementByID(id);
143-
144-
// Keep in mind that profiling data may be from a previous session.
145-
// In that case, IDs may match up arbitrarily; to be safe, compare both ID and display name.
146-
if (element !== null && element.displayName === name) {
141+
// Keep in mind that profiling data may be from a previous session.
142+
// If data has been imported, we should skip the selection sync.
143+
if (
144+
id !== null &&
145+
profilingData !== null &&
146+
profilingData.imported === false
147+
) {
148+
// We should still check to see if this element is still in the store.
149+
// It may have been removed during profiling.
150+
if (store.containsElement(id)) {
147151
dispatch({
148152
type: 'SELECT_ELEMENT_BY_ID',
149153
payload: id,
150154
});
151155
}
152156
}
153157
},
154-
[dispatch, selectFiberID, selectFiberName, store],
158+
[dispatch, selectFiberID, selectFiberName, store, profilingData],
155159
);
156160

157161
const setRootIDAndClearFiber = useCallback(

packages/react-devtools-shared/src/devtools/views/Profiler/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export type ProfilingDataForRootFrontend = {|
105105
export type ProfilingDataFrontend = {|
106106
// Profiling data per root.
107107
dataForRoots: Map<number, ProfilingDataForRootFrontend>,
108+
imported: boolean,
108109
|};
109110

110111
export type CommitDataExport = {|

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function prepareProfilingDataFrontendFromBackendAndStore(
9999
);
100100
});
101101

102-
return {dataForRoots};
102+
return {dataForRoots, imported: false};
103103
}
104104

105105
// Converts a Profiling data export into the format required by the Store.
@@ -156,7 +156,7 @@ export function prepareProfilingDataFrontendFromExport(
156156
},
157157
);
158158

159-
return {dataForRoots};
159+
return {dataForRoots, imported: true};
160160
}
161161

162162
// Converts a Store Profiling data into a format that can be safely (JSON) serialized for export.

0 commit comments

Comments
 (0)