Skip to content

Commit 4b510e0

Browse files
committed
fix docs mdx loader cache invalidation problem
1 parent 78a1c28 commit 4b510e0

File tree

1 file changed

+7
-17
lines changed
  • packages/docusaurus-plugin-content-docs/src

1 file changed

+7
-17
lines changed

packages/docusaurus-plugin-content-docs/src/index.ts

+7-17
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,22 @@ import type {DocFile, FullVersion} from './types';
6565
import type {RuleSetRule} from 'webpack';
6666

6767
// MDX loader is not 100% deterministic, leading to cache invalidation issue
68-
// It's possible to use env variables to build a site in different flavors
69-
// and you end-up using stale mdx loader cache hits
70-
//
71-
// This doesn't happen when modifying docusaurus.config.js because doing so
72-
// will invalidate the entire site cache, but can happen with other changes
73-
// such as env variables, or after creating a new docs version.
74-
//
75-
// This happens notably because of the resolveMarkdownLink() callback
76-
// Depending on docs options suck as "lastVersion" and "onlyIncludeVersions"
77-
// When docs versions change over time, the callback may behave differently
78-
// Depending on env variables, @site/docs/my-doc.md might resolve to:
79-
// - /docs/my-doc
80-
// - docs/next/my-doc
81-
// - docs/<otherVersion>/my-doc
82-
//
83-
// To avoid this kind of problem, we invalidate the mdx cache
84-
// whenever docs versions are updated in any way
68+
// This permits to invalidate the MDX loader cache entries when content changes
69+
// Problem documented here: https://github.com/facebook/docusaurus/pull/10934
70+
// TODO this is not a perfect solution, find better?
8571
async function createMdxLoaderDependencyFile({
8672
dataDir,
73+
options,
8774
versionsMetadata,
8875
}: {
8976
dataDir: string;
77+
options: PluginOptions;
9078
versionsMetadata: VersionMetadata[];
9179
}) {
9280
const filePath = path.join(dataDir, '__mdx-loader-dependency.json');
9381
// the cache is invalidated whenever this file content changes
9482
const fileContent = {
83+
options,
9584
versionsMetadata,
9685
};
9786
await fs.ensureDir(dataDir);
@@ -146,6 +135,7 @@ export default async function pluginContentDocs(
146135
dependencies: [
147136
await createMdxLoaderDependencyFile({
148137
dataDir,
138+
options,
149139
versionsMetadata,
150140
}),
151141
],

0 commit comments

Comments
 (0)