virtualstate / navigation

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

NavigationTransition.from.key is the same as NavigationDestination.key #31

Open nxtexe opened 2 months ago

nxtexe commented 2 months ago

Prerequisites

Version (i.e. v2.x.x)

1.0.1-alpha.202

Node.js version (i.e. 18.x, or N/A)

No response

Operating system

N/A

Operating system version (i.e. 20.04, 11.3, 10, or N/A)

N/A

Description

During a NavigateEvent interception the NavigationTransition.from on the navigation object has the same key as NavigationDestination on the NavigateEvent object. The key doesn't seem to be an existing history entry key. I've been using the API in chromium for a while now and built my router around that so I'm decently certain this is a bug.

Steps to Reproduce

  1. Apply the polyfill using the applyPolyfill function with history, interceptEvents, patch, persist and persistState config options set to true.
  2. Attach an event listener to window.navigation for navigation events.
  3. Observe the key on navigation.transition.from and event.destination.

Expected Behavior

When NavigateEvent.navigationType is push the key should be empty. When NavigateEvent.navigationType is traverse, replace or reload the key should be an existing history entry key.

fabiancook commented 2 months ago

Would it be possible to reproduce this as an example by chance?

e.g. https://github.com/virtualstate/navigation/blob/main/example/webcomponents.html

It can include assertions as to what should be expected.

nxtexe commented 2 months ago

Sure, here's the example. Navigate to any route and an assertion is thrown.