diff options
8 files changed, 84 insertions, 5 deletions
diff --git a/.changeset/silent-snakes-shave.md b/.changeset/silent-snakes-shave.md deleted file mode 100644 index 3f8c8c3ee..000000000 --- a/.changeset/silent-snakes-shave.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@astrojs/cloudflare': patch ---- - -Improve documentation and export the types needed to type the `runtime` object. diff --git a/packages/astro/CHANGELOG.md b/packages/astro/CHANGELOG.md index d2161969f..b1860b265 100644 --- a/packages/astro/CHANGELOG.md +++ b/packages/astro/CHANGELOG.md @@ -553,6 +553,12 @@ - @astrojs/internal-helpers@0.2.0-beta.0 - @astrojs/markdown-remark@3.0.0-beta.0 +## 2.10.14 + +### Patch Changes + +- [#8206](https://github.com/withastro/astro/pull/8206) [`52606a390`](https://github.com/withastro/astro/commit/52606a3909f9de5ced9b9ba3ba25832f73a8689e) Thanks [@martrapp](https://github.com/martrapp)! - fix: View Transition: swap attributes of document's root element + ## 2.10.13 ### Patch Changes diff --git a/packages/astro/components/ViewTransitions.astro b/packages/astro/components/ViewTransitions.astro index 612b89659..cb6cbbd33 100644 --- a/packages/astro/components/ViewTransitions.astro +++ b/packages/astro/components/ViewTransitions.astro @@ -136,6 +136,18 @@ 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 new file mode 100644 index 000000000..7a3284dd4 --- /dev/null +++ b/packages/astro/e2e/fixtures/view-transitions/src/components/AttributedLayout.astro @@ -0,0 +1,17 @@ +--- +import { ViewTransitions } from 'astro:transitions'; +import { HTMLAttributes } from 'astro/types'; + +interface Props extends HTMLAttributes<'html'> {} +--- +<html {...Astro.props}> + <head> + <title>Testing</title> + <ViewTransitions /> + </head> + <body> + <main transition:animate="slide"> + <slot /> + </main> + </body> +</html> 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 new file mode 100644 index 000000000..ade923277 --- /dev/null +++ b/packages/astro/e2e/fixtures/view-transitions/src/pages/other-attributes.astro @@ -0,0 +1,11 @@ +--- +import AttributeLayout from '../components/AttributedLayout.astro'; +--- +<AttributeLayout +lang="es" +style="background-color: green" +data-other-name="value" +data-astro-fake="value" +data-astro-transition="downward"> + <p id="heading">Page with other attributes</p> +</AttributeLayout> 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 new file mode 100644 index 000000000..165ef81c1 --- /dev/null +++ b/packages/astro/e2e/fixtures/view-transitions/src/pages/some-attributes.astro @@ -0,0 +1,7 @@ +--- +import AttributedLayout from '../components/AttributedLayout.astro'; +--- +<AttributedLayout lang="en" class="ugly"> + <p id="heading">Page with some attributes</p> + <a id="click-other-attributes" href="/other-attributes">Other attributes</a> +</AttributedLayout> diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index c681bfea0..57e23e6a9 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -397,3 +397,25 @@ 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', /.*/); +}); diff --git a/packages/integrations/cloudflare/CHANGELOG.md b/packages/integrations/cloudflare/CHANGELOG.md index ebbfba40c..255ff1bb6 100644 --- a/packages/integrations/cloudflare/CHANGELOG.md +++ b/packages/integrations/cloudflare/CHANGELOG.md @@ -96,6 +96,15 @@ - astro@3.0.0-beta.0 - @astrojs/underscore-redirects@0.3.0-beta.0 +## 6.8.1 + +### Patch Changes + +- [#8190](https://github.com/withastro/astro/pull/8190) [`0be8d9bfa`](https://github.com/withastro/astro/commit/0be8d9bfa9fa811c4b7e15c4ffd2d37c93f856fe) Thanks [@ematipico](https://github.com/ematipico)! - Improve documentation and export the types needed to type the `runtime` object. + +- Updated dependencies [[`52606a390`](https://github.com/withastro/astro/commit/52606a3909f9de5ced9b9ba3ba25832f73a8689e)]: + - astro@2.10.14 + ## 6.8.0 ### Minor Changes |