Skip to content

Commit

Permalink
Only redefine pushstate/replacestate in the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Dec 14, 2023
1 parent 236877e commit b645a85
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ type Events = 'astro:page-load' | 'astro:after-swap';

// Create bound versions of pushState/replaceState so that Partytown doesn't hijack them,
// which breaks Firefox.
const pushState = history.pushState.bind(history);
const replaceState = history.replaceState.bind(history);
const inBrowser = import.meta.env.SSR === false;
const pushState = (inBrowser && history.pushState.bind(history)) as typeof history.pushState;
const replaceState = (inBrowser && history.replaceState.bind(history)) as typeof history.replaceState;

// only update history entries that are managed by us
// leave other entries alone and do not accidently add state.
Expand All @@ -22,7 +23,7 @@ export const updateScrollPosition = (positions: { scrollX: number; scrollY: numb
replaceState({ ...history.state, ...positions }, '');
}
};
const inBrowser = import.meta.env.SSR === false;


export const supportsViewTransitions = inBrowser && !!document.startViewTransition;

Expand Down

0 comments on commit b645a85

Please sign in to comment.