Fix issue with responses from de-inited plugins
Summary: Now that flipper is using rsocket requestResponse, the SDK is responding with an error when the connection for this plugin has been torn down. To avoid flipper interpreting these as bad, keep track of which plugins are inited, and only worry about responses from these. Reviewed By: danielbuechele Differential Revision: D13973745 fbshipit-source-id: d4e6916f89b3b562e5dcf23c4fe5b5cb384a6ec4
This commit is contained in:
committed by
Facebook Github Bot
parent
ce5f739d81
commit
fe0eeafd98
@@ -98,6 +98,7 @@ export default class Client extends EventEmitter {
|
|||||||
this.store = store;
|
this.store = store;
|
||||||
this.broadcastCallbacks = new Map();
|
this.broadcastCallbacks = new Map();
|
||||||
this.requestCallbacks = new Map();
|
this.requestCallbacks = new Map();
|
||||||
|
this.activePlugins = new Set();
|
||||||
|
|
||||||
const client = this;
|
const client = this;
|
||||||
this.responder = {
|
this.responder = {
|
||||||
@@ -140,6 +141,7 @@ export default class Client extends EventEmitter {
|
|||||||
connection: ?ReactiveSocket;
|
connection: ?ReactiveSocket;
|
||||||
responder: PartialResponder;
|
responder: PartialResponder;
|
||||||
store: Store;
|
store: Store;
|
||||||
|
activePlugins: Set<string>;
|
||||||
|
|
||||||
broadcastCallbacks: Map<?string, Map<string, Set<Function>>>;
|
broadcastCallbacks: Map<?string, Map<string, Set<Function>>>;
|
||||||
|
|
||||||
@@ -355,6 +357,8 @@ export default class Client extends EventEmitter {
|
|||||||
params,
|
params,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const plugin = params?.api;
|
||||||
|
|
||||||
console.debug(data, 'message:call');
|
console.debug(data, 'message:call');
|
||||||
|
|
||||||
if (this.sdkVersion < 1) {
|
if (this.sdkVersion < 1) {
|
||||||
@@ -367,21 +371,29 @@ export default class Client extends EventEmitter {
|
|||||||
|
|
||||||
const mark = this.getPerformanceMark(metadata);
|
const mark = this.getPerformanceMark(metadata);
|
||||||
performance.mark(mark);
|
performance.mark(mark);
|
||||||
if (this.connection) {
|
if (this.isAcceptingMessagesFromPlugin(plugin)) {
|
||||||
this.connection
|
this.connection &&
|
||||||
.requestResponse({data: JSON.stringify(data)})
|
this.connection
|
||||||
.subscribe({
|
.requestResponse({data: JSON.stringify(data)})
|
||||||
onComplete: payload => {
|
.subscribe({
|
||||||
const logEventName = this.getLogEventName(data);
|
onComplete: payload => {
|
||||||
this.logger.trackTimeSince(mark, logEventName);
|
if (this.isAcceptingMessagesFromPlugin(plugin)) {
|
||||||
const response: {|
|
const logEventName = this.getLogEventName(data);
|
||||||
success?: Object,
|
this.logger.trackTimeSince(mark, logEventName);
|
||||||
error?: Object,
|
const response: {|
|
||||||
|} = JSON.parse(payload.data);
|
success?: Object,
|
||||||
this.onResponse(response, resolve, reject);
|
error?: Object,
|
||||||
},
|
|} = JSON.parse(payload.data);
|
||||||
onError: reject,
|
this.onResponse(response, resolve, reject);
|
||||||
});
|
}
|
||||||
|
},
|
||||||
|
// Open fresco then layout and you get errors because responses come back after deinit.
|
||||||
|
onError: e => {
|
||||||
|
if (this.isAcceptingMessagesFromPlugin(plugin)) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -396,6 +408,10 @@ export default class Client extends EventEmitter {
|
|||||||
this.logger.trackTimeSince(mark, logEventName);
|
this.logger.trackTimeSince(mark, logEventName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAcceptingMessagesFromPlugin(plugin: ?string) {
|
||||||
|
return this.connection && (!plugin || this.activePlugins.has(plugin));
|
||||||
|
}
|
||||||
|
|
||||||
getPerformanceMark(data: RequestMetadata): string {
|
getPerformanceMark(data: RequestMetadata): string {
|
||||||
const {method, id} = data;
|
const {method, id} = data;
|
||||||
return `request_response_${method}_${id}`;
|
return `request_response_${method}_${id}`;
|
||||||
@@ -408,6 +424,16 @@ export default class Client extends EventEmitter {
|
|||||||
: `request_response_${method}`;
|
: `request_response_${method}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initPlugin(pluginId: string) {
|
||||||
|
this.activePlugins.add(pluginId);
|
||||||
|
this.rawSend('init', {plugin: pluginId});
|
||||||
|
}
|
||||||
|
|
||||||
|
deinitPlugin(pluginId: string) {
|
||||||
|
this.activePlugins.delete(pluginId);
|
||||||
|
this.rawSend('deinit', {plugin: pluginId});
|
||||||
|
}
|
||||||
|
|
||||||
rawSend(method: string, params?: Object): void {
|
rawSend(method: string, params?: Object): void {
|
||||||
const data = {
|
const data = {
|
||||||
method,
|
method,
|
||||||
|
|||||||
@@ -209,12 +209,12 @@ export class FlipperPlugin<S = *, A = *, P = *> extends FlipperBasePlugin<
|
|||||||
// run plugin teardown
|
// run plugin teardown
|
||||||
this.teardown();
|
this.teardown();
|
||||||
if (this.realClient.connected) {
|
if (this.realClient.connected) {
|
||||||
this.realClient.rawSend('deinit', {plugin: this.constructor.id});
|
this.realClient.deinitPlugin(this.constructor.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_init() {
|
_init() {
|
||||||
this.realClient.rawSend('init', {plugin: this.constructor.id});
|
this.realClient.initPlugin(this.constructor.id);
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user