Skip to content

Commit

Permalink
skip reading element for imported data
Browse files Browse the repository at this point in the history
  • Loading branch information
bl00mber committed May 13, 2020
1 parent 6514e4a commit 30a55f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions packages/react-devtools-shared/src/devtools/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ export default class Store extends EventEmitter<{|
}

getElementByID(id: number): Element | null {
if (
this._profilerStore._dataFrontend &&
this._profilerStore._dataFrontend.imported === true
)
return null;
const element = this._idToElement.get(id);
if (element == null) {
console.warn(`No element found with id "${id}"`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ButtonIcon from '../ButtonIcon';
import {StoreContext} from '../context';
import {
prepareProfilingDataExport,
prepareProfilingDataFrontendFromExport,
prepareProfilingDataFrontendFromImport,
} from './utils';
import {downloadFile} from '../utils';

Expand Down Expand Up @@ -77,11 +77,11 @@ export default function ProfilingImportExportButtons() {
fileReader.addEventListener('load', () => {
try {
const raw = ((fileReader.result: any): string);
const profilingDataExport = ((JSON.parse(
const profilingDataImport = ((JSON.parse(
raw,
): any): ProfilingDataExport);
profilerStore.profilingData = prepareProfilingDataFrontendFromExport(
profilingDataExport,
profilerStore.profilingData = prepareProfilingDataFrontendFromImport(
profilingDataImport,
);
} catch (error) {
modalDialogDispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type ProfilingDataForRootFrontend = {|
export type ProfilingDataFrontend = {|
// Profiling data per root.
dataForRoots: Map<number, ProfilingDataForRootFrontend>,
imported: boolean,
|};

export type CommitDataExport = {|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,21 @@ export function prepareProfilingDataFrontendFromBackendAndStore(
);
});

return {dataForRoots};
return {dataForRoots, imported: false};
}

// Converts a Profiling data export into the format required by the Store.
export function prepareProfilingDataFrontendFromExport(
profilingDataExport: ProfilingDataExport,
export function prepareProfilingDataFrontendFromImport(
profilingDataImport: ProfilingDataExport,
): ProfilingDataFrontend {
const {version} = profilingDataExport;
const {version} = profilingDataImport;

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

const dataForRoots: Map<number, ProfilingDataForRootFrontend> = new Map();
profilingDataExport.dataForRoots.forEach(
profilingDataImport.dataForRoots.forEach(
({
commitData,
displayName,
Expand Down Expand Up @@ -156,7 +156,7 @@ export function prepareProfilingDataFrontendFromExport(
},
);

return {dataForRoots};
return {dataForRoots, imported: true};
}

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

0 comments on commit 30a55f0

Please sign in to comment.