mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 16:10:58 +00:00
Make the chrome debugger handle dynamic delta ids
Differential Revision: D7112419 fbshipit-source-id: 1d80c0c13144dd19bbcd5535383befc6567cacf7
This commit is contained in:
parent
7216079a79
commit
7be3d1cbaf
@ -30,6 +30,7 @@
|
|||||||
pre: new Map(),
|
pre: new Map(),
|
||||||
post: new Map(),
|
post: new Map(),
|
||||||
modules: new Map(),
|
modules: new Map(),
|
||||||
|
id: undefined,
|
||||||
};
|
};
|
||||||
this._initialized = false;
|
this._initialized = false;
|
||||||
this._lastNumModifiedFiles = 0;
|
this._lastNumModifiedFiles = 0;
|
||||||
@ -66,6 +67,7 @@
|
|||||||
pre: new Map(),
|
pre: new Map(),
|
||||||
post: new Map(),
|
post: new Map(),
|
||||||
modules: new Map(),
|
modules: new Map(),
|
||||||
|
id: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +82,15 @@
|
|||||||
this._patchMap(this._lastBundle.post, deltaBundle.post);
|
this._patchMap(this._lastBundle.post, deltaBundle.post);
|
||||||
this._patchMap(this._lastBundle.modules, deltaBundle.delta);
|
this._patchMap(this._lastBundle.modules, deltaBundle.delta);
|
||||||
|
|
||||||
|
this._lastBundle.id = deltaBundle.id;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLastBundleId() {
|
||||||
|
return this._lastBundle.id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of modified files in the last received Delta. This is
|
* 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
|
* currently used to populate the `X-Metro-Files-Changed-Count` HTTP header
|
||||||
|
@ -20,31 +20,34 @@
|
|||||||
* whole JS bundle Blob.
|
* whole JS bundle Blob.
|
||||||
*/
|
*/
|
||||||
async function deltaUrlToBlobUrl(deltaUrl) {
|
async function deltaUrlToBlobUrl(deltaUrl) {
|
||||||
let cachedBundle = cachedBundleUrls.get(deltaUrl);
|
const client = global.DeltaPatcher.get(deltaUrl);
|
||||||
|
|
||||||
const deltaBundleId = cachedBundle
|
const deltaBundleId = client.getLastBundleId()
|
||||||
? `&deltaBundleId=${cachedBundle.id}`
|
? `&deltaBundleId=${client.getLastBundleId()}`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const data = await fetch(deltaUrl + deltaBundleId);
|
const data = await fetch(deltaUrl + deltaBundleId);
|
||||||
const bundle = await data.json();
|
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),
|
pre: new Map(bundle.pre),
|
||||||
post: new Map(bundle.post),
|
post: new Map(bundle.post),
|
||||||
delta: new Map(bundle.delta),
|
delta: new Map(bundle.delta),
|
||||||
reset: bundle.reset,
|
reset: bundle.reset,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let cachedBundle = cachedBundleUrls.get(deltaUrl);
|
||||||
|
|
||||||
// If nothing changed, avoid recreating a bundle blob by reusing the
|
// If nothing changed, avoid recreating a bundle blob by reusing the
|
||||||
// previous one.
|
// previous one.
|
||||||
if (deltaPatcher.getLastNumModifiedFiles() === 0 && cachedBundle) {
|
if (deltaPatcher.getLastNumModifiedFiles() === 0 && cachedBundle) {
|
||||||
return cachedBundle.url;
|
return cachedBundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean up the previous bundle URL to not leak memory.
|
// Clean up the previous bundle URL to not leak memory.
|
||||||
if (cachedBundle) {
|
if (cachedBundle) {
|
||||||
URL.revokeObjectURL(cachedBundle.url);
|
URL.revokeObjectURL(cachedBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// To make Source Maps work correctly, we need to add a newline between
|
// To make Source Maps work correctly, we need to add a newline between
|
||||||
@ -58,13 +61,10 @@
|
|||||||
type: 'application/javascript',
|
type: 'application/javascript',
|
||||||
});
|
});
|
||||||
|
|
||||||
const bundleUrl = URL.createObjectURL(blob);
|
const bundleContents = URL.createObjectURL(blob);
|
||||||
cachedBundleUrls.set(deltaUrl, {
|
cachedBundleUrls.set(deltaUrl, bundleContents);
|
||||||
id: bundle.id,
|
|
||||||
url: bundleUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
return bundleUrl;
|
return bundleContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
global.deltaUrlToBlobUrl = deltaUrlToBlobUrl;
|
global.deltaUrlToBlobUrl = deltaUrlToBlobUrl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user