Skip to content

Commit e52fe9f

Browse files
jasonLasterdarkwing
authored andcommitted
[breakpoints] Fix timing issue with syncing breakpoints (firefox-devtools#6553)
1 parent 70e2361 commit e52fe9f

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/actions/breakpoints.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,20 @@ export function syncBreakpoint(
5252
pendingBreakpoint: PendingBreakpoint
5353
) {
5454
return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
55-
const { breakpoint, previousLocation } = await syncClientBreakpoint(
55+
const response = await syncClientBreakpoint(
5656
getState,
5757
client,
5858
sourceMaps,
5959
sourceId,
6060
pendingBreakpoint
6161
);
6262

63+
if (!response) {
64+
return;
65+
}
66+
67+
const { breakpoint, previousLocation } = response;
68+
6369
return dispatch(
6470
({
6571
type: "SYNC_BREAKPOINT",

src/actions/breakpoints/syncBreakpoint.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { getGeneratedLocation } from "../../utils/source-maps";
1515
import { getTextAtPosition } from "../../utils/source";
1616
import { originalToGeneratedId } from "devtools-source-map";
17-
import { getSourceFromId } from "../../selectors";
17+
import { getSource } from "../../selectors";
1818
import type {
1919
Location,
2020
ASTLocation,
@@ -76,16 +76,20 @@ export async function syncClientBreakpoint(
7676
sourceMaps: Object,
7777
sourceId: SourceId,
7878
pendingBreakpoint: PendingBreakpoint
79-
): Promise<BreakpointSyncData> {
79+
): Promise<BreakpointSyncData | null> {
8080
assertPendingBreakpoint(pendingBreakpoint);
8181

82-
const source = getSourceFromId(getState(), sourceId);
82+
const source = getSource(getState(), sourceId);
8383

8484
const generatedSourceId = sourceMaps.isOriginalId(sourceId)
8585
? originalToGeneratedId(sourceId)
8686
: sourceId;
8787

88-
const generatedSource = getSourceFromId(getState(), generatedSourceId);
88+
const generatedSource = getSource(getState(), generatedSourceId);
89+
90+
if (!source) {
91+
return null;
92+
}
8993

9094
const { location, astLocation } = pendingBreakpoint;
9195
const previousLocation = { ...location, sourceId };

src/actions/sources/newSources.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ function checkPendingBreakpoints(sourceId: string) {
136136
// load the source text if there is a pending breakpoint for it
137137
await dispatch(loadSourceText(source));
138138

139-
const pendingBreakpointsArray = pendingBreakpoints.valueSeq().toJS();
140-
for (const pendingBreakpoint of pendingBreakpointsArray) {
141-
await dispatch(syncBreakpoint(sourceId, pendingBreakpoint));
142-
}
139+
const breakpoints = pendingBreakpoints.valueSeq().toJS();
140+
await Promise.all(
141+
breakpoints.map(bp => dispatch(syncBreakpoint(sourceId, bp)))
142+
);
143143
};
144144
}
145145

src/utils/source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export function isLoading(source: Source) {
334334
return source.loadedState === "loading";
335335
}
336336

337-
export function getTextAtPosition(source: Source, location: Location) {
337+
export function getTextAtPosition(source: ?Source, location: Location) {
338338
if (!source || !source.text || source.isWasm) {
339339
return "";
340340
}

0 commit comments

Comments
 (0)