@@ -191,6 +191,8 @@ export default class Store extends EventEmitter<{
191
191
// Used for windowing purposes.
192
192
_weightAcrossRoots : number = 0 ;
193
193
194
+ _shouldCheckBridgeProtocolCompatibility : boolean = false ;
195
+
194
196
constructor ( bridge : FrontendBridge , config ? : Config ) {
195
197
super ( ) ;
196
198
@@ -218,6 +220,7 @@ export default class Store extends EventEmitter<{
218
220
supportsReloadAndProfile,
219
221
supportsTimeline,
220
222
supportsTraceUpdates,
223
+ checkBridgeProtocolCompatibility,
221
224
} = config ;
222
225
if ( supportsInspectMatchingDOMElement ) {
223
226
this . _supportsInspectMatchingDOMElement = true ;
@@ -234,6 +237,9 @@ export default class Store extends EventEmitter<{
234
237
if ( supportsTraceUpdates ) {
235
238
this . _supportsTraceUpdates = true ;
236
239
}
240
+ if ( checkBridgeProtocolCompatibility ) {
241
+ this . _shouldCheckBridgeProtocolCompatibility = true ;
242
+ }
237
243
}
238
244
239
245
this . _bridge = bridge ;
@@ -262,24 +268,9 @@ export default class Store extends EventEmitter<{
262
268
263
269
this . _profilerStore = new ProfilerStore ( bridge , this , isProfiling ) ;
264
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
-
279
271
bridge . addListener ( 'backendVersion' , this . onBridgeBackendVersion ) ;
280
- bridge . send ( 'getBackendVersion' ) ;
281
-
282
272
bridge . addListener ( 'saveToClipboard' , this . onSaveToClipboard ) ;
273
+ bridge . addListener ( 'backendInitialized' , this . onBackendInitialized ) ;
283
274
}
284
275
285
276
// This is only used in tests to avoid memory leaks.
@@ -1493,6 +1484,24 @@ export default class Store extends EventEmitter<{
1493
1484
copy ( text ) ;
1494
1485
} ;
1495
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
+ bridge . addListener ( 'bridgeProtocol' , this . onBridgeProtocol ) ;
1499
+ bridge . send ( 'getBridgeProtocol' ) ;
1500
+ }
1501
+
1502
+ bridge . send ( 'getBackendVersion' ) ;
1503
+ } ;
1504
+
1496
1505
// The Store should never throw an Error without also emitting an event.
1497
1506
// Otherwise Store errors will be invisible to users,
1498
1507
// but the downstream errors they cause will be reported as bugs.
0 commit comments