Skip to content

Commit a5e6d0d

Browse files
committed
skip reading element for imported data
1 parent 6514e4a commit a5e6d0d

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('profiling utils', () => {
1616

1717
it('should throw if importing older/unsupported data', () => {
1818
expect(() =>
19-
utils.prepareProfilingDataFrontendFromExport(
19+
utils.prepareProfilingDataFrontendFromImport(
2020
({
2121
version: 0,
2222
dataForRoots: [],

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export function requireTestRenderer(): ReactTestRenderer {
173173
export function exportImportHelper(bridge: FrontendBridge, store: Store): void {
174174
const {
175175
prepareProfilingDataExport,
176-
prepareProfilingDataFrontendFromExport,
176+
prepareProfilingDataFrontendFromImport,
177177
} = require('react-devtools-shared/src/devtools/views/Profiler/utils');
178178

179179
const {profilerStore} = store;
@@ -194,18 +194,18 @@ export function exportImportHelper(bridge: FrontendBridge, store: Store): void {
194194
);
195195
const parsedProfilingDataExport = JSON.parse(serializedProfilingDataExport);
196196

197-
const profilingDataFrontend = prepareProfilingDataFrontendFromExport(
197+
const profilingDataFrontendImport = prepareProfilingDataFrontendFromImport(
198198
(parsedProfilingDataExport: any),
199199
);
200200

201201
// Sanity check that profiling snapshots are serialized correctly.
202-
expect(profilingDataFrontendInitial).toEqual(profilingDataFrontend);
202+
expect(profilingDataFrontendInitial.dataForRoots).toEqual(profilingDataFrontendImport.dataForRoots);
203203

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

207207
act(() => {
208-
// Apply the new exported-then-reimported data so tests can re-run assertions.
209-
profilerStore.profilingData = profilingDataFrontend;
208+
// Apply the new exported-then-imported data so tests can re-run assertions.
209+
profilerStore.profilingData = profilingDataFrontendImport;
210210
});
211211
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ export default class Store extends EventEmitter<{|
416416
}
417417

418418
getElementByID(id: number): Element | null {
419+
if (
420+
this._profilerStore._dataFrontend &&
421+
this._profilerStore._dataFrontend.imported === true
422+
)
423+
return null;
419424
const element = this._idToElement.get(id);
420425
if (element == null) {
421426
console.warn(`No element found with id "${id}"`);

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import ButtonIcon from '../ButtonIcon';
1616
import {StoreContext} from '../context';
1717
import {
1818
prepareProfilingDataExport,
19-
prepareProfilingDataFrontendFromExport,
19+
prepareProfilingDataFrontendFromImport,
2020
} from './utils';
2121
import {downloadFile} from '../utils';
2222

@@ -77,11 +77,11 @@ export default function ProfilingImportExportButtons() {
7777
fileReader.addEventListener('load', () => {
7878
try {
7979
const raw = ((fileReader.result: any): string);
80-
const profilingDataExport = ((JSON.parse(
80+
const profilingDataImport = ((JSON.parse(
8181
raw,
8282
): any): ProfilingDataExport);
83-
profilerStore.profilingData = prepareProfilingDataFrontendFromExport(
84-
profilingDataExport,
83+
profilerStore.profilingData = prepareProfilingDataFrontendFromImport(
84+
profilingDataImport,
8585
);
8686
} catch (error) {
8787
modalDialogDispatch({

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

+1
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,21 @@ 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.
106-
export function prepareProfilingDataFrontendFromExport(
107-
profilingDataExport: ProfilingDataExport,
106+
export function prepareProfilingDataFrontendFromImport(
107+
profilingDataImport: ProfilingDataExport,
108108
): ProfilingDataFrontend {
109-
const {version} = profilingDataExport;
109+
const {version} = profilingDataImport;
110110

111111
if (version !== PROFILER_EXPORT_VERSION) {
112112
throw Error(`Unsupported profiler export version "${version}"`);
113113
}
114114

115115
const dataForRoots: Map<number, ProfilingDataForRootFrontend> = new Map();
116-
profilingDataExport.dataForRoots.forEach(
116+
profilingDataImport.dataForRoots.forEach(
117117
({
118118
commitData,
119119
displayName,
@@ -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)