@samitouri / QOS-React-2 / commits / 3e3c83aecd

Updated reload-and-profile temp key to use sessioStorage instead of localStorage

Brian Vaughn committed Jun 7, 2019 at 12:40 UTC 3e3c83aecde5112c064dfb314c589518b8aae081
4 files changed +20 -19
shells/browser/shared/src/injectGlobalHook.js
+3 -3
@@ -2,8 +2,8 @@
2
3 import nullthrows from 'nullthrows';
4 import { installHook } from 'src/hook';
5 -import { LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY } from 'src/constants';
6 -import { localStorageGetItem } from 'src/storage';
5 +import { SESSION_STORAGE_RELOAD_AND_PROFILE_KEY } from 'src/constants';
6 +import { sessionStorageGetItem } from 'src/storage';
7
8 function injectCode(code) {
9 const script = document.createElement('script');
@@ -64,7 +64,7 @@ window.__REACT_DEVTOOLS_GLOBAL_HOOK__.nativeSet = Set;
64 `;
65
66 // If we have just reloaded to profile, we need to inject the renderer interface before the app loads.
67 -if (localStorageGetItem(LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
67 +if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
68 const rendererURL = chrome.runtime.getURL('build/renderer.js');
69 let rendererCode;
70
src/backend/agent.js
+6 -7
@@ -4,14 +4,11 @@ import EventEmitter from 'events';
4 import memoize from 'memoize-one';
5 import throttle from 'lodash.throttle';
6 import {
7 - LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY,
7 SESSION_STORAGE_LAST_SELECTION_KEY,
8 + SESSION_STORAGE_RELOAD_AND_PROFILE_KEY,
9 __DEBUG__,
10 } from '../constants';
11 import {
12 - localStorageGetItem,
13 - localStorageRemoveItem,
14 - localStorageSetItem,
12 sessionStorageGetItem,
13 sessionStorageRemoveItem,
14 sessionStorageSetItem,
@@ -79,10 +76,12 @@ export default class Agent extends EventEmitter {
76 constructor(bridge: Bridge) {
77 super();
78
82 - if (localStorageGetItem(LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
79 + if (
80 + sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true'
81 + ) {
82 this._isProfiling = true;
83
85 - localStorageRemoveItem(LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY);
84 + sessionStorageRemoveItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY);
85 }
86
87 const persistedSelectionString = sessionStorageGetItem(
@@ -243,7 +242,7 @@ export default class Agent extends EventEmitter {
242 };
243
244 reloadAndProfile = () => {
246 - localStorageSetItem(LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY, 'true');
245 + sessionStorageSetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY, 'true');
246
247 // This code path should only be hit if the shell has explicitly told the Store that it supports profiling.
248 // In that case, the shell must also listen for this specific message to know when it needs to reload the app.
src/backend/renderer.js
+6 -5
@@ -25,11 +25,11 @@ import {
25 getUID,
26 utfEncodeString,
27 } from 'src/utils';
28 -import { localStorageGetItem } from 'src/storage';
28 +import { sessionStorageGetItem } from 'src/storage';
29 import { cleanForBridge, copyWithSet, setInObject } from './utils';
30 import {
31 __DEBUG__,
32 - LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY,
32 + SESSION_STORAGE_RELOAD_AND_PROFILE_KEY,
33 TREE_OPERATION_ADD,
34 TREE_OPERATION_REMOVE,
35 TREE_OPERATION_REORDER_CHILDREN,
@@ -339,7 +339,7 @@ export function attach(
339 if (window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ != null) {
340 applyComponentFilters(window.__REACT_DEVTOOLS_COMPONENT_FILTERS__);
341 } else {
342 - console.warn('⚛️ DevTools: Invalid component filters');
342 + console.warn('⚛️ DevTools: Could not locate saved component filters');
343
344 // Fallback to assuming the default filters in this case.
345 applyComponentFilters(getDefaultComponentFilters());
@@ -2201,8 +2201,9 @@ export function attach(
2201 }
2202
2203 // Automatically start profiling so that we don't miss timing info from initial "mount".
2204 - // TODO This doens't seem right
2205 - if (localStorageGetItem(LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
2204 + if (
2205 + sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true'
2206 + ) {
2207 startProfiling();
2208 }
2209
src/constants.js
+5 -4
@@ -1,5 +1,8 @@
1 // @flow
2
3 +// Flip this flag to true to enable verbose console debug logging.
4 +export const __DEBUG__ = false;
5 +
6 export const TREE_OPERATION_ADD = 1;
7 export const TREE_OPERATION_REMOVE = 2;
8 export const TREE_OPERATION_REORDER_CHILDREN = 3;
@@ -8,12 +11,10 @@ export const TREE_OPERATION_UPDATE_TREE_BASE_DURATION = 4;
11 export const LOCAL_STORAGE_FILTER_PREFERENCES_KEY =
12 'React::DevTools::componentFilters';
13
11 -export const LOCAL_STORAGE_RELOAD_AND_PROFILE_KEY =
12 - 'React::DevTools::reloadAndProfile';
13 -
14 export const SESSION_STORAGE_LAST_SELECTION_KEY =
15 'React::DevTools::lastSelection';
16
17 -export const __DEBUG__ = false;
17 +export const SESSION_STORAGE_RELOAD_AND_PROFILE_KEY =
18 + 'React::DevTools::reloadAndProfile';
19
20 export const PROFILER_EXPORT_VERSION = 4;