191
// Used for windowing purposes.
192
_weightAcrossRoots: number = 0;
193
194
+ _shouldCheckBridgeProtocolCompatibility: boolean = false;
195
+
196
constructor(bridge: FrontendBridge, config?: Config) {
197
super();
198
220
supportsReloadAndProfile,
221
supportsTimeline,
222
supportsTraceUpdates,
223
+ checkBridgeProtocolCompatibility,
224
} = config;
225
if (supportsInspectMatchingDOMElement) {
226
this._supportsInspectMatchingDOMElement = true;
237
if (supportsTraceUpdates) {
238
this._supportsTraceUpdates = true;
239
}
240
+ if (checkBridgeProtocolCompatibility) {
241
+ this._shouldCheckBridgeProtocolCompatibility = true;
242
+ }
243
}
244
245
this._bridge = bridge;
268
269
this._profilerStore = new ProfilerStore(bridge, this, isProfiling);
270
265
- // Verify that the frontend version is compatible with the connected backend.
266
- // See github.com/facebook/react/issues/21326
267
- if (config != null && config.checkBridgeProtocolCompatibility) {
268
- // Older backends don't support an explicit bridge protocol,
269
- // so we should timeout eventually and show a downgrade message.
270
- this._onBridgeProtocolTimeoutID = setTimeout(
271
- this.onBridgeProtocolTimeout,
272
- 10000,
273
- );
274
-
275
- bridge.addListener('bridgeProtocol', this.onBridgeProtocol);
276
- bridge.send('getBridgeProtocol');
277
- }
278
-
271
bridge.addListener('backendVersion', this.onBridgeBackendVersion);
280
- bridge.send('getBackendVersion');
281
-
272
bridge.addListener('saveToClipboard', this.onSaveToClipboard);
273
+ bridge.addListener('backendInitialized', this.onBackendInitialized);
274
}
275
276
// This is only used in tests to avoid memory leaks.
1484
copy(text);
1485
};
1486
1487
+ onBackendInitialized: () => void = () => {
1488
+ // Verify that the frontend version is compatible with the connected backend.
1489
+ // See github.com/facebook/react/issues/21326
1490
+ if (this._shouldCheckBridgeProtocolCompatibility) {
1491
+ // Older backends don't support an explicit bridge protocol,
1492
+ // so we should timeout eventually and show a downgrade message.
1493
+ this._onBridgeProtocolTimeoutID = setTimeout(
1494
+ this.onBridgeProtocolTimeout,
1495
+ 10000,
1496
+ );
1497
+
1498
+ this._bridge.addListener('bridgeProtocol', this.onBridgeProtocol);
1499
+ this._bridge.send('getBridgeProtocol');
1500
+ }
1501
+
1502
+ this._bridge.send('getBackendVersion');
1503
+ };
1504
+
1505
// The Store should never throw an Error without also emitting an event.
1506
// Otherwise Store errors will be invisible to users,
1507
// but the downstream errors they cause will be reported as bugs.