@@ -30,7 +30,10 @@ import ProfilerStore from './ProfilerStore';
30
30
31
31
import type { Element } from './views/Components/types' ;
32
32
import type { ComponentFilter , ElementType } from '../types' ;
33
- import type { FrontendBridge } from 'react-devtools-shared/src/bridge' ;
33
+ import type {
34
+ BridgeProtocol ,
35
+ FrontendBridge ,
36
+ } from 'react-devtools-shared/src/bridge' ;
34
37
35
38
const debug = ( methodName , ...args ) => {
36
39
if ( __DEBUG__ ) {
@@ -49,6 +52,7 @@ const LOCAL_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY =
49
52
'React::DevTools::recordChangeDescriptions' ;
50
53
51
54
type Config = { |
55
+ checkBridgeProtocolCompatibility ? : boolean ,
52
56
isProfiling ? : boolean ,
53
57
supportsNativeInspection ? : boolean ,
54
58
supportsReloadAndProfile ? : boolean ,
@@ -74,6 +78,7 @@ export default class Store extends EventEmitter<{|
74
78
supportsNativeStyleEditor : [ ] ,
75
79
supportsProfiling : [ ] ,
76
80
supportsReloadAndProfile : [ ] ,
81
+ unsupportedBridgeProtocolDetected : [ ] ,
77
82
unsupportedRendererVersionDetected : [ ] ,
78
83
| } > {
79
84
_bridge : FrontendBridge ;
@@ -128,6 +133,7 @@ export default class Store extends EventEmitter<{|
128
133
_supportsReloadAndProfile: boolean = false ;
129
134
_supportsTraceUpdates: boolean = false ;
130
135
136
+ _unsupportedBridgeProtocol: BridgeProtocol | null = null ;
131
137
_unsupportedRendererVersionDetected: boolean = false ;
132
138
133
139
// Total number of visible elements (within all roots).
@@ -194,6 +200,13 @@ export default class Store extends EventEmitter<{|
194
200
) ;
195
201
196
202
this . _profilerStore = new ProfilerStore ( bridge , this , isProfiling ) ;
203
+
204
+ // Verify that the frontend version is compatible with the connected backend.
205
+ // See github.com/facebook/react/issues/21326
206
+ if ( config != null && config . checkBridgeProtocolCompatibility ) {
207
+ bridge . addListener ( 'bridgeProtocol' , this . onBridgeProtocol ) ;
208
+ bridge . send ( 'getBridgeProtocol' ) ;
209
+ }
197
210
}
198
211
199
212
// This is only used in tests to avoid memory leaks.
@@ -353,6 +366,10 @@ export default class Store extends EventEmitter<{|
353
366
return this . _supportsTraceUpdates ;
354
367
}
355
368
369
+ get unsupportedBridgeProtocol ( ) : BridgeProtocol | null {
370
+ return this . _unsupportedBridgeProtocol ;
371
+ }
372
+
356
373
get unsupportedRendererVersionDetected ( ) : boolean {
357
374
return this . _unsupportedRendererVersionDetected ;
358
375
}
@@ -1020,6 +1037,7 @@ export default class Store extends EventEmitter<{|
1020
1037
'isBackendStorageAPISupported' ,
1021
1038
this . onBridgeStorageSupported ,
1022
1039
) ;
1040
+ this . _bridge . removeListener ( 'bridgeProtocol' , this . onBridgeProtocol ) ;
1023
1041
} ;
1024
1042
1025
1043
onBridgeStorageSupported = ( isBackendStorageAPISupported : boolean ) => {
@@ -1033,4 +1051,9 @@ export default class Store extends EventEmitter<{|
1033
1051
1034
1052
this . emit ( 'unsupportedRendererVersionDetected' ) ;
1035
1053
} ;
1054
+
1055
+ onBridgeProtocol = ( bridgeProtocol : BridgeProtocol ) => {
1056
+ this . _unsupportedBridgeProtocol = bridgeProtocol ;
1057
+ this . emit ( 'unsupportedBridgeProtocolDetected' ) ;
1058
+ } ;
1036
1059
}
0 commit comments