Fix markdown page HMR (#8418)

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Bjorn Lu 2023-09-06 03:35:56 +08:00 committed by GitHub
parent 837ad16491
commit 923a443cb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix markdown page HMR

View file

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

View file

@ -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');
});
});
});