-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(astro): newer navigation aborts existing one (#10900)
* Detection and cancelation of previous navigations and view transitions * typos and wording * typos and wording * add test for animation cancelation * second round * final touches * final final touches * Clear the most recent navigation after view transition finished
- Loading branch information
Showing
6 changed files
with
266 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"astro": patch | ||
--- | ||
|
||
Detects overlapping navigation and view transitions and automatically aborts all but the most recent one. |
29 changes: 29 additions & 0 deletions
29
packages/astro/e2e/fixtures/view-transitions/src/pages/abort.astro
This file contains 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,29 @@ | ||
--- | ||
import { ViewTransitions } from 'astro:transitions'; | ||
--- | ||
<html> | ||
<head> | ||
<ViewTransitions /> | ||
</head> | ||
<body> | ||
<h1>Abort</h1> | ||
</body> | ||
</html> | ||
<script> | ||
import {navigate } from 'astro:transitions/client'; | ||
|
||
document.addEventListener('astro:before-preparation', (e) => { | ||
const originalLoader = e.loader; | ||
e.loader = async () => { | ||
const result = await originalLoader(); | ||
if (e.to.href.endsWith("/two")) { | ||
// delay loading of /two | ||
await new Promise((resolve) => setTimeout(resolve, 1100)); | ||
} | ||
} | ||
}); | ||
// starts later, but is faster and overtakes the slower navigation | ||
setTimeout(()=>navigate("/one"), 400); | ||
// starts now, but is to slow to keep its lead | ||
navigate("/two"); | ||
</script> |
25 changes: 25 additions & 0 deletions
25
packages/astro/e2e/fixtures/view-transitions/src/pages/abort2.astro
This file contains 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,25 @@ | ||
--- | ||
import { ViewTransitions, fade } from 'astro:transitions'; | ||
--- | ||
<html transition:animate="none"> | ||
<head> | ||
<ViewTransitions /> | ||
</head> | ||
<body> | ||
<h1 transition:name="h1" transition:animate={fade({duration:10000})}>Abort</h1> | ||
</body> | ||
</html> | ||
|
||
<style is:global>::view-transition-group(h1){animation:none}</style> | ||
<script> | ||
import {navigate } from 'astro:transitions/client'; | ||
|
||
setTimeout(()=>{ | ||
[...document.getAnimations()].forEach((a) => a.addEventListener('cancel', | ||
(e) => console.log("[test]",e.type, a.animationName))); | ||
console.log("[test] navigate to /one") | ||
navigate("/one"); | ||
}, 1000); | ||
console.log('[test] navigate to "."') | ||
navigate("/abort2"); | ||
</script> |
This file contains 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 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
Oops, something went wrong.