virtualstate / navigation

Native JavaScript navigation [web api] implementation
MIT License
77 stars 5 forks source link

commit resolves at the wrong time #3

Closed fabiancook closed 2 years ago

fabiancook commented 2 years ago

Prerequisites

Version

1.0.1-alpha.75

Node.js version

17.2.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.0.1

Description

committed is resolved too early, and instead should be resolved once current has been updated related to that entry.

https://github.com/WICG/app-history/blob/7c0332b30746b14863f717404402bc49e497a2b2/spec.bs#L860-L863

If there is no AppHistoryEntry in appHistory.entries with the given key, both will reject with an "InvalidStateError" DOMException.

For same-document traversals intercepted by the navigate event’s transitionWhile() method, committed will fulfill as soon as the traversal is processed and appHistory.current is updated, and finished will fulfill or reject according to the promises passed to transitionWhile().

For non-intercepted same-document traversals, both promises will fulfill as soon as the traversal is processed and appHistory.current is updated

For cross-document traversals, both promises will never settle.

Steps to Reproduce

async function currentChangedExample(appHistory: AppHistory) {
  const url = `/${Math.random()}`;
  await appHistory.navigate(url).comitted; 
  assert<AppHistoryEntry>(appHistory.current);
  assert(appHistory.current.url === url);
  assert(appHistory.transition); // The transition should still be in progress. 
}

Expected Behavior

The navigation change should be available once committed it resolved.

fabiancook commented 2 years ago

Resolved by https://github.com/virtualstate/app-history/pull/4