@@ -30,7 +30,10 @@ import ProfilerStore from './ProfilerStore';
3030
3131import type { Element } from './views/Components/types' ;
3232import 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' ;
3437
3538const debug = ( methodName , ...args ) => {
3639 if ( __DEBUG__ ) {
@@ -49,6 +52,7 @@ const LOCAL_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY =
4952 'React::DevTools::recordChangeDescriptions' ;
5053
5154type Config = { |
55+ checkBridgeProtocolCompatibility ? : boolean ,
5256 isProfiling ? : boolean ,
5357 supportsNativeInspection ? : boolean ,
5458 supportsReloadAndProfile ? : boolean ,
@@ -74,6 +78,7 @@ export default class Store extends EventEmitter<{|
7478 supportsNativeStyleEditor : [ ] ,
7579 supportsProfiling : [ ] ,
7680 supportsReloadAndProfile : [ ] ,
81+ unsupportedBridgeProtocolDetected : [ ] ,
7782 unsupportedRendererVersionDetected : [ ] ,
7883| } > {
7984 _bridge : FrontendBridge ;
@@ -128,6 +133,7 @@ export default class Store extends EventEmitter<{|
128133 _supportsReloadAndProfile: boolean = false ;
129134 _supportsTraceUpdates: boolean = false ;
130135
136+ _unsupportedBridgeProtocol: BridgeProtocol | null = null ;
131137 _unsupportedRendererVersionDetected: boolean = false ;
132138
133139 // Total number of visible elements (within all roots).
@@ -194,6 +200,13 @@ export default class Store extends EventEmitter<{|
194200 ) ;
195201
196202 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+ }
197210 }
198211
199212 // This is only used in tests to avoid memory leaks.
@@ -353,6 +366,10 @@ export default class Store extends EventEmitter<{|
353366 return this . _supportsTraceUpdates ;
354367 }
355368
369+ get unsupportedBridgeProtocol ( ) : BridgeProtocol | null {
370+ return this . _unsupportedBridgeProtocol ;
371+ }
372+
356373 get unsupportedRendererVersionDetected ( ) : boolean {
357374 return this . _unsupportedRendererVersionDetected ;
358375 }
@@ -1020,6 +1037,7 @@ export default class Store extends EventEmitter<{|
10201037 'isBackendStorageAPISupported' ,
10211038 this . onBridgeStorageSupported ,
10221039 ) ;
1040+ this . _bridge . removeListener ( 'bridgeProtocol' , this . onBridgeProtocol ) ;
10231041 } ;
10241042
10251043 onBridgeStorageSupported = ( isBackendStorageAPISupported : boolean ) => {
@@ -1033,4 +1051,9 @@ export default class Store extends EventEmitter<{|
10331051
10341052 this . emit ( 'unsupportedRendererVersionDetected' ) ;
10351053 } ;
1054+
1055+ onBridgeProtocol = ( bridgeProtocol : BridgeProtocol ) => {
1056+ this . _unsupportedBridgeProtocol = bridgeProtocol ;
1057+ this . emit ( 'unsupportedBridgeProtocolDetected' ) ;
1058+ } ;
10361059}
0 commit comments