@@ -36,6 +36,8 @@ import type {
36
36
RendererID ,
37
37
RendererInterface ,
38
38
DevToolsHookSettings ,
39
+ ReloadAndProfileConfigPersistence ,
40
+ ReloadAndProfileConfig ,
39
41
} from './types' ;
40
42
import type { ComponentFilter } from 'react-devtools-shared/src/frontend/types' ;
41
43
import { isReactNativeEnvironment } from './utils' ;
@@ -159,21 +161,27 @@ export default class Agent extends EventEmitter<{
159
161
_persistedSelection : PersistedSelection | null = null ;
160
162
_persistedSelectionMatch : PathMatch | null = null ;
161
163
_traceUpdatesEnabled : boolean = false ;
164
+ _reloadAndProfileConfigPersistence : ReloadAndProfileConfigPersistence ;
162
165
163
- constructor ( bridge : BackendBridge ) {
166
+ constructor (
167
+ bridge : BackendBridge ,
168
+ reloadAndProfileConfigPersistence ? : ReloadAndProfileConfigPersistence = defaultReloadAndProfileConfigSetters ,
169
+ ) {
164
170
super ( ) ;
165
171
166
- if (
167
- sessionStorageGetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) === 'true'
168
- ) {
172
+ this . _reloadAndProfileConfigPersistence = reloadAndProfileConfigPersistence ;
173
+ const { getReloadAndProfileConfig, setReloadAndProfileConfig} =
174
+ reloadAndProfileConfigPersistence ;
175
+ const reloadAndProfileConfig = getReloadAndProfileConfig ( ) ;
176
+ if ( reloadAndProfileConfig . shouldReloadAndProfile ) {
169
177
this . _recordChangeDescriptions =
170
- sessionStorageGetItem (
171
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
172
- ) === 'true' ;
178
+ reloadAndProfileConfig . recordChangeDescriptions ;
173
179
this . _isProfiling = true ;
174
180
175
- sessionStorageRemoveItem ( SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ) ;
176
- sessionStorageRemoveItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) ;
181
+ setReloadAndProfileConfig ( {
182
+ shouldReloadAndProfile : false ,
183
+ recordChangeDescriptions : false ,
184
+ } ) ;
177
185
}
178
186
179
187
const persistedSelectionString = sessionStorageGetItem (
@@ -671,11 +679,10 @@ export default class Agent extends EventEmitter<{
671
679
672
680
reloadAndProfile : ( recordChangeDescriptions : boolean ) = > void =
673
681
recordChangeDescriptions => {
674
- sessionStorageSetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY , 'true' ) ;
675
- sessionStorageSetItem (
676
- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
677
- recordChangeDescriptions ? 'true' : 'false' ,
678
- ) ;
682
+ this . _reloadAndProfileConfigPersistence . setReloadAndProfileConfig ( {
683
+ shouldReloadAndProfile : true ,
684
+ recordChangeDescriptions,
685
+ } ) ;
679
686
680
687
// This code path should only be hit if the shell has explicitly told the Store that it supports profiling.
681
688
// In that case, the shell must also listen for this specific message to know when it needs to reload the app.
@@ -956,3 +963,35 @@ export default class Agent extends EventEmitter<{
956
963
}
957
964
} ;
958
965
}
966
+
967
+ const defaultReloadAndProfileConfigSetters : ReloadAndProfileConfigPersistence =
968
+ {
969
+ setReloadAndProfileConfig ( {
970
+ shouldReloadAndProfile,
971
+ recordChangeDescriptions,
972
+ } ) : void {
973
+ if ( shouldReloadAndProfile != null ) {
974
+ sessionStorageSetItem (
975
+ SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ,
976
+ shouldReloadAndProfile ? 'true' : 'false' ,
977
+ ) ;
978
+ }
979
+ if ( recordChangeDescriptions != null ) {
980
+ sessionStorageSetItem (
981
+ SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
982
+ recordChangeDescriptions ? 'true' : 'false' ,
983
+ ) ;
984
+ }
985
+ } ,
986
+ getReloadAndProfileConfig ( ) : ReloadAndProfileConfig {
987
+ return {
988
+ shouldReloadAndProfile :
989
+ sessionStorageGetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) ===
990
+ 'true' ,
991
+ recordChangeDescriptions :
992
+ sessionStorageGetItem (
993
+ SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
994
+ ) === 'true' ,
995
+ } ;
996
+ } ,
997
+ } ;
0 commit comments