Skip to content

Commit da6e3da

Browse files
authored
fix: reinsert attribute to specify direction of ViewTransition (forward / back) (#8109)
1 parent d6b4943 commit da6e3da

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

.changeset/wet-foxes-sleep.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
fix: reinsert attribute to specify direction of ViewTransition (forward / back)

packages/astro/components/ViewTransitions.astro

+7-7
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ const { fallback = 'animate' } = Astro.props as Props;
101101

102102
const parser = new DOMParser();
103103

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

108107
// Check for a head element that should persist, either because it has the data
109108
// attribute or is a link el.
@@ -233,15 +232,17 @@ const { fallback = 'animate' } = Astro.props as Props;
233232
location.href = href;
234233
return;
235234
}
235+
document.documentElement.dataset.astroTransition = dir;
236236
if (supportsViewTransitions) {
237-
finished = document.startViewTransition(() => updateDOM(dir, html, state)).finished;
237+
finished = document.startViewTransition(() => updateDOM(html, state)).finished;
238238
} else {
239-
finished = updateDOM(dir, html, state, getFallback());
239+
finished = updateDOM(html, state, getFallback());
240240
}
241241
try {
242242
await finished;
243243
} finally {
244-
document.documentElement.removeAttribute('data-astro-transition');
244+
// skip this for the moment as it tends to stop fallback animations
245+
// document.documentElement.removeAttribute('data-astro-transition');
245246
await runScripts();
246247
markScriptsExec();
247248
onload();
@@ -291,8 +292,7 @@ const { fallback = 'animate' } = Astro.props as Props;
291292
transitionEnabledOnThisPage()
292293
) {
293294
ev.preventDefault();
294-
navigate('forward', link.href, { index: currentHistoryIndex, scrollY: 0 });
295-
currentHistoryIndex++;
295+
navigate('forward', link.href, { index: ++currentHistoryIndex, scrollY: 0 });
296296
const newState: State = { index: currentHistoryIndex, scrollY };
297297
persistState({ index: currentHistoryIndex - 1, scrollY });
298298
history.pushState(newState, '', link.href);

0 commit comments

Comments
 (0)