Improvements to history management #2238
Draft
+34
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before I start going deep down the rabbithole making sure this is all cleaned up and tested etc, I'd like to get some feedback on if you're likely to accept this PR.
I've had some issues with inertia's history handling during a migration to inertia with a legacy app.
The problem is that inertia assumes that all history manipulation is handled with inertia's router.push / router.replace methods, which is not the case.
There are two ways this causes issues:
es that the url stored in currentPage is the correct current url, which it might not be if some other code has pushed a new state onto the stack in the meantime.
This causes a bug that means that if you are currently on and inertia page http://example.com/foo, and run
pushState({}, "", "http://example.com/foo?bar=123")
, you end up in a situation that inertia can't handle wella. If you scroll the page, the scroll handler will pushState with the latest inertia page url it knows about, and the query param will disappear
b. If you hit the back button, inertia will try to handle the pop state event with the empty state with no inertia page in it, and will error out trying to render a component.
I would like to fix these issues to make inertia more interoperable especially during stack migrations, so please let me know if going down this path is likely to align with the project goals and if so I'll improve the handling here to make things a little smoother
Note: I'm not actually sure just an option to turn off scroll preservation makes the most sense here - it might make more sense to make the scroll preservation smarter such that it handles non-inertia history state more gracefully but still works with inertia state