Bug 1515644 - [release 110] [sources] don't make newSources (a)wait on source maps to be loaded (#7302). r=davidwalsh

This commit is contained in:
Jason Laster 2018-12-20 10:08:35 -05:00
parent 39f03906f2
commit 7008ec7816
3 changed files with 37 additions and 26 deletions

View File

@ -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<Promise<Source>[]> {
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<Source[]> {
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));

View File

@ -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() {

View File

@ -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 <http://mozilla.org/MPL/2.0/>. */
// @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()
};