Replace the tab entries on first load #3041
Merged
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.
Context
When a tab history object is created, it already contains a single entry with the root pathname "/". In a previous PR, I changed the order of creating session tabs to 1) create the tab, 2) load the url in that tab. This made the code much easier to reason about, but it left this dangling "/" entry in the tab history. The meant the back button was enabled on a newly created session tab. If clicked, the tab would go back to the "/" url which renders a blank page without any buttons. You could not get back to your session if you ended up in this state. Could be very irritating if you needed those session history queries.
Changes
So this PR changes the BrowserTab#load function. It checks if the tab history entries equals ["/"]. If it does, it resets the entries to [] and the index to -1, the pushes the new pathname onto the history. This is exactly what we want. The "action" on the entry is still "push" instead of "replace" so that all the normal things happen.
Tests
There is an e2e test added that checks the back button on a newly created session tab to ensure it is disabled, meaning there is only one item in the tab history entries.