diff --git a/devtools/client/debugger/src/actions/sources/breakableLines.js b/devtools/client/debugger/src/actions/sources/breakableLines.js index 98d0b49a3717d1..cec8357221df89 100644 --- a/devtools/client/debugger/src/actions/sources/breakableLines.js +++ b/devtools/client/debugger/src/actions/sources/breakableLines.js @@ -5,6 +5,7 @@ import { getBreakableLines, getSourceActorBreakableLines, + getSourceActorsForSource, } from "../../selectors/index"; import { setBreakpointPositions } from "../breakpoints/breakpointPositions"; @@ -22,47 +23,93 @@ function calculateBreakableLines(positions) { /** * Ensure that breakable lines for a given source are fetched. * + * This method is memoized, so that if concurrent calls are dispatched, + * it will return the first async promise processing the breakable lines. + * * @param Object location */ export function setBreakableLines(location) { return async ({ getState, dispatch, client }) => { - let breakableLines; if (location.source.isOriginal) { - const positions = await dispatch(setBreakpointPositions(location)); - breakableLines = calculateBreakableLines(positions); - - const existingBreakableLines = getBreakableLines( - getState(), - location.source.id - ); - if (existingBreakableLines) { - breakableLines = [ - ...new Set([...existingBreakableLines, ...breakableLines]), - ]; + // Original sources have a dedicated codepath to fetch locations + // from the generated source actor and then map them to "positions" + // in the original source. + let promise = getBreakableLines(getState(), location.source.id); + if (promise) { + return promise; } - + promise = (async () => { + const positions = await dispatch(setBreakpointPositions(location)); + return calculateBreakableLines(positions); + })(); + dispatch({ + type: "SET_ORIGINAL_BREAKABLE_LINES", + source: location.source, + promise, + }); + const breakableLines = await promise; dispatch({ type: "SET_ORIGINAL_BREAKABLE_LINES", source: location.source, breakableLines, }); + } else if (location.source.isHTML) { + // For a given HTML page, we get a unique Source (for the html page), + // but many Source Actors (one per inline