Skip to content

Commit

Permalink
fix: avoid adding onNavigate if startViewTransition is not in document
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Sep 24, 2023
1 parent 1ab48d0 commit 6e6072c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gold-hornets-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sveltekit-view-transition': patch
---

avoid adding onNavigate if startViewTransition is not in document
4 changes: 3 additions & 1 deletion src/lib/sveltekit-view-transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterNavigate, onNavigate } from '$app/navigation';
import type { OnNavigate } from '@sveltejs/kit';
import { SetOfCallback } from './utils';
import { onDestroy } from 'svelte';
import { browser } from '$app/environment';

export type TransitionAction = {
name:
Expand Down Expand Up @@ -334,9 +335,10 @@ function transition(node: HTMLElement | SVGElement, props: string | TransitionAc

export function setupViewTransition() {
// only register once the onNavigate
if (on_navigate_registered === 0) {
if (on_navigate_registered === 0 && browser && document.startViewTransition) {
on_navigate_registered++;
onNavigate((navigation) => {
// this should never happen but better be safe than sorry
if (!document.startViewTransition) return;
return new Promise((resolve) => {
run_all_events('before-start-view-transition', { navigation });
Expand Down

1 comment on commit 6e6072c

@vercel
Copy link

@vercel vercel bot commented on 6e6072c Sep 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.