fix(mdx-loader): report vfile messages from Remark plugins - #12399
fix(mdx-loader): report vfile messages from Remark plugins#12399inancsege wants to merge 1 commit into
Conversation
Remark/Rehype plugins report non-fatal problems by attaching messages to the vfile instead of throwing. The MDX processor discarded those messages entirely, so warnings emitted by third-party plugins were invisible. The processor now exposes the vfile messages on its result, and the loader warns about them. Reporting is restricted to the client compiler to avoid duplicate warnings in prod mode, mirroring the existing logic in the unusedDirectives Remark plugin. Fixes facebook#9953
|
Hi @inancsege! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Pre-flight checklist
vfileby Remark plugins are not reported. #9953) and the maintainers have approved on my working plan.Motivation
Fixes #9953
Remark and Rehype plugins report non-fatal problems by attaching messages to the vfile via
file.message(...)rather than by throwing. Those messages accumulate onresult.messages, but the MDX processor discarded them:So warnings emitted by third-party Remark plugins through the standard Unified reporting API were invisible to users. Fatal messages (
file.fail(...)) already throw and are surfaced bycompileToJSX, so this only concerns the non-fatal path.From the issue:
Changes
processor.tsnow exposes the vfile messages onSimpleProcessorResultinstead of dropping them.reportMDXMessages()inmessages.tsformats and logs them, following the existingloggerconventions.loader.tscalls it after compilation.Reporting is restricted to the client compiler so prod builds do not emit each warning twice. This mirrors the existing logic in the
unusedDirectivesRemark plugin.Example output, for a plugin calling
file.message('Some plugin warning', ...):No new configuration option is introduced. If you would rather have this gated behind a
siteConfig.markdown.hooksseverity option than a plain warning, I am happy to follow up.Test Plan
New unit tests:
__tests__/processor.test.ts: the processor returns messages reported by a Remark plugin. This file previously contained no tests, as the old TODO about Jest and ESM no longer applies under Vitest.__tests__/messages.test.ts: formatting including line and column, the empty case, and the server compiler case.__tests__/loader.test.ts: end to end throughmdxLoader, asserting the warning reachesconsole.warn.Verified locally:
vitest run: 185 test files, 2965 tests passingtsc --noEmit -p packages/docusaurus-mdx-loader/tsconfig.json: cleaneslint "packages/docusaurus-mdx-loader/src/**/*.ts": no errorsoxfmt --list-different: cleanEach test was confirmed to fail before the corresponding change was applied.
Test links
This is a build-time logging change with no UI impact, so there is no relevant deploy preview page.
Related issues/PRs
Fixes #9953