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.
Problem
When making changes to a
.md
or.mdx
page in a Doctocat site, this error appears:This error occurs because
gatsby-plugin-mdx
should insertfrontmatter
in the page context of every page, and does on the first build, but when HMR kicks in the frontmatter is lost.This is a known bug in gatsby-plugin-mdx: gatsbyjs/gatsby#21837
Possible solutions
frontmatter
to the page context in our localgatsby-node.js
instead of relying ongatsby-plugin-mdx
to handlefrontmatter
for us (This is the solution implemented in this PR)gatsby-plugin-mdx
so that it correctly sets thefrontmatter
when a page is hot reloaded.Solution 1 (implemented)
@BinaryMuse had previously implemented this solution in #116. However, the GraphQL query that fetched the frontmatter only requested the
title
field. This caused frontmatter fields likestatus
andsource
to be lost.In this PR, I reimplemented @BinaryMuse's solution and added
status
,source
,additionalContributors
fields to the frontmatter GraphQL request.Downsides
null
notundefined
. Here's how I worked around that in this PR:Solution 2
I think this is the Right™️ solution, but I'm not sure how to implement it. I would have to a deep dive into the internals of
gatsby-plugin-mdx
and Gatsby itself.Closes #146