Replies: 2 comments 1 reply
-
Thanks for clearly exposing the issue. This is in my todo list and I will investigate it at some point, I don't have much time for now. This is an issue similar to what the future API for react-router v7 will have, so I definitely need to find a way to extends this |
Beta Was this translation helpful? Give feedback.
-
Can you elaborate more on the use case of FYI, I had this PR on remix for mdx hmr remix-run/remix#7954 and Remix currently doesn't support hmr when mdx file includes frontmatter. This is a trick I was thinking, but indeed this doesn't allow importers to react on change in frontmatter: {
transform(code: string) {
if (code.includes('export const frontmatter')) {
// cheat `isLikelyComponentType`
// https://github.com/facebook/react/blob/f5af92d2c47d1e1f455faf912b1d3221d1038c37/packages/react-refresh/src/ReactFreshRuntime.js#L717-L723
code += `
;Object.defineProperty(frontmatter, "$$typeof", {
enumerable: false,
value: Symbol.for('react.memo')
});
`;
return code;
}
},
}, |
Beta Was this translation helpful? Give feedback.
-
I am using Vite + MDX and a frontmatter plugin.
The plugin turns MDX into JSX + frontmatter export as const. Something like:
→
→
→
Because the plugin exports an object and the heuristic of triple equals only does an identity check, every change triggers a full reload:
vite-plugin-react/packages/plugin-react/src/refreshUtils.js
Lines 37 to 44 in 2737d41
It's not so straightforward to move the exports to another file, because this is a 'hidden' compilation step, and it would be quite awkward to move the exports into a separate file.
Repro on StackBlitz: Just edit the
Test.mdx
and see that it always does a full reload. If you remove the frontmatter part at the top, it actually does a fast reload.I don't think it warrants a full page reload when a plain old object has changed. Is there a way to solve this gracefully?
One thing that comes to mind is to offer an option like
customEquals
that could be hooked intorefreshUtils.js
above, to enable customization for equality checks: e.g. if the key equalsfrontmatter
I could do a deep equals, otherwise fallback to the default triple equals===
.Beta Was this translation helpful? Give feedback.
All reactions