From 7008ec78162ddc10dd5c5a75f1c456f6fae23fd4 Mon Sep 17 00:00:00 2001 From: Jason Laster Date: Thu, 20 Dec 2018 10:08:35 -0500 Subject: [PATCH] Bug 1515644 - [release 110] [sources] don't make newSources (a)wait on source maps to be loaded (#7302). r=davidwalsh --- .../new/src/actions/sources/newSources.js | 37 ++++++++++++------- .../debugger/new/src/client/firefox/events.js | 4 +- .../debugger/new/src/utils/source-queue.js | 22 ++++++----- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/devtools/client/debugger/new/src/actions/sources/newSources.js b/devtools/client/debugger/new/src/actions/sources/newSources.js index b560624c1f5b..8bb2d2996b5b 100644 --- a/devtools/client/debugger/new/src/actions/sources/newSources.js +++ b/devtools/client/debugger/new/src/actions/sources/newSources.js @@ -26,6 +26,7 @@ import { } from "../../selectors"; import { prefs } from "../../utils/prefs"; +import sourceQueue from "../../utils/source-queue"; import type { Source, SourceId } from "../../types"; import type { Action, ThunkArgs } from "../types"; @@ -46,20 +47,24 @@ function createOriginalSource( }; } -function loadSourceMaps(sources) { - return async function({ dispatch, sourceMaps }: ThunkArgs) { +function loadSourceMaps(sources: Source[]) { + return async function({ + dispatch, + sourceMaps + }: ThunkArgs): Promise[]> { if (!prefs.clientSourceMapsEnabled) { - return; + return []; } - let originalSources = await Promise.all( - sources.map(({ id }) => dispatch(loadSourceMap(id))) + return flatten( + await Promise.all( + sources.map(async ({ id }) => { + const originalSources = await dispatch(loadSourceMap(id)); + sourceQueue.queueSources(originalSources); + return originalSources; + }) + ) ); - - originalSources = flatten(originalSources).filter(Boolean); - if (originalSources.length > 0) { - await dispatch(newSources(originalSources)); - } }; } @@ -68,11 +73,15 @@ function loadSourceMaps(sources) { * @static */ function loadSourceMap(sourceId: SourceId) { - return async function({ dispatch, getState, sourceMaps }: ThunkArgs) { + return async function({ + dispatch, + getState, + sourceMaps + }: ThunkArgs): Promise { const source = getSource(getState(), sourceId); if (!source || isOriginal(source) || !source.sourceMapURL) { - return; + return []; } let urls = null; @@ -97,7 +106,7 @@ function loadSourceMap(sourceId: SourceId) { source: (({ ...currentSource, sourceMapURL: "" }: any): Source) }: Action) ); - return; + return []; } return urls.map(url => createOriginalSource(url, source, sourceMaps)); @@ -197,7 +206,7 @@ export function newSources(sources: Source[]) { dispatch(({ type: "ADD_SOURCES", sources: sources }: Action)); - await dispatch(loadSourceMaps(sources)); + dispatch(loadSourceMaps(sources)); for (const source of sources) { dispatch(checkSelectedSource(source.id)); diff --git a/devtools/client/debugger/new/src/client/firefox/events.js b/devtools/client/debugger/new/src/client/firefox/events.js index 70a5d929c9b4..3532a95539e1 100644 --- a/devtools/client/debugger/new/src/client/firefox/events.js +++ b/devtools/client/debugger/new/src/client/firefox/events.js @@ -32,7 +32,7 @@ function setupEvents(dependencies: Dependencies) { threadClient = dependencies.threadClient; actions = dependencies.actions; supportsWasm = dependencies.supportsWasm; - sourceQueue.initialize({ actions, supportsWasm, createSource }); + sourceQueue.initialize(actions); if (threadClient) { Object.keys(clientEvents).forEach(eventName => { @@ -98,7 +98,7 @@ function resumed(_: "resumed", packet: ResumedPacket) { } function newSource(_: "newSource", { source }: SourcePacket) { - sourceQueue.queue(source); + sourceQueue.queue(createSource(source, { supportsWasm })); } function workerListChanged() { diff --git a/devtools/client/debugger/new/src/utils/source-queue.js b/devtools/client/debugger/new/src/utils/source-queue.js index 4c6428df8ad8..64c9eeaa6e97 100644 --- a/devtools/client/debugger/new/src/utils/source-queue.js +++ b/devtools/client/debugger/new/src/utils/source-queue.js @@ -2,11 +2,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ +// @flow + import { throttle } from "lodash"; +import type { Source } from "../types"; let newSources; -let createSource; -let supportsWasm = false; let queuedSources; let currentWork; @@ -14,24 +15,25 @@ async function dispatchNewSources() { const sources = queuedSources; queuedSources = []; - currentWork = await newSources( - sources.map(source => createSource(source, { supportsWasm })) - ); + currentWork = await newSources(sources); } const queue = throttle(dispatchNewSources, 100); export default { - initialize: options => { - newSources = options.actions.newSources; - createSource = options.createSource; - supportsWasm = options.supportsWasm; + initialize: (actions: Object) => { + newSources = actions.newSources; queuedSources = []; }, - queue: source => { + queue: (source: Source) => { queuedSources.push(source); queue(); }, + queueSources: (sources: Source[]) => { + queuedSources = queuedSources.concat(sources); + queue(); + }, + flush: () => Promise.all([queue.flush(), currentWork]), clear: () => queue.cancel() };