0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Always add the HMR script in dev (#536)

* Always add the HMR script in dev

for livereload

* Adds the changeset
This commit is contained in:
Matthew Phillips 2021-06-24 17:05:55 -04:00 committed by GitHub
parent 1eda589be1
commit feb9a3141e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 8 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes livereload on static pages

View file

@ -123,7 +123,7 @@ export default function (opts: TransformOptions): Transformer {
});
}
if (isHmrEnabled && hasComponents) {
if (isHmrEnabled) {
const { hmrPort } = opts.compileOptions;
children.push(
{

View file

@ -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;

View file

@ -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();

View file

@ -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>