Skip to content

Commit

Permalink
fix: reinsert attribute to specify direction of ViewTransition (forwa…
Browse files Browse the repository at this point in the history
…rd / back) (#8109)
  • Loading branch information
martrapp authored and ematipico committed Aug 21, 2023
1 parent be6bbd2 commit a87cbe4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-foxes-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

fix: reinsert attribute to specify direction of ViewTransition (forward / back)
14 changes: 7 additions & 7 deletions packages/astro/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ const { fallback = 'animate' } = Astro.props as Props;

const parser = new DOMParser();

async function updateDOM(dir: Direction, html: string, state?: State, fallback?: Fallback) {
async function updateDOM(html: string, state?: State, fallback?: Fallback) {
const doc = parser.parseFromString(html, 'text/html');
doc.documentElement.dataset.astroTransition = dir;

// Check for a head element that should persist, either because it has the data
// attribute or is a link el.
Expand Down Expand Up @@ -233,15 +232,17 @@ const { fallback = 'animate' } = Astro.props as Props;
location.href = href;
return;
}
document.documentElement.dataset.astroTransition = dir;
if (supportsViewTransitions) {
finished = document.startViewTransition(() => updateDOM(dir, html, state)).finished;
finished = document.startViewTransition(() => updateDOM(html, state)).finished;
} else {
finished = updateDOM(dir, html, state, getFallback());
finished = updateDOM(html, state, getFallback());
}
try {
await finished;
} finally {
document.documentElement.removeAttribute('data-astro-transition');
// skip this for the moment as it tends to stop fallback animations
// document.documentElement.removeAttribute('data-astro-transition');
await runScripts();
markScriptsExec();
onload();
Expand Down Expand Up @@ -291,8 +292,7 @@ const { fallback = 'animate' } = Astro.props as Props;
transitionEnabledOnThisPage()
) {
ev.preventDefault();
navigate('forward', link.href, { index: currentHistoryIndex, scrollY: 0 });
currentHistoryIndex++;
navigate('forward', link.href, { index: ++currentHistoryIndex, scrollY: 0 });
const newState: State = { index: currentHistoryIndex, scrollY };
persistState({ index: currentHistoryIndex - 1, scrollY });
history.pushState(newState, '', link.href);
Expand Down

0 comments on commit a87cbe4

Please sign in to comment.