From cc1379c9cbaf5e3747219210d4a3935e4f43a9d4 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Thu, 28 Jul 2022 14:57:23 +0200 Subject: [PATCH] fix `Hydration failed because the initial UI...` while modifying `meta.json` on dev env and react 18 (#606) --- .changeset/fuzzy-panthers-cry.md | 5 +++++ packages/nextra/src/loader.ts | 23 +++++++---------------- 2 files changed, 12 insertions(+), 16 deletions(-) create mode 100644 .changeset/fuzzy-panthers-cry.md diff --git a/.changeset/fuzzy-panthers-cry.md b/.changeset/fuzzy-panthers-cry.md new file mode 100644 index 0000000000..d452fe18fa --- /dev/null +++ b/.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 diff --git a/packages/nextra/src/loader.ts b/packages/nextra/src/loader.ts index ffa76e238a..71dec40b31 100644 --- a/packages/nextra/src/loader.ts +++ b/packages/nextra/src/loader.ts @@ -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)