Closed MikeM2343 closed 3 years ago
@MikeM2343 I believe that I experienced this same issue. My workaround was not to mutate the returned data object, at which point things worked fine.
@arakelian Thank you for the feedback, Greg.
You are correct that you should not modify the data object that is returned from the matter call. After some digging, I found that by modifying the data object, you are in fact modifying the data object in the cache for the mdx content string that you requested. If you then request that same string to be converted again, it will return the modified data object, which is why it looks like stale data.
I ended up fixing my problem by disabling the cache as follows:
const mdx = matter(str, {})
Please note that stringify(content, data) will also cache data because before it stringify's the content and the front matter, it calls matter(content) to get a file object, which it in turn passes to the internal stringify function. To disable caching there, you also need to pass in options like so:
const str = stringify(mdxContent, mdxData, {})
In my case it made sense to completely disable the cache because in an mdx editor situation, you would end up caching every single character edit of all files until the page is refreshed.
Although this is a bit of a gotcha for people using the library, it appears to be by design, so I'm closing the issue.
Steps to reproduce:
I believe this is caused because the cache is based on the "content" portion of the input string and not based on the entire input string.