Skip to content

Commit

Permalink
fix Hydration failed because the initial UI... while modifying `met…
Browse files Browse the repository at this point in the history
…a.json` on dev env and react 18 (#606)
  • Loading branch information
dimaMachina committed Jul 28, 2022
1 parent 512953f commit cc1379c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-panthers-cry.md
@@ -0,0 +1,5 @@
---
'nextra': patch
---

fix `Hydration failed because the initial UI...` while modifying `meta.json` on dev env and react 18
23 changes: 7 additions & 16 deletions packages/nextra/src/loader.ts
Expand Up @@ -82,23 +82,14 @@ async function loader(
defaultLocale
)

if (IS_PRODUCTION) {
// We only add meta files as dependencies for production build,
// so we can do incremental builds.
Object.entries(fileMap).forEach(([filePath, { name, meta, locale }]) => {
if (
name === 'meta.json' &&
meta &&
(!fileLocale || locale === fileLocale)
) {
context.addDependency(filePath)
}
})
} else {
// Add the entire directory `pages` as the dependency,
// so we can generate the correct page map.
context.addContextDependency(pagesDir)
for (const [filePath, { name, locale }] of Object.entries(fileMap)) {
if (name === 'meta.json' && (!fileLocale || locale === fileLocale)) {
context.addDependency(filePath)
}
}
// Add the entire directory `pages` as the dependency,
// so we can generate the correct page map.
context.addContextDependency(pagesDir)

// Extract frontMatter information if it exists
const { data, content } = grayMatter(source)
Expand Down

0 comments on commit cc1379c

Please sign in to comment.