Skip to content

Commit 6ebd625

Browse files
committed
fix: support useConfig and composables in markdown templates
1 parent d78298e commit 6ebd625

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/composables/renderContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ export interface RenderContext {
2727
tailwindBlocks?: TailwindBlock[]
2828
}
2929

30-
export const RenderContextKey: InjectionKey<RenderContext> = Symbol('RenderContext')
30+
// Global symbol registry — same rationale as MaizzleConfigKey in useConfig.ts.
31+
export const RenderContextKey: InjectionKey<RenderContext> = Symbol.for('maizzle.renderContext')

src/composables/useConfig.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { inject } from 'vue'
22
import type { InjectionKey } from 'vue'
33
import type { MaizzleConfig } from '../types/index.ts'
44

5-
export const MaizzleConfigKey: InjectionKey<MaizzleConfig> = Symbol('MaizzleConfig')
5+
/**
6+
* Use the global symbol registry so the key is identical across every
7+
* module instance. In dev, `render()` (Node) and the SFC's auto-imported
8+
* composables can resolve to two separate instances of this module; a plain
9+
* `Symbol()` would differ between them, so `app.provide()` and the SFC's
10+
* `inject()` would miss each other and `useConfig()` would throw.
11+
*/
12+
export const MaizzleConfigKey: InjectionKey<MaizzleConfig> = Symbol.for('maizzle.config')
613

714
export function useConfig(): MaizzleConfig {
815
const config = inject(MaizzleConfigKey)

src/render/createRenderer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ export async function createRenderer(
307307
resolve(__dirname, '../filters'),
308308
],
309309
imports: ['vue', unheadVueComposablesImports],
310+
/**
311+
* unplugin-auto-import's default `include` doesn't match `.md`, so
312+
* auto-imports (Vue, unhead and Maizzle composables/filters) were
313+
* never injected into Markdown templates — `useConfig()` and friends
314+
* threw at runtime. Extend the default list with `.md` (and its
315+
* `?vue` script sub-requests) to mirror the `.md` coverage the
316+
* Components plugin already declares below.
317+
*/
318+
include: [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/, /\.md\?vue/],
310319
dts: dts ? resolve(dtsDir, 'auto-imports.d.ts') : false,
311320
}),
312321
Components({

0 commit comments

Comments
 (0)