Skip to content

Commit

Permalink
fix(storefront): Update <ViewTransitions> to skip /app/* routes and…
Browse files Browse the repository at this point in the history
… dont prefetch with role=button

`<a role=button>` commonly used as no-JS interaction fallback, thus, on-click redirect may be prevented after component hydration. Should not prefetch.

/app/* are "real" SPA routes, ensure not prefecthing and forcing reload
  • Loading branch information
leomp12 committed Oct 25, 2023
1 parent dc5ed9a commit efc2dba
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/storefront/src/lib/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ const { fallback = 'animate' } = Astro.props as Props;
link.dataset.astroReload !== undefined ||
link.hasAttribute('download') ||
!link.href ||
link.pathname.startsWith('/app/') || // "real" SPA routes
(link.target && link.target !== '_self') ||
link.origin !== location.origin ||
ev.button !== 0 || // left clicks only
Expand Down Expand Up @@ -384,8 +385,13 @@ const { fallback = 'animate' } = Astro.props as Props;
if (
el.origin === location.origin &&
el.pathname !== location.pathname &&
!el.pathname.startsWith('/app/') && // "real" SPA routes
el.dataset.astroReload === undefined &&
!el.hasAttribute('download') &&
/* <a role=button> commonly used as no-JS interaction fallback,
thus, on-click redirect may be prevented after component hydration.
Shouldn't prefetch. */
el.role !== 'button' &&
transitionEnabledOnThisPage()
) {
maybePrefetch(el.pathname);
Expand Down

0 comments on commit efc2dba

Please sign in to comment.