Skip to content

Commit 7be3d1c

Browse files
rafecafacebook-github-bot
authored andcommitted
Make the chrome debugger handle dynamic delta ids
Differential Revision: D7112419 fbshipit-source-id: 1d80c0c13144dd19bbcd5535383befc6567cacf7
1 parent 7216079 commit 7be3d1c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

local-cli/server/util/debugger-ui/DeltaPatcher.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
pre: new Map(),
3131
post: new Map(),
3232
modules: new Map(),
33+
id: undefined,
3334
};
3435
this._initialized = false;
3536
this._lastNumModifiedFiles = 0;
@@ -66,6 +67,7 @@
6667
pre: new Map(),
6768
post: new Map(),
6869
modules: new Map(),
70+
id: undefined,
6971
};
7072
}
7173

@@ -80,9 +82,15 @@
8082
this._patchMap(this._lastBundle.post, deltaBundle.post);
8183
this._patchMap(this._lastBundle.modules, deltaBundle.delta);
8284

85+
this._lastBundle.id = deltaBundle.id;
86+
8387
return this;
8488
}
8589

90+
getLastBundleId() {
91+
return this._lastBundle.id;
92+
}
93+
8694
/**
8795
* Returns the number of modified files in the last received Delta. This is
8896
* currently used to populate the `X-Metro-Files-Changed-Count` HTTP header

local-cli/server/util/debugger-ui/deltaUrlToBlobUrl.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,34 @@
2020
* whole JS bundle Blob.
2121
*/
2222
async function deltaUrlToBlobUrl(deltaUrl) {
23-
let cachedBundle = cachedBundleUrls.get(deltaUrl);
23+
const client = global.DeltaPatcher.get(deltaUrl);
2424

25-
const deltaBundleId = cachedBundle
26-
? `&deltaBundleId=${cachedBundle.id}`
25+
const deltaBundleId = client.getLastBundleId()
26+
? `&deltaBundleId=${client.getLastBundleId()}`
2727
: '';
2828

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

32-
const deltaPatcher = global.DeltaPatcher.get(bundle.id).applyDelta({
32+
const deltaPatcher = client.applyDelta({
33+
id: bundle.id,
3334
pre: new Map(bundle.pre),
3435
post: new Map(bundle.post),
3536
delta: new Map(bundle.delta),
3637
reset: bundle.reset,
3738
});
3839

40+
let cachedBundle = cachedBundleUrls.get(deltaUrl);
41+
3942
// If nothing changed, avoid recreating a bundle blob by reusing the
4043
// previous one.
4144
if (deltaPatcher.getLastNumModifiedFiles() === 0 && cachedBundle) {
42-
return cachedBundle.url;
45+
return cachedBundle;
4346
}
4447

4548
// Clean up the previous bundle URL to not leak memory.
4649
if (cachedBundle) {
47-
URL.revokeObjectURL(cachedBundle.url);
50+
URL.revokeObjectURL(cachedBundle);
4851
}
4952

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

61-
const bundleUrl = URL.createObjectURL(blob);
62-
cachedBundleUrls.set(deltaUrl, {
63-
id: bundle.id,
64-
url: bundleUrl,
65-
});
64+
const bundleContents = URL.createObjectURL(blob);
65+
cachedBundleUrls.set(deltaUrl, bundleContents);
6666

67-
return bundleUrl;
67+
return bundleContents;
6868
}
6969

7070
global.deltaUrlToBlobUrl = deltaUrlToBlobUrl;

0 commit comments

Comments
 (0)