diff --git a/.changeset/chilled-elephants-develop.md b/.changeset/chilled-elephants-develop.md new file mode 100644 index 000000000000..06c1da4520af --- /dev/null +++ b/.changeset/chilled-elephants-develop.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Adds an `astro:beforeload` event for the dark mode use-case diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 2df794679ea4..33cad86a2d8c 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -13,6 +13,7 @@ const { fallback = 'animate' } = Astro.props as Props; + diff --git a/packages/astro/e2e/fixtures/view-transitions/src/components/Layout.astro b/packages/astro/e2e/fixtures/view-transitions/src/components/Layout.astro index e4dc54015c4c..9d94681cda57 100644 --- a/packages/astro/e2e/fixtures/view-transitions/src/components/Layout.astro +++ b/packages/astro/e2e/fixtures/view-transitions/src/components/Layout.astro @@ -1,5 +1,6 @@ --- import { ViewTransitions } from 'astro:transitions'; +import DarkMode from './DarkMode.astro'; interface Props { link?: string; @@ -12,6 +13,7 @@ const { link } = Astro.props as Props; Testing {link ? : ''} +
diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index ee5db3f2ffbd..2dd02afe21ba 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -159,6 +159,19 @@ test.describe('View Transitions', () => { await expect(article, 'should have script content').toHaveText('works'); }); + test('astro:beforeload event fires right before the swap', async ({ page, astro }) => { + // Go to page 1 + await page.goto(astro.resolveUrl('/one')); + let p = page.locator('#one'); + await expect(p, 'should have content').toHaveText('Page 1'); + + // go to page 2 + await page.click('#click-two'); + p = page.locator('#two'); + const h = page.locator('html'); + await expect(h, 'imported CSS updated').toHaveCSS('background-color', 'rgba(0, 0, 0, 0)'); + }) + test('click hash links does not do navigation', async ({ page, astro }) => { // Go to page 1 await page.goto(astro.resolveUrl('/one'));