Skip to content

Conversation

@kaigritun
Copy link

Fixes #2402

Problem

The setup/preparser.ts file in themes was being ignored while other setup files like shiki.ts were correctly loaded.

Root Cause

In packages/slidev/node/setups/preparser.ts, the roots array only included:

  • Addon roots
  • User root

But NOT theme roots. Compare with how setupShiki() receives resolved.roots which includes themes.

Solution

Resolve the theme root from headmatter (using the same logic as options.ts) and include it in the roots array passed to loadSetups().

Testing

  • All 101 existing tests pass
  • ESLint passes

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,
    ])

Fixes slidevjs#2402

The preparser setup was only loading setup/preparser.ts from addons
and userRoot, but not from the theme. This caused theme preparser
extensions to be ignored while other setup files like shiki.ts
were correctly loaded from themes.

This fix resolves the theme root from headmatter (matching the logic
in options.ts) and includes it in the roots array passed to loadSetups.
@netlify
Copy link

netlify bot commented Feb 8, 2026

Deploy Preview for slidev ready!

Name Link
🔨 Latest commit 80f47f5
🔍 Latest deploy log https://app.netlify.com/projects/slidev/deploys/6987f0edb3227b00085e1a2d
😎 Deploy Preview https://deploy-preview-2456--slidev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@antfu
Copy link
Member

antfu commented Feb 9, 2026

Why do you want to use a theme to change the preparser but not an addon? I believe this was on purpose to differentiate two integrations with different scope

@kaigritun
Copy link
Author

Good question! I based this on consistency with existing behavior - themes already support setup/shiki.ts and other setup files via resolved.roots (which includes themes), but preparser was the exception.

The original issue (#2402) reports that users expect parity: if setup/shiki.ts works in themes, setup/preparser.ts should too.

That said, if the intent is for preparser customization to be addon-only, I can close this PR - just wanted to match the pattern established by other setup files. Happy to follow whichever direction you prefer!

@antfu
Copy link
Member

antfu commented Feb 10, 2026

Shiki is related to the theming, which is why it's included. We could update the docs to clear the behaviour instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preparser.ts not loaded from theme

2 participants