Skip to content

fix: get mdc configs by calling mdc:configSources hook#3736

Merged
farnabaz merged 3 commits intomainfrom
fix/mdc-config-order
Mar 26, 2026
Merged

fix: get mdc configs by calling mdc:configSources hook#3736
farnabaz merged 3 commits intomainfrom
fix/mdc-config-order

Conversation

@danielroe
Copy link
Copy Markdown
Member

@danielroe danielroe commented Feb 27, 2026

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

discovered whilst working on nuxt-content-twoslash, currently if a module also hooks into mdc:configSources but does so after nuxt content, any changes it makes will be silently dropped due to ordering.

this instead moves to call the hook (and depends on nuxt-content/mdc#471)

Important

this should not be released before nuxt-content/mdc#471. the mdc pr is safe to release on its own, but it should be released, and then this PR should be released, depending on the newer version of mdc, or we'll lose 'local' mdc.config.ts files

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
content Ready Ready Preview, Comment Mar 26, 2026 5:11pm

@danielroe danielroe requested a review from farnabaz February 27, 2026 08:00
@danielroe danielroe marked this pull request as draft February 27, 2026 08:00
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 27, 2026

npm i https://pkg.pr.new/@nuxt/content@3736

commit: af1c37a

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d6cbe93-1ee2-4508-bc07-5eb8215b21a4

📥 Commits

Reviewing files that changed from the base of the PR and between e54ea95 and af1c37a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json
✅ Files skipped from review due to trivial changes (1)
  • package.json

📝 Walkthrough

Walkthrough

Removed the exported setParserOptions mutator and introduced setMdcConfigResolver(fn) to provide an asynchronous MDC config getter. Code now obtains MDC configs by invoking the resolver (_getMdcConfigs?.() ?? []) instead of reading parserOptions.mdcConfigs. src/utils/mdc.ts registers the resolver, collects config source paths via nuxt.callHook('mdc:configSources', paths), lazily imports each config, caches the results, and returns them on subsequent calls. package.json updates @nuxtjs/mdc from ^0.20.1 to ^0.21.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main change—moving from a module load order approach to calling the mdc:configSources hook to retrieve MDC configs.
Description check ✅ Passed The pull request description explains the bug being fixed, the rationale, and the dependency on another PR, all of which relate to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mdc-config-order

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@danielroe danielroe force-pushed the fix/mdc-config-order branch from 8547381 to a426486 Compare February 27, 2026 09:51
@danielroe danielroe changed the title fix: process content on nuxt.ready rather than in modules:done fix: get mdc configs by calling mdc:configSources hook Feb 27, 2026
@danielroe danielroe marked this pull request as ready for review February 27, 2026 11:13
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/utils/mdc.ts (1)

19-30: Prevent duplicate config resolution on concurrent first access.

Lines 21-27 can run more than once if multiple calls happen before _configs is set. Cache the in-flight promise too.

♻️ Suggested change
 let _configs: MdcConfig[] | undefined
+let _configsPromise: Promise<MdcConfig[]> | undefined
 setMdcConfigResolver(async () => {
-  if (!_configs) {
-    const paths: string[] = []
-    await nuxt.callHook('mdc:configSources', paths)
-    const jiti = createJiti(nuxt.options.rootDir)
-    _configs = paths.length
-      ? await Promise.all(paths.map(path => jiti.import(path).then(m => (m as { default: MdcConfig }).default || m)))
-      : []
-  }
-  return _configs
+  if (_configs) {
+    return _configs
+  }
+  _configsPromise ||= (async () => {
+    const paths: string[] = []
+    await nuxt.callHook('mdc:configSources', paths)
+    const jiti = createJiti(nuxt.options.rootDir)
+    _configs = paths.length
+      ? await Promise.all(paths.map(path => jiti.import(path).then(m => (m as { default: MdcConfig }).default || m)))
+      : []
+    return _configs
+  })()
+  return _configsPromise
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/mdc.ts` around lines 19 - 30, The resolver passed to
setMdcConfigResolver can run multiple times concurrently because only the
resolved _configs is cached; instead cache the in-flight promise so concurrent
calls await the same work. Modify the resolver in src/utils/mdc.ts to use a
module-level variable (e.g., _configsPromise) and set it when starting the async
work (calling nuxt.callHook('mdc:configSources'), createJiti(...) and
Promise.all(paths.map(... jiti.import ...))) and have subsequent calls return
await _configsPromise; once fulfilled assign the resulting array to _configs and
clear/retain the promise as appropriate so only the first invocation does the
import work.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils/mdc.ts`:
- Around line 23-26: The call to nuxt.callHook('mdc:configSources', paths) uses
an unreleased feature (PR `#471`) so paths may remain empty with
`@nuxtjs/mdc`@0.20.1; update the call to be defensive: detect the installed mdc
version or the presence of the hook support and only call
nuxt.callHook('mdc:configSources', paths) when supported, otherwise fall back to
the existing default sources or explicitly populate paths; reference the symbols
nuxt.callHook, 'mdc:configSources', and the paths variable in src/utils/mdc.ts,
or alternatively update the dependency constraint to a version that includes PR
`#471` before relying on the hook.

---

Nitpick comments:
In `@src/utils/mdc.ts`:
- Around line 19-30: The resolver passed to setMdcConfigResolver can run
multiple times concurrently because only the resolved _configs is cached;
instead cache the in-flight promise so concurrent calls await the same work.
Modify the resolver in src/utils/mdc.ts to use a module-level variable (e.g.,
_configsPromise) and set it when starting the async work (calling
nuxt.callHook('mdc:configSources'), createJiti(...) and
Promise.all(paths.map(... jiti.import ...))) and have subsequent calls return
await _configsPromise; once fulfilled assign the resulting array to _configs and
clear/retain the promise as appropriate so only the first invocation does the
import work.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8547381 and a426486.

📒 Files selected for processing (2)
  • src/utils/content/index.ts
  • src/utils/mdc.ts

@farnabaz farnabaz merged commit 57f5552 into main Mar 26, 2026
8 checks passed
@farnabaz farnabaz deleted the fix/mdc-config-order branch March 26, 2026 17:16
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.

2 participants