diff --git a/.changeset/old-buses-tell.md b/.changeset/old-buses-tell.md new file mode 100644 index 0000000000..41473d6717 --- /dev/null +++ b/.changeset/old-buses-tell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes livereload on static pages diff --git a/packages/astro/src/compiler/transform/head.ts b/packages/astro/src/compiler/transform/head.ts index fdf07cdfc8..b081491a3c 100644 --- a/packages/astro/src/compiler/transform/head.ts +++ b/packages/astro/src/compiler/transform/head.ts @@ -123,7 +123,7 @@ export default function (opts: TransformOptions): Transformer { }); } - if (isHmrEnabled && hasComponents) { + if (isHmrEnabled) { const { hmrPort } = opts.compileOptions; children.push( { diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js index 4f8fc3a32b..cf964e3b14 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -27,12 +27,6 @@ Basics('Sets the HMR port when dynamic components used', async ({ runtime }) => assert.ok(/HMR_WEBSOCKET_PORT/.test(html), 'Sets the websocket port'); }); -Basics('Does not set the HMR port when no dynamic component used', async ({ runtime }) => { - const result = await runtime.load('/'); - const html = result.contents; - assert.ok(!/HMR_WEBSOCKET_PORT/.test(html), 'Does not set the websocket port'); -}); - Basics('Correctly serializes boolean attributes', async ({ runtime }) => { const result = await runtime.load('/'); const html = result.contents; diff --git a/packages/astro/test/astro-hmr.test.js b/packages/astro/test/astro-hmr.test.js index 5d4fb5f0ea..2d295c0b7e 100644 --- a/packages/astro/test/astro-hmr.test.js +++ b/packages/astro/test/astro-hmr.test.js @@ -21,7 +21,7 @@ HMR('Honors the user provided port', async ({ runtime }) => { HMR('Does not override script added by the user', async ({ runtime }) => { const result = await runtime.load('/manual'); - console.log(result.error); + if (result.error) throw new Error(result.error); const html = result.contents; @@ -29,4 +29,14 @@ HMR('Does not override script added by the user', async ({ runtime }) => { assert.ok(/window\.HMR_WEBSOCKET_PORT = 5555/.test(html), 'Ignored when window.HMR_WEBSOCKET_URL set'); }); +HMR('Adds script to static pages too', async ({ runtime }) => { + const result = await runtime.load('/static'); + if (result.error) throw new Error(result.error); + + const html = result.contents; + const $ = doc(html); + assert.equal($('[src="/_snowpack/hmr-client.js"]').length, 1); + assert.ok(/window\.HMR_WEBSOCKET_PORT/.test(html), 'websocket port added'); +}); + HMR.run(); diff --git a/packages/astro/test/fixtures/astro-hmr/src/pages/static.astro b/packages/astro/test/fixtures/astro-hmr/src/pages/static.astro new file mode 100644 index 0000000000..3c6cd01476 --- /dev/null +++ b/packages/astro/test/fixtures/astro-hmr/src/pages/static.astro @@ -0,0 +1,12 @@ +--- +import Tour from '../components/Tour.jsx'; +--- + +
+