Skip to content

Commit

Permalink
Trigger custom events to simulate Astro load lifecycle
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Daun <[email protected]>
  • Loading branch information
daun committed Nov 17, 2024
1 parent 9c5f8fb commit 6143476
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export function buildInitScript(options: Partial<Options> = {}): string {
]
});
const dispatch = (name) => document.dispatchEvent(new Event(name));
// Trigger custom events to simulate Astro load lifecycle
swup.hooks.before('content:replace', () => dispatch('astro:before-swap'));
swup.hooks.on('content:replace', () => dispatch('astro:after-swap'));
swup.hooks.on('page:view', () => dispatch('astro:page-load'));
${globalInstance ? 'window.swup = swup;' : ''}
}
Expand Down

0 comments on commit 6143476

Please sign in to comment.