-
-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor router transitions to prefer Navigation API with History fallback #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
11
commits into
main
Choose a base branch
from
copilot/refactor-replace-history-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4332a39
Initial plan
Copilot aab8dcb
refactor: use Navigation API for route transitions
Copilot e5fb1d4
test: align form navigation state handling
Copilot e777472
refactor: finalize navigation state handling
Copilot 44ad99b
test: cover empty navigation state fallback
Copilot 195be7c
chore: tighten navigation listener and test spy
Copilot 564a7e4
refactor: require Navigation API for route transitions
Copilot d9f3752
chore: switch Navigation API typings to dom-navigation
Copilot 04c2aea
refactor: harden navigation state title extraction
Copilot 7e39219
[migrate] upgrade to PNPM 11, Lint-Staged 17, Puppeteer 25, FS-Match …
TechQuery 07dadc8
[refactor] replace Manual Link & Form listeners with Navigation API
TechQuery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** @jest-environment jsdom */ | ||
|
|
||
| import { History, RouterMode } from '../source/History'; | ||
|
|
||
| describe('History', () => { | ||
| let navigate: jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| document.head.innerHTML = '<title>Cell Router</title>'; | ||
| document.body.innerHTML = ''; | ||
| navigate = jest.fn(); | ||
|
|
||
| Object.defineProperty(window, 'navigation', { | ||
| writable: true, | ||
| configurable: true, | ||
| value: { | ||
| navigate, | ||
| addEventListener: jest.fn(), | ||
| currentEntry: { getState: () => ({ title: 'Cell Router' }) } | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it('should use Navigation API to navigate links', () => { | ||
| const history = new History('https://example.com', RouterMode.history); | ||
| const link = document.createElement('a'); | ||
|
|
||
| link.title = 'List page'; | ||
| link.setAttribute('href', '/list/1'); | ||
|
|
||
| history.handleLink(new MouseEvent('click', { cancelable: true }), link); | ||
|
|
||
| expect(navigate).toHaveBeenCalledWith('/list/1', { | ||
| state: { title: 'List page' }, | ||
| history: 'push' | ||
| }); | ||
| expect(history.path).toBe('/list/1'); | ||
| }); | ||
|
|
||
| it('should use Navigation API to submit GET forms', () => { | ||
| const history = new History('https://example.com', RouterMode.history); | ||
| const form = document.createElement('form'); | ||
|
|
||
| form.setAttribute('action', '/search'); | ||
| form.setAttribute('method', 'get'); | ||
| form.innerHTML = '<input name="keyword" value="router" />'; | ||
|
|
||
| history.handleForm(new Event('submit', { cancelable: true }), form); | ||
|
|
||
| expect(navigate).toHaveBeenCalledWith('/search?keyword=router', { | ||
| state: { title: 'Cell Router' }, | ||
| history: 'push' | ||
| }); | ||
| expect(history.path).toBe('/search?keyword=router'); | ||
| }); | ||
|
Comment on lines
+50
to
+62
|
||
|
|
||
| it('should restore title from Navigation API state', () => { | ||
| Object.defineProperty(window, 'navigation', { | ||
| writable: true, | ||
| configurable: true, | ||
| value: { | ||
| addEventListener: jest.fn(), | ||
| navigate, | ||
| currentEntry: { getState: () => ({ title: 'Navigation title' }) } | ||
| } | ||
| }); | ||
|
|
||
| new History('https://example.com', RouterMode.history); | ||
|
|
||
| expect(document.title).toBe('Navigation title'); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.