navigation icon indicating copy to clipboard operation
navigation copied to clipboard

document.location.href should be updated before intercept handler is run.

Open LEW21 opened this issue 8 months ago • 1 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched existing issues to ensure it has not already been reported

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

1.0.1-alpha.209

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

No response

Operating system

None

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

No response

Description

As per MDN ("The URL has already changed"), the page URL should be already changed when the interception handler is called.

Steps to Reproduce

window.navigation.addEventListener('navigate', ev => {
	ev.intercept({
		async handler() {
			console.log(document.location.pathname)
		}
	})
})

window.navigation.navigate('/xyz')

Expected Behavior

In Chrome, this logs '/xyz'. With the polyfill, it logs whatever the pathname was before.

LEW21 avatar Apr 11 '25 15:04 LEW21

This appears to be because history is updated only on current entry change

https://github.com/virtualstate/navigation/blob/6f66ed21bb050345e937002f847fbcdc9eb30b7e/src/get-polyfill.ts#L756-L779

I'll investigate updating this earlier in the polyfill and then reverting the change if it was aborted.

fabiancook avatar Apr 25 '25 00:04 fabiancook