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

Bringing back currentchange, or maybe change in general #148

Closed
domenic opened this issue Aug 13, 2021 · 2 comments
Closed

Bringing back currentchange, or maybe change in general #148

domenic opened this issue Aug 13, 2021 · 2 comments
Labels
addition A proposed addition which could be added later without impacting the rest of the API

Comments

@domenic
Copy link
Collaborator

domenic commented Aug 13, 2021

We removed currentchange in #125 due to lack of use cases. #14 has some discussion.

Since then a couple of use cases have come up for currentchange:

  • Providing a clear point in time when, even if the transition is not finished, the current entry/URL has updated. This could be used to kick off processes which are independent of the transition, e.g., sending certain types of analytics, or updating parts of your UI, or similar. Stated another way, this gives you an immediate signal that the navigate event was not canceled.

  • Relatedly, easing the migration from popstate and hashchange. Codebases today might want to not embrace the full app history paradigm of the navigate event and converting cross-document navs to same-document, but still get a more reliable change event.

This currentchange event would fire whenever either appHistory.current changes value, or when appHistory.current gets updated, e.g. by history.replaceState() or appHistory.updateCurrent().

It would probably be useful if the event object contained a property like event.previous or event.from so you could compare to the old value? But that's a bit unusual for change events on the web platform, so maybe not.


But then I was thinking, why not go further? We could fire an event when anything in entries() changes. In particular, this event would fire if entries from far back in the list disappear (due to browser policies on maximum number of entries, or the user clearing their history). Or if new entries grow in the back of the list (due to #45). Or if we allow other modifications like #9.

The use cases this would enable, in addition to the above, are:

  • Displaying a live-updating in-page history navigation list. (The explainer kind of mentions this case, but seems like I forgot to update it when we removed currentchange: "In combination with the following section, the entries() API also allows applications to display a UI allowing navigation through the app history list.")

  • All the use cases that the per-entry dispose event is used for, but perhaps in a cleaner fashion. See also discussion in An event for when entries disappear for other reasons than forward-pruning #72.

Similarly the event object here could contain e.g. addedEntries, removedEntries, updatedEntries. Or we could have the developer save the old entries list and compare manually.

@domenic domenic added the addition A proposed addition which could be added later without impacting the rest of the API label Aug 13, 2021
@samthor
Copy link
Contributor

samthor commented Aug 25, 2021

Echoing my summary from chat, I think it'll be hard to describe exactly when users should add events handlers to an entry (or perhaps a number of entries created on page load, e.g., because of a reload). The current example in the spec doc just shows adding entries after programmatic navigation, which implies you know the nav is coming.

This becomes clearer to me in a centralized change/currentchange event.

domenic added a commit that referenced this issue Sep 23, 2021
domenic added a commit that referenced this issue Oct 12, 2021
Part of #148.

This removes the interception-details.md document, as it wasn't bringing clear value and maintaining it was a pain. Web platform tests are probably a better place for such detailed event sequences.
@domenic
Copy link
Collaborator Author

domenic commented Mar 14, 2022

Split off just the remaining part (a general "any entry changed" event) into #205

@domenic domenic closed this as completed Mar 14, 2022
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