Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-plugin-mdx] Frontmatter shows up in page content #35901

Closed
2 tasks done
karlhorky opened this issue Jun 9, 2022 · 4 comments
Closed
2 tasks done

[gatsby-plugin-mdx] Frontmatter shows up in page content #35901

karlhorky opened this issue Jun 9, 2022 · 4 comments
Labels
topic: remark/mdx Related to Markdown, remark & MDX ecosystem type: bug An issue or pull request relating to a bug in Gatsby

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Jun 9, 2022

Preliminary Checks

Description

After upgrading from gatsby-plugin-mdx@3.15.1 to gatsby-plugin-mdx@3.15.2, we're seeing our Frontmatter code show up in the content of the page 😱

Screen Shot 2022-06-04 at 20 14 57

This appears regardless of whether we have the JSFrontmatterEngine set to true or unconfigured...

cc @pieh @GeeWizWow


Workaround

A solution for gatsby build (SSG) requires reverting the change made by @pieh in #35830:

  1. Commenting out passing all options to gray-matter in the mdx-loader.js, utils/mdx.js, utils/gen-mdx.js files (using patch-package)
  2. And then ALSO enabling the JSFrontmatterEngine option

Super strange, wonder what's causing this Frontmatter to show up in the content.

Reproduction Link

https//.com/karlhorky/gatsby-mdx-frontmatter-bug

Steps to Reproduce

  1. Upgrade existing project from gatsby-plugin-mdx@3.15.1 to gatsby-plugin-mdx@3.15.2
  2. Run gatsby develop or gatsby build
  3. Observe Frontmatter in the page content

Expected Result

No Frontmatter in the page content

Actual Result

Frontmatter displayed in the page content

Environment

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.11.0 - /var/folders/sw/v93sywxs2g1bcsr6ln488qfh0000gn/T/yarn--1654793941511-0.7489250249814705/node
    Yarn: 1.22.19 - /var/folders/sw/v93sywxs2g1bcsr6ln488qfh0000gn/T/yarn--1654793941511-0.7489250249814705/yarn
    npm: 8.7.0 - ~/.nvm/versions/node/v16.11.0/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Firefox: 99.0.1
    Safari: 15.5

Config Flags

No response

@karlhorky karlhorky added the type: bug An issue or pull request relating to a bug in Gatsby label Jun 9, 2022
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 9, 2022
@pieh
Copy link
Contributor

pieh commented Jun 9, 2022

Hi @karlhorky

We did merge the #35859 - the initial suggestion comments you made in the PR that introduced it made sense and we just used it. This was not release yet to npm.

I couldn't really reproduce the part about the change not working in builds - I suspect this is because of webpack caching (if you edit files in node_modules, webpack doesn't detect those - see https://webpack.js.org/configuration/cache/#cachemanagedpaths

Webpack will avoid hashing and timestamping them, assume the version is unique and will use it as a snapshot (for both memory and filesystem cache).

So to test changes like that inside node_modules, you do need to nuke webpack cache (either gatsby clean or rm -rf .cache/webpack (to just nuke webpack caches).

I'm not sure if the change above is enough - this was targetted for webpack loader for now, but this is only usage of the matter field returned from gray-matter in MDX plugin. We will be checking other uses as well soon

@karlhorky
Copy link
Contributor Author

karlhorky commented Jun 9, 2022

Oh didn't see #35859 yet, thanks!! I'll be happy to test whether this fixes the issue without my patches when it is published to npm.

So to test changes like that inside node_modules, you do need to nuke webpack cache (either gatsby clean or rm -rf .cache/webpack (to just nuke webpack caches).

Yeah I was doing gatsby clean every time I changed the patch-package patch, to make sure that I wasn't confusing myself.

@pieh
Copy link
Contributor

pieh commented Jun 10, 2022

@karlhorky just released gatsby-plugin-mdx@3.16.1 with the change from the PR.

I did want to try the reproduction, but link seems borked. Tried using github.com ( https://github.com/karlhorky/gatsby-mdx-frontmatter-bug ) but repo like doesn't exist or is private

@karlhorky
Copy link
Contributor Author

karlhorky commented Jun 11, 2022

Ah sorry, that repo is not there right now.

But just upgraded to gatsby-plugin-mdx@3.16.1 and deleted my patch, and it seems to have resolved the problem! 🎉

Passing our tests:

Screen Shot 2022-06-11 at 11 54 05

And, no more Frontmatter content on the page:

Screen Shot 2022-06-11 at 12 09 12

Closing this out.

@LekoArts LekoArts added topic: remark/mdx Related to Markdown, remark & MDX ecosystem and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: remark/mdx Related to Markdown, remark & MDX ecosystem type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants