@@ -36,6 +36,8 @@ import type {
3636 RendererID ,
3737 RendererInterface ,
3838 DevToolsHookSettings ,
39+ ReloadAndProfileConfigPersistence ,
40+ ReloadAndProfileConfig ,
3941} from './types' ;
4042import type { ComponentFilter } from 'react-devtools-shared/src/frontend/types' ;
4143import { isReactNativeEnvironment } from './utils' ;
@@ -159,21 +161,27 @@ export default class Agent extends EventEmitter<{
159161 _persistedSelection : PersistedSelection | null = null ;
160162 _persistedSelectionMatch : PathMatch | null = null ;
161163 _traceUpdatesEnabled : boolean = false ;
164+ _reloadAndProfileConfigPersistence : ReloadAndProfileConfigPersistence ;
162165
163- constructor ( bridge : BackendBridge ) {
166+ constructor (
167+ bridge : BackendBridge ,
168+ reloadAndProfileConfigPersistence ? : ReloadAndProfileConfigPersistence = defaultReloadAndProfileConfigSetters ,
169+ ) {
164170 super ( ) ;
165171
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 ) {
169177 this . _recordChangeDescriptions =
170- sessionStorageGetItem (
171- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
172- ) === 'true' ;
178+ reloadAndProfileConfig . recordChangeDescriptions ;
173179 this . _isProfiling = true ;
174180
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+ } ) ;
177185 }
178186
179187 const persistedSelectionString = sessionStorageGetItem (
@@ -671,11 +679,10 @@ export default class Agent extends EventEmitter<{
671679
672680 reloadAndProfile : ( recordChangeDescriptions : boolean ) = > void =
673681 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+ } ) ;
679686
680687 // This code path should only be hit if the shell has explicitly told the Store that it supports profiling.
681688 // 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<{
956963 }
957964 } ;
958965}
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