Skip to content

Commit

Permalink
Disabled transferrables for now (to avoid a Chrome runtime error)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Mar 6, 2019
1 parent 0db7770 commit c184493
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
22 changes: 20 additions & 2 deletions src/backend/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,27 @@ export default class Agent extends EventEmitter {
onHookOperations = (operations: Uint32Array) => {
debug('onHookOperations', operations);

// TODO The chrome.runtime does not currently support transferables; it forces JSON serialization.
// TODO:
// The chrome.runtime does not currently support transferables; it forces JSON serialization.
// See bug https://bugs.chromium.org/p/chromium/issues/detail?id=927134
//
// Regarding transferables, the postMessage doc states:
// If the ownership of an object is transferred, it becomes unusable (neutered)
// in the context it was sent from and becomes available only to the worker it was sent to.
//
// Even though Chrome is eventually JSON serializing the array buffer,
// using the transferable approach also sometimes causes it to throw:
// DOMException: Failed to execute 'postMessage' on 'Window': ArrayBuffer at index 0 is already neutered.
//
// See bug https://github.com/bvaughn/react-devtools-experimental/issues/25
//
// The Store has a fallback in place that parses the message as JSON if the type isn't an array.
this._bridge.send('operations', operations, [operations.buffer]);
// For now the simplest fix seems to be to not transfer the array.
// This will negatively impact performance on Firefox so it's unfortunate,
// but until we're able to fix the Chrome error mentioned above, it seems necessary.
//
// this._bridge.send('operations', operations, [operations.buffer]);
this._bridge.send('operations', operations);
};

_onClick = (event: MouseEvent) => {
Expand Down
12 changes: 4 additions & 8 deletions src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Bridge extends EventEmitter {
this._wall = wall;

wall.listen((message: Message) => {
this._emit(message);
this.emit(message.event, message.payload);
});
}

Expand All @@ -40,12 +40,12 @@ export default class Bridge extends EventEmitter {
if (now - time > BATCH_DURATION) {
this._flush();
} else {
this._timeoutID = setTimeout(() => this._flush(), BATCH_DURATION);
this._timeoutID = setTimeout(this._flush, BATCH_DURATION);
}
}
}

_flush() {
_flush = () => {
while (this._messageQueue.length) {
this._wall.send.apply(this._wall, this._messageQueue.splice(0, 3));
}
Expand All @@ -57,9 +57,5 @@ export default class Bridge extends EventEmitter {

this._messageQueue = [];
this._time = null;
}

_emit(message: Message) {
this.emit(message.event, message.payload);
}
};
}

0 comments on commit c184493

Please sign in to comment.