Merge pull request #3134 from weaveworks/use-json-stable-stringify

Don't update route if it hasn't changed
This commit is contained in:
Filip Barl
2018-04-09 20:44:16 +02:00
committed by GitHub
2 changed files with 8 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import page from 'page';
import stableStringify from 'json-stable-stringify';
import { fromJS, is as isDeepEqual } from 'immutable';
import { each, omit, omitBy, isEmpty } from 'lodash';
@@ -107,9 +108,12 @@ export function getUrlState(state) {
export function updateRoute(getState) {
const state = getUrlState(getState());
const stateUrl = encodeURL(JSON.stringify(state));
const dispatch = false;
const prevState = parseHashState();
const dispatch = false;
const stateUrl = encodeURL(stableStringify(state));
const prevStateUrl = encodeURL(stableStringify(prevState));
if (stateUrl === prevStateUrl) return;
// back up state in storage as well
storageSet(STORAGE_STATE_KEY, stateUrl);
@@ -152,7 +156,7 @@ export function getRouter(dispatch, initialState) {
} else {
const mergedState = Object.assign(initialState, parsedState);
// push storage state to URL
window.location.hash = `!/state/${JSON.stringify(mergedState)}`;
window.location.hash = `!/state/${stableStringify(mergedState)}`;
dispatch(route(mergedState));
}
} else {

View File

@@ -24,6 +24,7 @@
"filter-invalid-dom-props": "2.0.0",
"font-awesome": "4.7.0",
"immutable": "3.8.2",
"json-stable-stringify": "1.0.1",
"lcp": "1.1.0",
"lodash": "4.17.4",
"materialize-css": "0.98.1",