Skip to content

Commit

Permalink
Make the chrome debugger handle dynamic delta ids
Browse files Browse the repository at this point in the history
Differential Revision: D7112419

fbshipit-source-id: 1d80c0c13144dd19bbcd5535383befc6567cacf7
  • Loading branch information
rafeca authored and facebook-github-bot committed Mar 2, 2018
1 parent 7216079 commit 7be3d1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
8 changes: 8 additions & 0 deletions local-cli/server/util/debugger-ui/DeltaPatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
pre: new Map(),
post: new Map(),
modules: new Map(),
id: undefined,
};
this._initialized = false;
this._lastNumModifiedFiles = 0;
Expand Down Expand Up @@ -66,6 +67,7 @@
pre: new Map(),
post: new Map(),
modules: new Map(),
id: undefined,
};
}

Expand All @@ -80,9 +82,15 @@
this._patchMap(this._lastBundle.post, deltaBundle.post);
this._patchMap(this._lastBundle.modules, deltaBundle.delta);

this._lastBundle.id = deltaBundle.id;

return this;
}

getLastBundleId() {
return this._lastBundle.id;
}

/**
* Returns the number of modified files in the last received Delta. This is
* currently used to populate the `X-Metro-Files-Changed-Count` HTTP header
Expand Down
24 changes: 12 additions & 12 deletions local-cli/server/util/debugger-ui/deltaUrlToBlobUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,34 @@
* whole JS bundle Blob.
*/
async function deltaUrlToBlobUrl(deltaUrl) {
let cachedBundle = cachedBundleUrls.get(deltaUrl);
const client = global.DeltaPatcher.get(deltaUrl);

const deltaBundleId = cachedBundle
? `&deltaBundleId=${cachedBundle.id}`
const deltaBundleId = client.getLastBundleId()
? `&deltaBundleId=${client.getLastBundleId()}`
: '';

const data = await fetch(deltaUrl + deltaBundleId);
const bundle = await data.json();

const deltaPatcher = global.DeltaPatcher.get(bundle.id).applyDelta({
const deltaPatcher = client.applyDelta({
id: bundle.id,
pre: new Map(bundle.pre),
post: new Map(bundle.post),
delta: new Map(bundle.delta),
reset: bundle.reset,
});

let cachedBundle = cachedBundleUrls.get(deltaUrl);

// If nothing changed, avoid recreating a bundle blob by reusing the
// previous one.
if (deltaPatcher.getLastNumModifiedFiles() === 0 && cachedBundle) {
return cachedBundle.url;
return cachedBundle;
}

// Clean up the previous bundle URL to not leak memory.
if (cachedBundle) {
URL.revokeObjectURL(cachedBundle.url);
URL.revokeObjectURL(cachedBundle);
}

// To make Source Maps work correctly, we need to add a newline between
Expand All @@ -58,13 +61,10 @@
type: 'application/javascript',
});

const bundleUrl = URL.createObjectURL(blob);
cachedBundleUrls.set(deltaUrl, {
id: bundle.id,
url: bundleUrl,
});
const bundleContents = URL.createObjectURL(blob);
cachedBundleUrls.set(deltaUrl, bundleContents);

return bundleUrl;
return bundleContents;
}

global.deltaUrlToBlobUrl = deltaUrlToBlobUrl;
Expand Down

0 comments on commit 7be3d1c

Please sign in to comment.