Skip to content

Commit

Permalink
Fix to get Integration Data even when a page is transitioned by ViewT…
Browse files Browse the repository at this point in the history
…ransition (#10079)

* Fix to get Integration Data even when a page is transitioned by ViewTransition.

* add test case

* add changeset

* fix test

* Fix typo
  • Loading branch information
ktym4a authored Feb 20, 2024
1 parent b92d35f commit 80f8996
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-laws-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fix integrationData fetch to always be called even if View Transition is enabled.
22 changes: 22 additions & 0 deletions packages/astro/e2e/dev-toolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ test.describe('Dev Toolbar', () => {
await expect(astroWindow).not.toBeVisible();
});

test('show integration app', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/view-transition-a'));

let toolbar = page.locator('astro-dev-toolbar');
let appButton = toolbar.locator('button[data-app-id="astro"]');
await appButton.click();

let astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro"]');
let astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card');
await page.waitForSelector('astro-dev-toolbar-card');
await expect(astroToolbarCards.first()).toBeVisible();

let consolePromise = page.waitForEvent('console');
await page.click('#go-to-b');
await consolePromise;

astroAppCanvas = toolbar.locator('astro-dev-toolbar-app-canvas[data-app-id="astro"]');
astroToolbarCards = await astroAppCanvas.locator('astro-dev-toolbar-card');
await page.waitForSelector('astro-dev-toolbar-card');
await expect(astroToolbarCards.first()).toBeVisible();
});

test('xray shows highlights and tooltips', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));

Expand Down
18 changes: 18 additions & 0 deletions packages/astro/e2e/fixtures/dev-toolbar/src/layout/Layout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import { ViewTransitions } from 'astro:transitions';
---
<html lang="en">
<head>
<title>View Transition Test</title>
<ViewTransitions />
<script is:inline>
// let playwright know when navigate() is done
document.addEventListener('astro:before-swap', (e) => {
e.viewTransition.ready.then(()=>console.log("ready"))
});
</script>
</head>
<body>
<slot />
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
import Layout from '../layout/Layout.astro'
---
<Layout>
<div>Test</div>
<a href="/view-transition-b" id="go-to-b">Go to B</a>
</Layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
import Layout from '../layout/Layout.astro'
---
<Layout>
<div>Test</div>
<a href="/view-transition-a" id="go-to-a">Go to A</a>
</Layout>
28 changes: 16 additions & 12 deletions packages/astro/src/runtime/client/dev-toolbar/apps/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,31 @@ export default {
createCanvas();

document.addEventListener('astro:after-swap', createCanvas);
document.addEventListener('astro:after-swap', fetchIntegrationData);

eventTarget.addEventListener('app-toggled', async (event) => {
resetDebugButton();
if (!(event instanceof CustomEvent)) return;

if (event.detail.state === true) {
if (!integrationData)
fetch('https://astro.build/api/v1/dev-overlay/', {
cache: 'no-cache',
})
.then((res) => res.json())
.then((data) => {
integrationData = data;
integrationData.data = integrationData.data.map((integration) => {
return integration;
});
refreshIntegrationList();
});
if (!integrationData) fetchIntegrationData();
}
});

function fetchIntegrationData() {
fetch('https://astro.build/api/v1/dev-overlay/', {
cache: 'no-cache',
})
.then((res) => res.json())
.then((data) => {
integrationData = data;
integrationData.data = integrationData.data.map((integration) => {
return integration;
});
refreshIntegrationList();
});
}

function createCanvas() {
const links: { icon: Icon; name: string; link: string }[] = [
{
Expand Down

0 comments on commit 80f8996

Please sign in to comment.