From e942855329bfcd3e2f52bd609af9acbe9be5929d Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 24 Aug 2023 10:23:01 -0400 Subject: [PATCH] Revert "View Transition: swap attributes of document's root element (#8206)" This reverts commit 52606a3909f9de5ced9b9ba3ba25832f73a8689e. --- .../astro/components/ViewTransitions.astro | 12 ---------- .../src/components/AttributedLayout.astro | 17 -------------- .../src/pages/other-attributes.astro | 11 ---------- .../src/pages/some-attributes.astro | 7 ------ packages/astro/e2e/view-transitions.test.js | 22 ------------------- 5 files changed, 69 deletions(-) delete mode 100644 packages/astro/e2e/fixtures/view-transitions/src/components/AttributedLayout.astro delete mode 100644 packages/astro/e2e/fixtures/view-transitions/src/pages/other-attributes.astro delete mode 100644 packages/astro/e2e/fixtures/view-transitions/src/pages/some-attributes.astro diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index cb6cbbd33..612b89659 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -136,18 +136,6 @@ const { fallback = 'animate' } = Astro.props as Props; // Remove them before swapping. doc.querySelectorAll('head noscript').forEach((el) => el.remove()); - // swap attributes of the html element - // - delete all attributes from the current document - // - insert all attributes from doc - // - reinsert all original attributes that are named 'data-astro-*' - const html = document.documentElement; - const astro = [...html.attributes].filter( - ({ name }) => (html.removeAttribute(name), name.startsWith('data-astro-')) - ); - [...doc.documentElement.attributes, ...astro].forEach(({ name, value }) => - html.setAttribute(name, value) - ); - // Swap head for (const el of Array.from(document.head.children)) { const newEl = persistedHeadElement(el); diff --git a/packages/astro/e2e/fixtures/view-transitions/src/components/AttributedLayout.astro b/packages/astro/e2e/fixtures/view-transitions/src/components/AttributedLayout.astro deleted file mode 100644 index 7a3284dd4..000000000 --- a/packages/astro/e2e/fixtures/view-transitions/src/components/AttributedLayout.astro +++ /dev/null @@ -1,17 +0,0 @@ ---- -import { ViewTransitions } from 'astro:transitions'; -import { HTMLAttributes } from 'astro/types'; - -interface Props extends HTMLAttributes<'html'> {} ---- - - - Testing - - - -
- -
- - diff --git a/packages/astro/e2e/fixtures/view-transitions/src/pages/other-attributes.astro b/packages/astro/e2e/fixtures/view-transitions/src/pages/other-attributes.astro deleted file mode 100644 index ade923277..000000000 --- a/packages/astro/e2e/fixtures/view-transitions/src/pages/other-attributes.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- -import AttributeLayout from '../components/AttributedLayout.astro'; ---- - -

Page with other attributes

-
diff --git a/packages/astro/e2e/fixtures/view-transitions/src/pages/some-attributes.astro b/packages/astro/e2e/fixtures/view-transitions/src/pages/some-attributes.astro deleted file mode 100644 index 165ef81c1..000000000 --- a/packages/astro/e2e/fixtures/view-transitions/src/pages/some-attributes.astro +++ /dev/null @@ -1,7 +0,0 @@ ---- -import AttributedLayout from '../components/AttributedLayout.astro'; ---- - -

Page with some attributes

- Other attributes -
diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index 57e23e6a9..c681bfea0 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -397,25 +397,3 @@ test.describe('View Transitions', () => { ).toEqual(1); }); }); - -test('Navigation also swaps the attributes of the document root', async ({ page, astro }) => { - page.on('console', (msg) => console.log(msg.text())); - await page.goto(astro.resolveUrl('/some-attributes')); - let p = page.locator('#heading'); - await expect(p, 'should have content').toHaveText('Page with some attributes'); - - let h = page.locator('html'); - await expect(h, 'should have content').toHaveAttribute('lang', 'en'); - - await page.click('#click-other-attributes'); - p = page.locator('#heading'); - await expect(p, 'should have content').toHaveText('Page with other attributes'); - - h = page.locator('html'); - await expect(h, 'should have content').toHaveAttribute('lang', 'es'); - await expect(h, 'should have content').toHaveAttribute('style', 'background-color: green'); - await expect(h, 'should have content').toHaveAttribute('data-other-name', 'value'); - await expect(h, 'should have content').toHaveAttribute('data-astro-fake', 'value'); - await expect(h, 'should have content').toHaveAttribute('data-astro-transition', 'forward'); - await expect(h, 'should be absent').not.toHaveAttribute('class', /.*/); -});