From 56530a86efb6ac62eecccb6403a35b495c75a9d3 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Fri, 3 Jun 2022 18:39:35 -0400 Subject: [PATCH] fix: generate client directive scripts from metadata --- packages/astro/src/core/render/dev/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/astro/src/core/render/dev/index.ts b/packages/astro/src/core/render/dev/index.ts index ddde50291..0fec19b87 100644 --- a/packages/astro/src/core/render/dev/index.ts +++ b/packages/astro/src/core/render/dev/index.ts @@ -18,6 +18,7 @@ import { getStylesForURL } from './css.js'; import { injectTags } from './html.js'; import { isBuildingToSSR } from '../../util.js'; import { collectMdMetadata } from '../util.js'; +import { hydrationSpecifier } from '../../../runtime/server/util.js'; export interface SSROptions { /** an instance of the AstroConfig */ @@ -129,6 +130,17 @@ export async function render( }, children: '', }); + // generate client directive scripts to prevent `isSelfAccepting` issues during development + await Promise.all([...mod.$$metadata.hydrationDirectives].map(async (hydrationDirective) => { + const [, resolvedImport] = await viteServer.moduleGraph.resolveUrl(hydrationSpecifier(hydrationDirective)) + scripts.add({ + props: { + type: 'module', + src: resolvedImport, + }, + children: "", + }); + })) } // TODO: We should allow adding generic HTML elements to the head, not just scripts for (const script of astroConfig._ctx.scripts) {