Skip to content

Commit 59951ed

Browse files
Fix/too many history replace state (#7530)
* Fix too many history.replaceState() error on Safari * fix restyled error by running prettier for client/app/services/location.js
1 parent 777153e commit 59951ed

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

client/app/services/location.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function normalizeLocation(rawLocation) {
99
const result = {};
1010

1111
result.path = pathname;
12-
result.search = mapValues(qs.parse(search), value => (isNil(value) ? true : value));
12+
result.search = mapValues(qs.parse(search), (value) => (isNil(value) ? true : value));
1313
result.hash = trimStart(hash, "#");
1414
result.url = `${pathname}${search}${hash}`;
1515

@@ -27,7 +27,7 @@ const location = {
2727

2828
confirmChange(handler) {
2929
if (isFunction(handler)) {
30-
return history.block(nextLocation => {
30+
return history.block((nextLocation) => {
3131
return handler(normalizeLocation(nextLocation), location);
3232
});
3333
} else {
@@ -60,12 +60,18 @@ const location = {
6060
// serialize search and keep existing search parameters (!)
6161
if (isObject(newLocation.search)) {
6262
newLocation.search = omitBy(extend({}, location.search, newLocation.search), isNil);
63-
newLocation.search = mapValues(newLocation.search, value => (value === true ? null : value));
63+
newLocation.search = mapValues(newLocation.search, (value) => (value === true ? null : value));
6464
newLocation.search = qs.stringify(newLocation.search);
6565
}
6666
}
6767
if (replace) {
68-
history.replace(newLocation);
68+
if (
69+
newLocation.pathname !== location.path ||
70+
newLocation.search !== qs.stringify(location.search) ||
71+
newLocation.hash !== location.hash
72+
) {
73+
history.replace(newLocation);
74+
}
6975
} else {
7076
history.push(newLocation);
7177
}

0 commit comments

Comments
 (0)