Disabled transferrables for now (to avoid a Chrome runtime error)
Brian Vaughn committed
Mar 6, 2019 at 13:17 UTC
c18449326dd7a790d9beabf6292d78b01e7a712e
2 files changed
+24
-10
src/backend/agent.js
+20
-2
@@ -202,9 +202,27 @@ export default class Agent extends EventEmitter {
202
onHookOperations = (operations: Uint32Array) => {
203
debug('onHookOperations', operations);
204
205
- // TODO The chrome.runtime does not currently support transferables; it forces JSON serialization.
205
+ // TODO:
206
+ // The chrome.runtime does not currently support transferables; it forces JSON serialization.
207
+ // See bug https://bugs.chromium.org/p/chromium/issues/detail?id=927134
208
+ //
209
+ // Regarding transferables, the postMessage doc states:
210
+ // If the ownership of an object is transferred, it becomes unusable (neutered)
211
+ // in the context it was sent from and becomes available only to the worker it was sent to.
212
+ //
213
+ // Even though Chrome is eventually JSON serializing the array buffer,
214
+ // using the transferable approach also sometimes causes it to throw:
215
+ // DOMException: Failed to execute 'postMessage' on 'Window': ArrayBuffer at index 0 is already neutered.
216
+ //
217
+ // See bug https://github.com/bvaughn/react-devtools-experimental/issues/25
218
+ //
219
// The Store has a fallback in place that parses the message as JSON if the type isn't an array.
207
- this._bridge.send('operations', operations, [operations.buffer]);
220
+ // For now the simplest fix seems to be to not transfer the array.
221
+ // This will negatively impact performance on Firefox so it's unfortunate,
222
+ // but until we're able to fix the Chrome error mentioned above, it seems necessary.
223
+ //
224
+ // this._bridge.send('operations', operations, [operations.buffer]);
225
+ this._bridge.send('operations', operations);
226
};
227
228
_onClick = (event: MouseEvent) => {
src/bridge.js
+4
-8
@@ -23,7 +23,7 @@ export default class Bridge extends EventEmitter {
23
this._wall = wall;
24
25
wall.listen((message: Message) => {
26
- this._emit(message);
26
+ this.emit(message.event, message.payload);
27
});
28
}
29
@@ -40,12 +40,12 @@ export default class Bridge extends EventEmitter {
40
if (now - time > BATCH_DURATION) {
41
this._flush();
42
} else {
43
- this._timeoutID = setTimeout(() => this._flush(), BATCH_DURATION);
43
+ this._timeoutID = setTimeout(this._flush, BATCH_DURATION);
44
}
45
}
46
}
47
48
- _flush() {
48
+ _flush = () => {
49
while (this._messageQueue.length) {
50
this._wall.send.apply(this._wall, this._messageQueue.splice(0, 3));
51
}
@@ -57,9 +57,5 @@ export default class Bridge extends EventEmitter {
57
58
this._messageQueue = [];
59
this._time = null;
60
- }
61
-
62
- _emit(message: Message) {
63
- this.emit(message.event, message.payload);
64
- }
60
+ };
61
}