diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 7b556c252..daa79ee6e 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -64,7 +64,9 @@ const { fallback = 'animate' } = Astro.props as Props; }; async function getHTML(href: string) { - const res = await fetch(href); + const res = await fetch(href, { + redirect: 'manual' + }); const html = await res.text(); return { ok: res.ok, html }; } diff --git a/packages/astro/e2e/fixtures/view-transitions/astro.config.mjs b/packages/astro/e2e/fixtures/view-transitions/astro.config.mjs index 02dc2043d..68fdc8e2e 100644 --- a/packages/astro/e2e/fixtures/view-transitions/astro.config.mjs +++ b/packages/astro/e2e/fixtures/view-transitions/astro.config.mjs @@ -7,6 +7,10 @@ export default defineConfig({ output: 'server', adapter: nodejs({ mode: 'standalone' }), integrations: [react()], + redirects: { + '/redirect-two': '/two', + '/redirect-external': 'http://example.com/', + }, vite: { build: { assetsInlineLimit: 0, diff --git a/packages/astro/e2e/fixtures/view-transitions/src/pages/one.astro b/packages/astro/e2e/fixtures/view-transitions/src/pages/one.astro index 3f9666c1d..cc57e76d8 100644 --- a/packages/astro/e2e/fixtures/view-transitions/src/pages/one.astro +++ b/packages/astro/e2e/fixtures/view-transitions/src/pages/one.astro @@ -8,6 +8,8 @@ import Layout from '../components/Layout.astro'; go to 3 go to long page go to top + go to redirect 2 + go to a redirect external
test content
diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index 34f1a4e02..6d23b9684 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -543,4 +543,42 @@ test.describe('View Transitions', () => { p = page.locator('#one'); await expect(p, 'should have content').toHaveText('Page 1'); }); + + test.skip('Moving to a page which redirects to another', async ({ page, astro }) => { + const loads = []; + page.addListener('load', (p) => { + loads.push(p.title()); + }); + + // 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-redirect-two'); + p = page.locator('#two'); + await expect(p, 'should have content').toHaveText('Page 2'); + + expect(loads.length, 'There should be 2 page loads').toEqual(2); + }); + + test.only('Redirect to external site causes page load', async ({ page, astro }) => { + const loads = []; + page.addListener('load', (p) => { + loads.push(p.title()); + }); + + // 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 external page + await page.click('#click-redirect-external'); + p = page.locator('h1'); + await expect(p, 'should have content').toBeVisible(); + + expect(loads.length, 'There should be 2 page load').toEqual(2); + }); });