Skip to content

Commit

Permalink
Make sure saved trace-updates preference is restored properly after a…
Browse files Browse the repository at this point in the history
… reload
  • Loading branch information
Brian Vaughn committed Oct 3, 2019
1 parent 4ed7ff0 commit 2492694
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/react-devtools-core/src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function connectToDevTools(options: ?ConnectOptions) {
}

if (bridge !== null) {
bridge.emit('shutdown');
bridge.shutdown();
}

scheduleRetry();
Expand Down
4 changes: 4 additions & 0 deletions packages/react-devtools-extensions/src/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function setup(hook) {

initBackend(hook, agent, window);

// Let the frontend know that the backend has attached listeners and is ready for messages.
// This covers the case of of syncing saved values after reloading/navigating while DevTools remain open.
bridge.send('extensionBackendInitialized');

// Setup React Native style editor if a renderer like react-native-web has injected it.
if (hook.resolveRNStyle) {
setupNativeStyleEditor(
Expand Down
11 changes: 11 additions & 0 deletions packages/react-devtools-extensions/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getBrowserName,
getBrowserTheme,
} from './utils';
import {LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY} from 'react-devtools-shared/src/constants';
import {
getSavedComponentFilters,
getAppendComponentStack,
Expand Down Expand Up @@ -125,6 +126,16 @@ function createPanelIfReactLoaded() {
profilingData = store.profilerStore.profilingData;
}

bridge.addListener('extensionBackendInitialized', () => {
// Initialize the renderer's trace-updates setting.
// This handles the case of navigating to a new page after the DevTools have already been shown.
bridge.send(
'setTraceUpdatesEnabled',
localStorageGetItem(LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY) ===
'true',
);
});

store = new Store(bridge, {
isProfiling,
supportsReloadAndProfile: isChrome,
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type NativeStyleEditor_SetValueParams = {|
|};

type BackendEvents = {|
extensionBackendInitialized: [],
inspectedElement: [InspectedElementPayload],
isBackendStorageAPISupported: [boolean],
operations: [Array<number>],
Expand Down
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export const SESSION_STORAGE_RELOAD_AND_PROFILE_KEY =
export const LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY =
'React::DevTools::appendComponentStack';

export const LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY =
'React::DevTools::traceUpdatesEnabled';

export const PROFILER_EXPORT_VERSION = 4;

export const CHANGE_LOG_URL =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
COMFORTABLE_LINE_HEIGHT,
COMPACT_LINE_HEIGHT,
LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY,
LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY,
} from 'react-devtools-shared/src/constants';
import {useLocalStorage} from '../hooks';
import {BridgeContext} from '../context';
Expand Down Expand Up @@ -78,7 +79,7 @@ function SettingsContextController({
>(LOCAL_STORAGE_SHOULD_PATCH_CONSOLE_KEY, true);
const [traceUpdatesEnabled, setTraceUpdatesEnabled] = useLocalStorage<
boolean,
>('React::DevTools::traceUpdatesEnabled', false);
>(LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY, false);

const documentElements = useMemo<DocumentElements>(
() => {
Expand Down

0 comments on commit 2492694

Please sign in to comment.