diff --git a/.changeset/twelve-cars-tell.md b/.changeset/twelve-cars-tell.md new file mode 100644 index 000000000000..a1812d637aff --- /dev/null +++ b/.changeset/twelve-cars-tell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix markdown page HMR diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index cc86d1fc1bcc..deaccebef559 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -107,7 +107,7 @@ export default function markdown({ settings, logger }: AstroPluginOptions): Plug } const code = escapeViteEnvReferences(` - import { unescapeHTML, spreadAttributes, createComponent, render, renderComponent } from ${JSON.stringify( + import { unescapeHTML, spreadAttributes, createComponent, render, renderComponent, maybeRenderHead } from ${JSON.stringify( astroServerRuntimeModulePath )}; import { AstroError, AstroErrorData } from ${JSON.stringify(astroErrorModulePath)}; @@ -180,10 +180,9 @@ export default function markdown({ settings, logger }: AstroPluginOptions): Plug }, { 'default': () => render\`\${unescapeHTML(html)}\` })}\`;` - : `render\`\${unescapeHTML(html)}\`;` + : `render\`\${maybeRenderHead(result)}\${unescapeHTML(html)}\`;` } }); - Content[Symbol.for('astro.needsHeadRendering')] = ${layout ? 'false' : 'true'}; export default Content; `); diff --git a/packages/astro/test/astro-pages.test.js b/packages/astro/test/astro-pages.test.js index 70f391be7c9d..3d17b521d2ea 100644 --- a/packages/astro/test/astro-pages.test.js +++ b/packages/astro/test/astro-pages.test.js @@ -49,5 +49,10 @@ describe('Pages', () => { expect($('#testing').length).to.be.greaterThan(0); }); + + it('should have Vite client in dev', async () => { + const html = await fixture.fetch('/').then((res) => res.text()); + expect(html).to.include('/@vite/client', 'Markdown page does not have Vite client for HMR'); + }); }); });