diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index ba5b54813..f6da58546 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -339,18 +339,18 @@ async function handleRequest( * Vite HMR sends requests for new CSS and those get returned as JS, but we want it to be CSS * since they are inside of a link tag for Astro. */ -const forceTextCSSForStylesMiddleware: vite.Connect.NextHandleFunction = function(req, res, next) { - if(req.url) { +const forceTextCSSForStylesMiddleware: vite.Connect.NextHandleFunction = function (req, res, next) { + if (req.url) { // We are just using this to parse the URL to get the search params object // so the second arg here doesn't matter const url = new URL(req.url, 'https://astro.build'); // lang.css is a search param that exists on Astro, Svelte, and Vue components. // We only want to override for astro files. - if(url.searchParams.has('astro') && url.searchParams.has('lang.css')) { + if (url.searchParams.has('astro') && url.searchParams.has('lang.css')) { // Override setHeader so we can set the correct content-type for this request. const setHeader = res.setHeader; - res.setHeader = function(key, value) { - if(key.toLowerCase() === 'content-type') { + res.setHeader = function (key, value) { + if (key.toLowerCase() === 'content-type') { return setHeader.call(this, key, 'text/css'); } return setHeader.apply(this, [key, value]); @@ -381,7 +381,10 @@ export default function createPlugin({ config, logging }: AstroPluginOptions): v removeViteHttpMiddleware(viteServer.middlewares); // Push this middleware to the front of the stack so that it can intercept responses. - viteServer.middlewares.stack.unshift({ route: '', handle: forceTextCSSForStylesMiddleware }); + viteServer.middlewares.stack.unshift({ + route: '', + handle: forceTextCSSForStylesMiddleware, + }); viteServer.middlewares.use(async (req, res) => { if (!req.url || !req.method) { throw new Error('Incomplete request'); diff --git a/packages/astro/test/hmr-css.test.js b/packages/astro/test/hmr-css.test.js index 2705d8fd1..f8f741904 100644 --- a/packages/astro/test/hmr-css.test.js +++ b/packages/astro/test/hmr-css.test.js @@ -22,7 +22,9 @@ describe('HMR - CSS', () => { }); it('Timestamp URL used by Vite gets the right mime type', async () => { - let res = await fixture.fetch('/src/pages/index.astro?astro=&type=style&index=0&lang.css=&t=1653657441095'); + let res = await fixture.fetch( + '/src/pages/index.astro?astro=&type=style&index=0&lang.css=&t=1653657441095' + ); let headers = res.headers; expect(headers.get('content-type')).to.equal('text/css'); }); diff --git a/packages/integrations/lit/client-shim.js b/packages/integrations/lit/client-shim.js index c3ac563ca..ca97b92cc 100644 --- a/packages/integrations/lit/client-shim.js +++ b/packages/integrations/lit/client-shim.js @@ -2,7 +2,9 @@ async function polyfill() { const { hydrateShadowRoots } = await import( '@webcomponents/template-shadowroot/template-shadowroot.js' ); - window.addEventListener('DOMContentLoaded', () => hydrateShadowRoots(document.body), { once: true }); + window.addEventListener('DOMContentLoaded', () => hydrateShadowRoots(document.body), { + once: true, + }); } const polyfillCheckEl = new DOMParser() diff --git a/packages/integrations/lit/client-shim.min.js b/packages/integrations/lit/client-shim.min.js index 0882a78b3..afae053ac 100644 --- a/packages/integrations/lit/client-shim.min.js +++ b/packages/integrations/lit/client-shim.min.js @@ -77,7 +77,7 @@ var S = i(() => { }); async function g() { let { hydrateShadowRoots: t } = await Promise.resolve().then(() => (S(), v)); - window.addEventListener('DOMContentLoaded', () => t(document.body),{once:true}); + window.addEventListener('DOMContentLoaded', () => t(document.body), { once: true }); } var x = new DOMParser() .parseFromString('

', 'text/html', {