fix: load preparser.ts from theme roots #2456
Open
+9
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2402
Problem
The
setup/preparser.tsfile in themes was being ignored while other setup files likeshiki.tswere correctly loaded.Root Cause
In
packages/slidev/node/setups/preparser.ts, the roots array only included:But NOT theme roots. Compare with how
setupShiki()receivesresolved.rootswhich includes themes.Solution
Resolve the theme root from headmatter (using the same logic as
options.ts) and include it in the roots array passed toloadSetups().Testing
Changes
import { resolveAddons } from '../integrations/addons' +import { resolveTheme } from '../integrations/themes' import { getRoots } from '../resolver' import { loadSetups } from './load' export default function setupPreparser() { injectPreparserExtensionLoader(async (headmatter, filepath, mode) => { const addons = Array.isArray(headmatter?.addons) ? headmatter.addons : [] + // Resolve theme from headmatter (matching logic from options.ts) + let themeRaw = headmatter?.theme as string | null | undefined + themeRaw = themeRaw === null ? 'none' : (themeRaw || 'default') const { userRoot } = await getRoots() + const [, themeRoot] = await resolveTheme(themeRaw, filepath) + const themeRoots = themeRoot ? [themeRoot] : [] const roots = uniq([ + ...themeRoots, ...await resolveAddons(addons), userRoot, ])