Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving data from replaced entries #41

Open
domenic opened this issue Feb 17, 2021 · 1 comment
Open

Retrieving data from replaced entries #41

domenic opened this issue Feb 17, 2021 · 1 comment
Labels
addition A proposed addition which could be added later without impacting the rest of the API

Comments

@domenic
Copy link
Collaborator

domenic commented Feb 17, 2021

A nice feature of the navigation API is that (unless we implement #9) data is almost never "lost". This solves a lot of problems we hear about today where history.state is unreliable, or there's no way to easily know what your previous history entry was without keeping a side table, etc.

However, there is one place in the current design where data can be lost: if you use navigation.navigate(url, { replace: true }), history.replaceState(), or location.replace(), the current navigation API history entry data disappears.

I say "kind of" because object references get replaced, not updated. So you could have a reference to the old NavigationHistoryEntry object, which would allow you to access url and getState(). (But it's no longer in appHistory.entries().)

We could pretty easily keep these replaced NavigationHistoryEntrys around and expose them. For example:

  • Each app history entry could have a replaced property that is null, or the entry it replaced. (This allows potentially chaining, e.g. navigation.currentEntry.replaced.replaced.replaced.) This lets you access them forever. (Is this a problem for memory usage?)

  • The currententrychange event could have a replaced property which contains the replaced NavigationHistoryEntry. This lets unrelated parts of the code (i.e., not the code doing navigation.navigate(, { replace: true })) grab important data as necessary.

@domenic domenic added the addition A proposed addition which could be added later without impacting the rest of the API label Feb 17, 2021
@tbondwilkinson
Copy link
Contributor

The only other case where they got lost is if they're in the forward stack, or in most browsers if it's evicted by the back stack growing too long (I believe the limit is 40). I think the dispose event helps to find out when this happens though, so it's not a major concern.

Another possible solution is to identify in the dispose event that it was a replace, rather than an evict, which would allow you to grab a handle on the entry (and state) that's replacing yours.

domenic added a commit that referenced this issue Apr 2, 2021
This gives insight into any "ongoing" navigation, i.e. a navigation that hasn't yet reached navigationsuccess/navigationerror because the promise passed to respondWith() has not yet settled.

Additionally:

* Removes the finished property from every AppHistoryEntry, which is nice because it only ever really made sense on the current entry; it was about the transition. Instead, the presence or nullness of appHistory.transition can be used.
* Adds a type property to AppHistoryNavigateEvent since we're going to have it on appHistory.transition anyway so having it earlier (before respondWith() is called) seems very reasonable.

Closes #86. Closes #11 by adding the appHistory.transition.finished promise.

Helps with #41 as you can retrieve data from the replaced entry, at least during the transition, with appHistory.transition.previous.

Probably helps with #14 (although currentchange needs a bit of an overhaul) since appHistory.transition has the sort of useful information discussed there, such as the previous entry or the type of navigation.
domenic added a commit that referenced this issue Apr 5, 2021
This gives insight into any "ongoing" navigation, i.e. a navigation that hasn't yet reached navigationsuccess/navigationerror because the promise passed to respondWith() has not yet settled.

Additionally:

* Removes the finished property from every AppHistoryEntry, which is nice because it only ever really made sense on the current entry; it was about the transition. Instead, the presence or nullness of appHistory.transition can be used.

* Adds a type property to AppHistoryNavigateEvent since we're going to have it on appHistory.transition anyway so having it earlier (before respondWith() is called) seems very reasonable.

Closes #86. Closes #11 by adding the appHistory.transition.finished promise.

Helps with #41 as you can retrieve data from the replaced entry, at least during the transition, with appHistory.transition.from.

Probably helps with #14 (although currentchange needs a bit of an overhaul) since appHistory.transition has the sort of useful information discussed there, such as the previous entry or the type of navigation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition A proposed addition which could be added later without impacting the rest of the API
Projects
None yet
Development

No branches or pull requests

2 participants