MDX Hot Reload
To make Next.js blog page hot reloads while editing the .mdx file
The Problem
If you have a blog created with Next.js and MDX either using mdx-bundler or next-mdx-remote (maybe there's more libs with the same issue), you must've experienced the dreaded manual refresh every time you want to see some changes. The hot reload or fast refresh doesn't work because we are not directly changing a JavaScript or TypeScript files.
With this short article, I'll show you how to enable hot-reload for your blog page by listening to mdx file changes.
Install next-remote-refresh
This library enables hot reload by utilizing websocket by listening to folder changes.
Update next.config.js
I'm listening changes for all files inside src/contents
folder.
Add the hook to _app.tsx
It should work now!