summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar matthewp <matthewp@users.noreply.github.com> 2023-09-07 18:24:12 +0000
committerGravatar astrobot-houston <fred+astrobot@astro.build> 2023-09-07 18:24:12 +0000
commit5c23bf1c901006ea9615827430642c2041a6cf8d (patch)
tree750989d1b231bc8764194452653cfd659496fad2
parentf66053a1ea0a4e3bdb0b0df12bb1bf56e1ea2618 (diff)
downloadastro-5c23bf1c901006ea9615827430642c2041a6cf8d.tar.gz
astro-5c23bf1c901006ea9615827430642c2041a6cf8d.tar.zst
astro-5c23bf1c901006ea9615827430642c2041a6cf8d.zip
[ci] format
-rw-r--r--packages/astro/components/ViewTransitions.astro16
-rw-r--r--packages/astro/e2e/view-transitions.test.js1
2 files changed, 6 insertions, 11 deletions
diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro
index 049355461..7b556c252 100644
--- a/packages/astro/components/ViewTransitions.astro
+++ b/packages/astro/components/ViewTransitions.astro
@@ -34,12 +34,12 @@ const { fallback = 'animate' } = Astro.props as Props;
// can use that to determine popstate if going forward or back.
let currentHistoryIndex = 0;
if (history.state) {
- // we reloaded a page with history state
+ // we reloaded a page with history state
// (e.g. history navigation from non-transition page or browser reload)
currentHistoryIndex = history.state.index;
scrollTo({ left: 0, top: history.state.scrollY });
} else if (transitionEnabledOnThisPage()) {
- history.replaceState({index: currentHistoryIndex, scrollY}, '');
+ history.replaceState({ index: currentHistoryIndex, scrollY }, '');
}
const throttle = (cb: (...args: any[]) => any, delay: number) => {
let wait = false;
@@ -201,11 +201,7 @@ const { fallback = 'animate' } = Astro.props as Props;
scrollTo(0, state.scrollY); // usings default scrollBehavior
}
!state &&
- history.pushState(
- { index: ++currentHistoryIndex, scrollY: initialScrollY },
- '',
- loc.href
- );
+ history.pushState({ index: ++currentHistoryIndex, scrollY: initialScrollY }, '', loc.href);
triggerEvent('astro:after-swap');
};
@@ -253,7 +249,7 @@ const { fallback = 'animate' } = Astro.props as Props;
async function navigate(dir: Direction, loc: URL, state?: State) {
let finished: Promise<void>;
- const href=loc.href;
+ const href = loc.href;
const { html, ok } = await getHTML(href);
// If there is a problem fetching the new page, just do an MPA navigation to it.
if (!ok) {
@@ -411,9 +407,9 @@ const { fallback = 'animate' } = Astro.props as Props;
addEventListener('load', onPageLoad);
// There's not a good way to record scroll position before a back button.
// So the way we do it is by listening to scrollend if supported, and if not continuously record the scroll position.
- const updateState = () => {
+ const updateState = () => {
persistState({ ...history.state, scrollY });
- }
+ };
if ('onscrollend' in window) addEventListener('scrollend', updateState);
else addEventListener('scroll', throttle(updateState, 300));
diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js
index f5a63c67c..34f1a4e02 100644
--- a/packages/astro/e2e/view-transitions.test.js
+++ b/packages/astro/e2e/view-transitions.test.js
@@ -544,4 +544,3 @@ test.describe('View Transitions', () => {
await expect(p, 'should have content').toHaveText('Page 1');
});
});
-