88 */
99
1010import EventEmitter from '../events' ;
11- import {
12- SESSION_STORAGE_LAST_SELECTION_KEY ,
13- SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ,
14- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
15- __DEBUG__ ,
16- } from '../constants' ;
17- import {
18- sessionStorageGetItem ,
19- sessionStorageRemoveItem ,
20- sessionStorageSetItem ,
21- } from 'react-devtools-shared/src/storage' ;
11+ import { SESSION_STORAGE_LAST_SELECTION_KEY , __DEBUG__ } from '../constants' ;
2212import setupHighlighter from './views/Highlighter' ;
2313import {
2414 initialize as setupTraceUpdates ,
@@ -36,9 +26,16 @@ import type {
3626 RendererID ,
3727 RendererInterface ,
3828 DevToolsHookSettings ,
29+ ReloadAndProfileConfigPersistence ,
3930} from './types' ;
4031import type { ComponentFilter } from 'react-devtools-shared/src/frontend/types' ;
4132import { isReactNativeEnvironment } from './utils' ;
33+ import { defaultReloadAndProfileConfigPersistence } from '../utils' ;
34+ import {
35+ sessionStorageGetItem ,
36+ sessionStorageRemoveItem ,
37+ sessionStorageSetItem ,
38+ } from '../storage' ;
4239
4340const debug = ( methodName : string , ...args : Array < string > ) => {
4441 if ( __DEBUG__ ) {
@@ -159,21 +156,27 @@ export default class Agent extends EventEmitter<{
159156 _persistedSelection : PersistedSelection | null = null ;
160157 _persistedSelectionMatch : PathMatch | null = null ;
161158 _traceUpdatesEnabled : boolean = false ;
159+ _reloadAndProfileConfigPersistence : ReloadAndProfileConfigPersistence ;
162160
163- constructor ( bridge : BackendBridge ) {
161+ constructor (
162+ bridge : BackendBridge ,
163+ reloadAndProfileConfigPersistence ? : ReloadAndProfileConfigPersistence = defaultReloadAndProfileConfigPersistence ,
164+ ) {
164165 super ( ) ;
165166
166- if (
167- sessionStorageGetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) === 'true'
168- ) {
167+ this . _reloadAndProfileConfigPersistence = reloadAndProfileConfigPersistence ;
168+ const { getReloadAndProfileConfig, setReloadAndProfileConfig} =
169+ reloadAndProfileConfigPersistence ;
170+ const reloadAndProfileConfig = getReloadAndProfileConfig ( ) ;
171+ if ( reloadAndProfileConfig . shouldReloadAndProfile ) {
169172 this . _recordChangeDescriptions =
170- sessionStorageGetItem (
171- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
172- ) === 'true' ;
173+ reloadAndProfileConfig . recordChangeDescriptions ;
173174 this . _isProfiling = true ;
174175
175- sessionStorageRemoveItem ( SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ) ;
176- sessionStorageRemoveItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY ) ;
176+ setReloadAndProfileConfig ( {
177+ shouldReloadAndProfile : false ,
178+ recordChangeDescriptions : false ,
179+ } ) ;
177180 }
178181
179182 const persistedSelectionString = sessionStorageGetItem (
@@ -671,11 +674,10 @@ export default class Agent extends EventEmitter<{
671674
672675 reloadAndProfile : ( recordChangeDescriptions : boolean ) = > void =
673676 recordChangeDescriptions => {
674- sessionStorageSetItem ( SESSION_STORAGE_RELOAD_AND_PROFILE_KEY , 'true' ) ;
675- sessionStorageSetItem (
676- SESSION_STORAGE_RECORD_CHANGE_DESCRIPTIONS_KEY ,
677- recordChangeDescriptions ? 'true' : 'false' ,
678- ) ;
677+ this . _reloadAndProfileConfigPersistence . setReloadAndProfileConfig ( {
678+ shouldReloadAndProfile : true ,
679+ recordChangeDescriptions,
680+ } ) ;
679681
680682 // This code path should only be hit if the shell has explicitly told the Store that it supports profiling.
681683 // In that case, the shell must also listen for this specific message to know when it needs to reload the app.
0 commit comments