Commit ebf912b
Correctly update history for pop and replace actions (codesandbox#1158)
<!--
Please make sure you are familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).
Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!
-->
<!-- Is it a Bug fix, feature, docs update, ... -->
**What kind of change does this PR introduce?**
This alters how the fake browser (`<Preview>`) manages its `history` state.
Fixes codesandbox#1102.
<!-- You can also link to an open issue here -->
**What is the current behavior?**
Previously, all `urlchange` dispatches were treated as pushes (append URL to end of `history.state` and increment `state.historyPosition`). The fake browser's back and forward buttons got around this by manually updating the state, but manual `history.go()` and `history.replaceState()` calls resulted in an incorrect history array/position.
This behavior can be seen here:
https://codesandbox.io/s/vqw1mnnl9y
(steps to reproduce are described in codesandbox#1102)
<!-- if this is a feature change -->
**What is the new behavior?**
When `history.go()` is called, the `state.history` array is unchanged while the `state.historyPosition` is altered by the go amount.
When `history.replaceState()` is called, the `state.history` array is altered to replace the current entry at `state.historyPosition` with the new URL.
`BasePreview.handleForward()` and `BasePreview.handleBack()` no longer manually set state because they can rely on `commitUrl()` to handle this correctly.
<!-- Have you done all of these things? -->
**Checklist**:
<!-- add "N/A" to the end of each line that's irrelevant to your changes -->
<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->
- [ ] Documentation (N/A?)
- [ ] Tests (would probably be nice, but I'm not sure if there is a way to test this)
- [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [ ] Added myself to contributors table (already in there) <!-- this is optional, see the contributing guidelines for instructions -->
<!-- feel free to add additional comments -->
<!-- Thank you for contributing! -->1 parent 791979c commit ebf912b
File tree
2 files changed
+37
-31
lines changed- packages
- app/src/app/components/Preview
- sandbox-hooks
2 files changed
+37
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
388 | | - | |
| 388 | + | |
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
| |||
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | 560 | | |
567 | 561 | | |
568 | 562 | | |
569 | 563 | | |
570 | 564 | | |
571 | 565 | | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | 566 | | |
579 | 567 | | |
580 | | - | |
| 568 | + | |
581 | 569 | | |
582 | 570 | | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
591 | 597 | | |
592 | 598 | | |
593 | 599 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
0 commit comments