diff --git a/packages/astro/package.json b/packages/astro/package.json index f3696d787..078b2a13a 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -87,7 +87,7 @@ "sass": "^1.32.13", "shorthash": "^0.0.2", "slash": "^4.0.0", - "snowpack": "^3.5.6", + "snowpack": "^3.5.7", "source-map-support": "^0.5.19", "string-width": "^5.0.0", "tiny-glob": "^0.2.8", diff --git a/packages/astro/src/compiler/transform/head.ts b/packages/astro/src/compiler/transform/head.ts index b11581814..5ddc40d7d 100644 --- a/packages/astro/src/compiler/transform/head.ts +++ b/packages/astro/src/compiler/transform/head.ts @@ -11,7 +11,7 @@ export default function (opts: TransformOptions): Transformer { visitors: { html: { InlineComponent: { - enter(node, parent) { + enter(node) { const [name, kind] = node.name.split(':'); if (kind && !hasComponents) { hasComponents = true; @@ -20,7 +20,6 @@ export default function (opts: TransformOptions): Transformer { }, Element: { enter(node) { - if (!hasComponents) return; switch (node.name) { case 'head': { head = node; @@ -56,7 +55,7 @@ export default function (opts: TransformOptions): Transformer { }); } - if (isHmrEnabled) { + if (isHmrEnabled && hasComponents) { 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 ce9f1cded..d258fdd3a 100644 --- a/packages/astro/test/astro-basic.test.js +++ b/packages/astro/test/astro-basic.test.js @@ -5,7 +5,11 @@ import { setup } from './helpers.js'; const Basics = suite('Basic test'); -setup(Basics, './fixtures/astro-basic'); +setup(Basics, './fixtures/astro-basic', { + runtimeOptions: { + mode: 'development' + } +}); Basics('Can load page', async ({ runtime }) => { const result = await runtime.load('/'); @@ -16,4 +20,16 @@ Basics('Can load page', async ({ runtime }) => { assert.equal($('h1').text(), 'Hello world!'); }); +Basics('Sets the HMR port when dynamic components used', async ({ runtime }) => { + const result = await runtime.load('/client'); + const html = result.contents; + assert.ok(/HMR_WEBSOCKET_URL/.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_URL/.test(html), 'Does not set the websocket port'); +}); + Basics.run(); diff --git a/packages/astro/test/fixtures/astro-basic/src/components/Tour.jsx b/packages/astro/test/fixtures/astro-basic/src/components/Tour.jsx new file mode 100644 index 000000000..f05f3f9d8 --- /dev/null +++ b/packages/astro/test/fixtures/astro-basic/src/components/Tour.jsx @@ -0,0 +1,5 @@ +import { h } from 'preact'; + +export default function() { + return