Skip to content

Commit

Permalink
Revert "View Transition: swap attributes of document's root element (#…
Browse files Browse the repository at this point in the history
…8206)"

This reverts commit 52606a3.
  • Loading branch information
matthewp committed Aug 24, 2023
1 parent fd5fa86 commit e942855
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 69 deletions.
12 changes: 0 additions & 12 deletions packages/astro/components/ViewTransitions.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions packages/astro/e2e/view-transitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', /.*/);
});

0 comments on commit e942855

Please sign in to comment.