Skip to content

Commit

Permalink
fix: generate client directive scripts from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Jun 4, 2022
1 parent 98e2b53 commit 56530a8
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/astro/src/core/render/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 56530a8

Please sign in to comment.