Skip to content

Commit bdfd728

Browse files
pshrmnCompuIves
authored andcommitted
Pushing wipes "future" history (codesandbox#1206)
* Pushing wipes "future" history * Sanity check
1 parent 8ea3d55 commit bdfd728

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/app/src/app/components/Preview/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class BasePreview extends React.Component<Props, State> {
590590
break;
591591
default:
592592
this.setState({
593-
history: [...history, url],
593+
history: [...history.slice(0, historyPosition + 1), url],
594594
historyPosition: historyPosition + 1,
595595
urlInAddressBar: url,
596596
});

packages/sandbox-hooks/url-listeners.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ let historyPosition = -1;
1717
let disableNextHashChange = false;
1818

1919
function pushHistory(url, state) {
20-
historyPosition += 1;
21-
historyList.length = historyPosition + 1;
22-
historyList[historyPosition] = { url, state };
20+
// remove "future" locations
21+
historyList.splice(historyPosition + 1);
22+
historyList.push({ url, state });
23+
historyPosition = historyList.length - 1;
2324
}
2425

2526
function pathWithHash(location) {

0 commit comments

Comments
 (0)