Skip to content

refactor: Switch to Navigation API#75

Draft
rschristian wants to merge 8 commits intov3from
refactor/navigation-api
Draft

refactor: Switch to Navigation API#75
rschristian wants to merge 8 commits intov3from
refactor/navigation-api

Conversation

@rschristian
Copy link
Copy Markdown
Member

@rschristian rschristian commented Mar 2, 2025

No intention of landing this anytime soon, it's still Chrome-only, but it's a fun & promising test.

Blocked on the upcoming .sourceElement property, else we can't handle anchor target attributes correctly.

@rschristian rschristian force-pushed the v3 branch 3 times, most recently from d365844 to c113e3b Compare March 3, 2025 03:46
@rschristian rschristian force-pushed the refactor/navigation-api branch 2 times, most recently from 01b351c to acf137f Compare March 3, 2025 09:03
@rschristian rschristian force-pushed the refactor/navigation-api branch 2 times, most recently from 4b99ec5 to c68ff03 Compare April 10, 2025 03:34
@rschristian rschristian force-pushed the v3 branch 3 times, most recently from 394bd76 to bb7ce7f Compare August 10, 2025 22:29
@rschristian rschristian force-pushed the refactor/navigation-api branch 2 times, most recently from b23faff to 4a823d7 Compare August 10, 2025 23:11
@pspeter3
Copy link
Copy Markdown

Now that the Navigation API is baseline, is this something to consider?

@pspeter3
Copy link
Copy Markdown

sourceElement is also supported in all major browsers https://developer.mozilla.org/en-US/docs/Web/API/NavigateEvent/sourceElement

@rschristian
Copy link
Copy Markdown
Member Author

Yep, I've been meaning to come back to it but haven't had the time unfortunately.

I might want offer it as a separate entrypoint, say preact-iso/navigation-api, as I'm not sure we can reasonably switch over (in a new major) given the limited number of compatible browser versions.

@pspeter3
Copy link
Copy Markdown

That makes sense. Do you want to maybe include some of the changes you were thinking about for v3 as well?

@rschristian
Copy link
Copy Markdown
Member Author

Might do, that gets a bit more murky. Will think about it

@rschristian rschristian force-pushed the v3 branch 2 times, most recently from 02d84b4 to 1ab8157 Compare March 5, 2026 01:54
* fix: Handle traversal navigation when canIntercept is false

For back/forward traversals, canIntercept may be false when the destination
entry was created via history.replaceState, but the URL changes regardless.
Only gate on canIntercept for push/replace navigations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: Remove non-configurable window.location stub

sinon cannot stub window.location in modern browsers as it is non-configurable
and non-writable. The stub was a leftover from before the Navigation API refactor
— location.assign/replace are no longer used in the router or tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: Fix _top/_parent navigation crashing WTR in CI

WTR runs tests inside an iframe. Clicking links with target="_top" or
target="_parent" targets the WTR runner frame (canIntercept=false), so
calling e.intercept() unconditionally throws and lets the navigation
escape — crashing the entire test session.

Fix by:
- Checking canIntercept before calling e.intercept() in test handlers
- Skipping _top/_parent tests (like _blank) since they can't be
  meaningfully tested in an iframe context

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: Remove unused sinon afterEach cleanup

sinon.restore() in afterEach was only needed for the window.location stub
which was removed. The remaining sinon.spy (scrollTo) is restored manually.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* revert: Undo traversal/canIntercept handling that broke tests

Reverts the isTraversal guard and conditional e.intercept() from
router.js, and restores the original test handler behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: Gate navigation intercept on canIntercept check

Move canIntercept to the top of the guard conditions so navigations
that cannot be intercepted (e.g. back/forward to history.replaceState
entries) are skipped cleanly without calling e.intercept().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: Revert scope handler to unconditional intercept

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: Skip navigation tests, add a big ol' TODO

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Ryan Christian <rchristian@ryanchristian.dev>
@rschristian rschristian force-pushed the refactor/navigation-api branch from cc6b19f to b4d12f3 Compare March 24, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants