fix(mdx-loader): get correct error line numbers, handle front matter + contentTitle with remark #9386
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.
Motivation
As users upgrade to v3 they are going to encounter compilation errors presenting line numbers. This ensures that the displayed line numbers are correct to avoid confusing users.
The way we used to handle MDX files is problematic because we stripped front matter and contentTitle before passing the string to MDX, and all errors usually had incorrect line numbers.
This was also requested that it should be possible to access front matter while writing a remark plugin: now this is possible.
Fix #3935
Note: although the logic to generate the
contentTitle
string probably has changed a bit, I consider this is not a breaking change: turning the h1 line AST to a proper string is a best-effort and considered as an implementation detail. If you care about SEO title etc, you must provide an explicit front matter title, in particular if you use fancy JSX/HTML syntax in the h1 title.Test Plan
CI, Argos
Test links
Deploy preview: https://deploy-preview-9386--docusaurus-2.netlify.app/