diff options
author | 2021-06-24 17:05:55 -0400 | |
---|---|---|
committer | 2021-06-24 17:05:55 -0400 | |
commit | feb9a3141e43b4bbe643a6676f8f0e6eeff410e2 (patch) | |
tree | 679ecd71f9d43c1a19d54ee0f18704f6459a3b2a | |
parent | 1eda589be175123b7a5be383e21590518ed09ca4 (diff) | |
download | astro-feb9a3141e43b4bbe643a6676f8f0e6eeff410e2.tar.gz astro-feb9a3141e43b4bbe643a6676f8f0e6eeff410e2.tar.zst astro-feb9a3141e43b4bbe643a6676f8f0e6eeff410e2.zip |
Always add the HMR script in dev (#536)
* Always add the HMR script in dev
for livereload
* Adds the changeset
-rw-r--r-- | .changeset/old-buses-tell.md | 5 | ||||
-rw-r--r-- | packages/astro/src/compiler/transform/head.ts | 2 | ||||
-rw-r--r-- | packages/astro/test/astro-basic.test.js | 6 | ||||
-rw-r--r-- | packages/astro/test/astro-hmr.test.js | 12 | ||||
-rw-r--r-- | packages/astro/test/fixtures/astro-hmr/src/pages/static.astro | 12 |
5 files changed, 29 insertions, 8 deletions
diff --git a/.changeset/old-buses-tell.md b/.changeset/old-buses-tell.md new file mode 100644 index 000000000..41473d671 --- /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 fdf07cdfc..b081491a3 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 4f8fc3a32..cf964e3b1 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 5d4fb5f0e..2d295c0b7 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 000000000..3c6cd0147 --- /dev/null +++ b/packages/astro/test/fixtures/astro-hmr/src/pages/static.astro @@ -0,0 +1,12 @@ +--- +import Tour from '../components/Tour.jsx'; +--- +<html> +<head> + <title>My Test</title> +</head> +<body> + <div>Hello world</div> + <Tour /> +</body> +</html>
\ No newline at end of file |