Skip to content

Commit 2492694

Browse files
author
Brian Vaughn
committed
Make sure saved trace-updates preference is restored properly after a reload
1 parent 4ed7ff0 commit 2492694

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

packages/react-devtools-core/src/backend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
114114
}
115115

116116
if (bridge !== null) {
117-
bridge.emit('shutdown');
117+
bridge.shutdown();
118118
}
119119

120120
scheduleRetry();

packages/react-devtools-extensions/src/backend.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ function setup(hook) {
6767

6868
initBackend(hook, agent, window);
6969

70+
// Let the frontend know that the backend has attached listeners and is ready for messages.
71+
// This covers the case of of syncing saved values after reloading/navigating while DevTools remain open.
72+
bridge.send('extensionBackendInitialized');
73+
7074
// Setup React Native style editor if a renderer like react-native-web has injected it.
7175
if (hook.resolveRNStyle) {
7276
setupNativeStyleEditor(

packages/react-devtools-extensions/src/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getBrowserName,
1010
getBrowserTheme,
1111
} from './utils';
12+
import {LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY} from 'react-devtools-shared/src/constants';
1213
import {
1314
getSavedComponentFilters,
1415
getAppendComponentStack,
@@ -125,6 +126,16 @@ function createPanelIfReactLoaded() {
125126
profilingData = store.profilerStore.profilingData;
126127
}
127128

129+
bridge.addListener('extensionBackendInitialized', () => {
130+
// Initialize the renderer's trace-updates setting.
131+
// This handles the case of navigating to a new page after the DevTools have already been shown.
132+
bridge.send(
133+
'setTraceUpdatesEnabled',
134+
localStorageGetItem(LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY) ===
135+
'true',
136+
);
137+
});
138+
128139
store = new Store(bridge, {
129140
isProfiling,
130141
supportsReloadAndProfile: isChrome,

packages/react-devtools-shared/src/bridge.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type NativeStyleEditor_SetValueParams = {|
7070
|};
7171

7272
type BackendEvents = {|
73+
extensionBackendInitialized: [],
7374
inspectedElement: [InspectedElementPayload],
7475
isBackendStorageAPISupported: [boolean],
7576
operations: [Array<number>],

packages/react-devtools-shared/src/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export const SESSION_STORAGE_RELOAD_AND_PROFILE_KEY =
3030
export const LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY =
3131
'React::DevTools::appendComponentStack';
3232

33+
export const LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY =
34+
'React::DevTools::traceUpdatesEnabled';
35+
3336
export const PROFILER_EXPORT_VERSION = 4;
3437

3538
export const CHANGE_LOG_URL =

packages/react-devtools-shared/src/devtools/views/Settings/SettingsContext.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
COMFORTABLE_LINE_HEIGHT,
1919
COMPACT_LINE_HEIGHT,
2020
LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY,
21+
LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY,
2122
} from 'react-devtools-shared/src/constants';
2223
import {useLocalStorage} from '../hooks';
2324
import {BridgeContext} from '../context';
@@ -78,7 +79,7 @@ function SettingsContextController({
7879
>(LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY, true);
7980
const [traceUpdatesEnabled, setTraceUpdatesEnabled] = useLocalStorage<
8081
boolean,
81-
>('React::DevTools::traceUpdatesEnabled', false);
82+
>(LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY, false);
8283

8384
const documentElements = useMemo<DocumentElements>(
8485
() => {

0 commit comments

Comments
 (0)