Skip to content

Commit 7661f48

Browse files
authored
chores(transitions): replace deprecated constants with string literals (#16076)
1 parent be661fb commit 7661f48

2 files changed

Lines changed: 9 additions & 18 deletions

File tree

packages/astro/src/transitions/events.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ export const TRANSITION_AFTER_SWAP = 'astro:after-swap';
1212
/** @deprecated This will be removed in Astro 7 */
1313
export const TRANSITION_PAGE_LOAD = 'astro:page-load';
1414

15-
type Events =
16-
| typeof TRANSITION_AFTER_PREPARATION
17-
| typeof TRANSITION_AFTER_SWAP
18-
| typeof TRANSITION_PAGE_LOAD;
15+
type Events = 'astro:after-preparation' | 'astro:after-swap' | 'astro:page-load';
1916
export const triggerEvent = (name: Events) => document.dispatchEvent(new Event(name));
20-
export const onPageLoad = () => triggerEvent(TRANSITION_PAGE_LOAD);
17+
export const onPageLoad = () => triggerEvent('astro:page-load');
2118

2219
/*
2320
* Common stuff
@@ -91,7 +88,7 @@ export class TransitionBeforePreparationEvent extends BeforeEvent {
9188
loader: (event: TransitionBeforePreparationEvent) => Promise<void>,
9289
) {
9390
super(
94-
TRANSITION_BEFORE_PREPARATION,
91+
'astro:before-preparation',
9592
{ cancelable: true },
9693
from,
9794
to,
@@ -116,15 +113,15 @@ export class TransitionBeforePreparationEvent extends BeforeEvent {
116113
*/
117114
/** @deprecated This will be removed in Astro 7 */
118115
export const isTransitionBeforeSwapEvent = (value: any): value is TransitionBeforeSwapEvent =>
119-
value.type === TRANSITION_BEFORE_SWAP;
116+
value.type === 'astro:before-swap';
120117
export class TransitionBeforeSwapEvent extends BeforeEvent {
121118
readonly direction: Direction | string;
122119
readonly viewTransition: ViewTransition;
123120
swap: () => void;
124121

125122
constructor(afterPreparation: BeforeEvent, viewTransition: ViewTransition) {
126123
super(
127-
TRANSITION_BEFORE_SWAP,
124+
'astro:before-swap',
128125
undefined,
129126
afterPreparation.from,
130127
afterPreparation.to,
@@ -173,7 +170,7 @@ export async function doPreparation(
173170
if (document.dispatchEvent(event)) {
174171
await event.loader();
175172
if (!event.defaultPrevented) {
176-
triggerEvent(TRANSITION_AFTER_PREPARATION);
173+
triggerEvent('astro:after-preparation');
177174
if (event.navigationType !== 'traverse') {
178175
// save the current scroll position before we change the DOM and transition to the new page
179176
updateScrollPosition({ scrollX, scrollY });

packages/astro/src/transitions/router.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { internalFetchHeaders } from 'virtual:astro:adapter-config/client';
22
import type { TransitionBeforePreparationEvent } from './events.js';
3-
import {
4-
doPreparation,
5-
doSwap,
6-
TRANSITION_AFTER_SWAP,
7-
onPageLoad,
8-
triggerEvent,
9-
updateScrollPosition,
10-
} from './events.js';
3+
4+
import { doPreparation, doSwap, onPageLoad, triggerEvent, updateScrollPosition } from './events.js';
115
import { detectScriptExecuted } from './swap-functions.js';
126
import type { Direction, Fallback, Options } from './types.js';
137

@@ -319,7 +313,7 @@ async function updateDOM(
319313
animateFallbackOld,
320314
);
321315
moveToLocation(swapEvent.to, swapEvent.from, options, pageTitleForBrowserHistory, historyState);
322-
triggerEvent(TRANSITION_AFTER_SWAP);
316+
triggerEvent('astro:after-swap');
323317

324318
// Resolve the finished promise of the simulation's ViewTransition.
325319
// For 'animate', wait for the new-page animation to complete first.

0 commit comments

Comments
 (0)