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
Testing
+} \ No newline at end of file diff --git a/packages/astro/test/fixtures/astro-basic/src/pages/client.astro b/packages/astro/test/fixtures/astro-basic/src/pages/client.astro new file mode 100644 index 000000000..43d8b373b --- /dev/null +++ b/packages/astro/test/fixtures/astro-basic/src/pages/client.astro @@ -0,0 +1,12 @@ +--- +import Tour from '../components/Tour.jsx'; +--- + + + +Stuff + + + + + \ No newline at end of file diff --git a/packages/astro/test/helpers.js b/packages/astro/test/helpers.js index 68af678df..ebcfb0274 100644 --- a/packages/astro/test/helpers.js +++ b/packages/astro/test/helpers.js @@ -11,7 +11,7 @@ const MAX_TEST_TIME = 10000; // max time an individual test may take const MAX_SHUTDOWN_TIME = 3000; // max time shutdown() may take /** setup fixtures for tests */ -export function setup(Suite, fixturePath) { +export function setup(Suite, fixturePath, { runtimeOptions = {} } = {}) { let runtime; const timers = {}; @@ -24,6 +24,7 @@ export function setup(Suite, fixturePath) { runtime = await createRuntime(astroConfig, { logging: { level: 'error', dest: process.stderr }, + ...runtimeOptions }); context.runtime = runtime; diff --git a/yarn.lock b/yarn.lock index d126a1cbf..98f5aa5a4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8938,10 +8938,10 @@ smartwrap@^1.2.3: wcwidth "^1.0.1" yargs "^15.1.0" -snowpack@^3.5.6: - version "3.5.6" - resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.5.6.tgz#79f8699e4248e19f67ec50433e50072bb2e69e89" - integrity sha512-R9uqattPhS2j1zaOFgwl7i54rFTtxxk4kmKmqJBRwD+9YggUulGm7O7YRXaMMjtmi69czK7jxbtZs1Up/xA+1A== +snowpack@^3.5.7: + version "3.5.7" + resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.5.7.tgz#1d56a273c97e6f8fe23800f4d3c641eefb65f356" + integrity sha512-mMdbG9vSs7JL69/Zk2VtpduBnbfzCCCXvhJeX4GzPg4aYyKtfs0s6MA5VoQbN9HL6lZpKRy/knaigKcC4E29GA== dependencies: cli-spinners "^2.5.0" default-browser-id "^2.0.0"