Description
Consider a case where you do
appHistory.navigate("other-url").then(onFulfilled, onRejected);
and you have no navigate
event handler to convert this into a same-document navigation. Here onFulfilled
and onRejected
will never be called, because by the time the navigate goes through, your document has been unloaded, so there's no way for onFulfilled
and onRejected
to run. Makes sense.
Of course, if you do that but then add a navigate
handler which converts the navigation into a same-document navigation using event.respondWith()
, then one of your handlers will get called, after the promise passed to respondWith()
settles. That's the main use case for the returned promise.
Now consider the following case, again with no navigate
event handlers:
frames[0].appHistory.navigate("other-url").then(onFulfilled, onRejected);
Here, because we're navigating a subframe, it's very conceivable that onFulfilled
or onRejected
could be called, at some point after the cross-document navigation of the subframe finishes. (When, exactly? The load event? DOMContentLoaded? pageshow? readystatechange? Similar issues to #31.)
Should this work?
Our tentative answer is "no": cross-document navigations should never settle the promise. It seems like a good deal of work to implement and it's outside the usual use cases of app history which are really supposed to be about your own frame.
On the other hand, I've written a lot of test code which does the equivalent of
iframe.src = "foo";
await new Promise(r => iframe.onload = r);
which could be nice to replace (for same-origin iframes) with
await iframe.contentWindow.appHistory.navigate("foo");
See also whatwg/html#5725; /cc @jakearchibald @annevk. So hmm. Maybe it would be nice.