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:
parent
1eda589be1
commit
feb9a3141e
5 changed files with 29 additions and 8 deletions
5
.changeset/old-buses-tell.md
Normal file
5
.changeset/old-buses-tell.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes livereload on static pages
|
|
@ -123,7 +123,7 @@ export default function (opts: TransformOptions): Transformer {
|
|||
});
|
||||
}
|
||||
|
||||
if (isHmrEnabled && hasComponents) {
|
||||
if (isHmrEnabled) {
|
||||
const { hmrPort } = opts.compileOptions;
|
||||
children.push(
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
12
packages/astro/test/fixtures/astro-hmr/src/pages/static.astro
vendored
Normal file
12
packages/astro/test/fixtures/astro-hmr/src/pages/static.astro
vendored
Normal 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>
|
Loading…
Reference in a new issue