Skip to content

Commit

Permalink
fix: other md document updates cause home page data loss (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
callqh committed Oct 17, 2022
1 parent 6efa733 commit b5edd92
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/theme-default/logic/useFrontmatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect } from 'react';
import { usePageData } from '@client';
import { removeTrailingSlash } from './utils';

export const useFrontmatter = () => {
const pageData = usePageData();
Expand All @@ -9,10 +10,13 @@ export const useFrontmatter = () => {
// The frontmatter data changes require us to manually trigger the react rerender
useEffect(() => {
if (import.meta.env.DEV) {
import.meta.hot?.on('md(x)-changed', ({ filePath }) => {
import.meta.hot?.on('md(x)-changed', ({ filePath, routePath }) => {
const fileRoutePath = removeTrailingSlash(routePath);
import(/* @vite-ignore */ `${filePath}?import&t=${Date.now()}`).then(
(mod) => {
setFrontmatter(mod.frontmatter);
// fix: updates to non-Home md documents will trigger this event,resulting in loss of Home data
pageData.routePath === fileRoutePath &&
setFrontmatter(mod.frontmatter);
}
);
});
Expand Down

1 comment on commit b5edd92

@vercel
Copy link

@vercel vercel bot commented on b5edd92 Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.