From 345808170fce783ddd3c9a4035a91fa64dcc5f46 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 29 Sep 2023 21:55:46 +0800 Subject: [PATCH] Fix duplicated Astro and Vite injected styles (#8706) --- .changeset/olive-bags-think.md | 5 +++ packages/astro/e2e/css-sourcemaps.test.js | 36 --------------- packages/astro/e2e/css.test.js | 18 ++------ .../fixtures/css-sourcemaps/astro.config.mjs | 7 --- .../e2e/fixtures/css-sourcemaps/package.json | 8 ---- .../e2e/fixtures/css-sourcemaps/src/env.d.ts | 1 - .../css-sourcemaps/src/pages/index.astro | 9 ---- .../css-sourcemaps/src/styles/main.css | 3 -- packages/astro/e2e/view-transitions.test.js | 2 +- packages/astro/src/runtime/client/hmr.ts | 45 ++----------------- packages/astro/src/transitions/router.ts | 2 +- .../astro/src/vite-plugin-astro-server/css.ts | 2 +- .../src/vite-plugin-astro-server/route.ts | 15 ++----- 13 files changed, 18 insertions(+), 135 deletions(-) create mode 100644 .changeset/olive-bags-think.md delete mode 100644 packages/astro/e2e/css-sourcemaps.test.js delete mode 100644 packages/astro/e2e/fixtures/css-sourcemaps/astro.config.mjs delete mode 100644 packages/astro/e2e/fixtures/css-sourcemaps/package.json delete mode 100644 packages/astro/e2e/fixtures/css-sourcemaps/src/env.d.ts delete mode 100644 packages/astro/e2e/fixtures/css-sourcemaps/src/pages/index.astro delete mode 100644 packages/astro/e2e/fixtures/css-sourcemaps/src/styles/main.css diff --git a/.changeset/olive-bags-think.md b/.changeset/olive-bags-think.md new file mode 100644 index 000000000000..70fc7501e9dc --- /dev/null +++ b/.changeset/olive-bags-think.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix duplicated Astro and Vite injected styles diff --git a/packages/astro/e2e/css-sourcemaps.test.js b/packages/astro/e2e/css-sourcemaps.test.js deleted file mode 100644 index 4ea3fc0e248d..000000000000 --- a/packages/astro/e2e/css-sourcemaps.test.js +++ /dev/null @@ -1,36 +0,0 @@ -import { expect } from '@playwright/test'; -import { testFactory } from './test-utils.js'; - -const test = testFactory({ - root: './fixtures/css/', -}); - -let devServer; - -test.beforeAll(async ({ astro }) => { - devServer = await astro.startDevServer(); -}); - -test.afterAll(async () => { - await devServer.stop(); -}); - -test.describe('CSS Sourcemap HMR', () => { - test('removes Astro-injected CSS once Vite-injected CSS loads', async ({ page, astro }) => { - const html = await astro.fetch('/').then((res) => res.text()); - - // style[data-astro-dev-id] should exist in initial SSR'd markup - expect(html).toMatch('data-astro-dev-id'); - - await page.goto(astro.resolveUrl('/')); - - // Ensure JS has initialized - await page.waitForTimeout(500); - - // style[data-astro-dev-id] should NOT exist once JS runs - expect(await page.locator('style[data-astro-dev-id]').count()).toEqual(0); - - // style[data-vite-dev-id] should exist now - expect(await page.locator('style[data-vite-dev-id]').count()).toBeGreaterThan(0); - }); -}); diff --git a/packages/astro/e2e/css.test.js b/packages/astro/e2e/css.test.js index b302d9d90add..3e0486d0f369 100644 --- a/packages/astro/e2e/css.test.js +++ b/packages/astro/e2e/css.test.js @@ -29,21 +29,9 @@ test.describe('CSS HMR', () => { await expect(h).toHaveCSS('color', 'rgb(0, 128, 0)'); }); - test('removes Astro-injected CSS once Vite-injected CSS loads', async ({ page, astro }) => { + test('removes Astro-injected CSS once Vite-injected CSS loads', async ({ astro }) => { const html = await astro.fetch('/').then((res) => res.text()); - - // style[data-astro-dev-id] should exist in initial SSR'd markup - expect(html).toMatch('data-astro-dev-id'); - - await page.goto(astro.resolveUrl('/')); - - // Ensure JS has initialized - await page.waitForTimeout(500); - - // style[data-astro-dev-id] should NOT exist once JS runs - expect(await page.locator('style[data-astro-dev-id]').count()).toEqual(0); - - // style[data-vite-dev-id] should exist now - expect(await page.locator('style[data-vite-dev-id]').count()).toBeGreaterThan(0); + // style[data-vite-dev-id] should exist in initial SSR'd markup + expect(html).toMatch('data-vite-dev-id'); }); }); diff --git a/packages/astro/e2e/fixtures/css-sourcemaps/astro.config.mjs b/packages/astro/e2e/fixtures/css-sourcemaps/astro.config.mjs deleted file mode 100644 index 7e8fac1e7f7c..000000000000 --- a/packages/astro/e2e/fixtures/css-sourcemaps/astro.config.mjs +++ /dev/null @@ -1,7 +0,0 @@ -export default { - vite: { - css: { - devSourcemap: true, - } - } -}; diff --git a/packages/astro/e2e/fixtures/css-sourcemaps/package.json b/packages/astro/e2e/fixtures/css-sourcemaps/package.json deleted file mode 100644 index 1fa4c2c79fac..000000000000 --- a/packages/astro/e2e/fixtures/css-sourcemaps/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@e2e/css-sourcemaps", - "version": "0.0.0", - "private": true, - "dependencies": { - "astro": "workspace:*" - } -} diff --git a/packages/astro/e2e/fixtures/css-sourcemaps/src/env.d.ts b/packages/astro/e2e/fixtures/css-sourcemaps/src/env.d.ts deleted file mode 100644 index 8c34fb45e7cf..000000000000 --- a/packages/astro/e2e/fixtures/css-sourcemaps/src/env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// \ No newline at end of file diff --git a/packages/astro/e2e/fixtures/css-sourcemaps/src/pages/index.astro b/packages/astro/e2e/fixtures/css-sourcemaps/src/pages/index.astro deleted file mode 100644 index 7275177f961d..000000000000 --- a/packages/astro/e2e/fixtures/css-sourcemaps/src/pages/index.astro +++ /dev/null @@ -1,9 +0,0 @@ -

hello world

- - diff --git a/packages/astro/e2e/fixtures/css-sourcemaps/src/styles/main.css b/packages/astro/e2e/fixtures/css-sourcemaps/src/styles/main.css deleted file mode 100644 index c80a6cde1b69..000000000000 --- a/packages/astro/e2e/fixtures/css-sourcemaps/src/styles/main.css +++ /dev/null @@ -1,3 +0,0 @@ -:root { - --h1-color: red; -} diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index 05a8f8ad03ac..a04b905af7c7 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -631,7 +631,7 @@ test.describe('View Transitions', () => { }); test('client:only styles are retained on transition', async ({ page, astro }) => { - const totalExpectedStyles = 8; + const totalExpectedStyles = 7; // Go to page 1 await page.goto(astro.resolveUrl('/client-only-one')); diff --git a/packages/astro/src/runtime/client/hmr.ts b/packages/astro/src/runtime/client/hmr.ts index 989ddc6b99da..5b6eddc23665 100644 --- a/packages/astro/src/runtime/client/hmr.ts +++ b/packages/astro/src/runtime/client/hmr.ts @@ -1,46 +1,7 @@ /// if (import.meta.hot) { - // Vite injects `