diff --git a/.changeset/light-meals-press.md b/.changeset/light-meals-press.md new file mode 100644 index 000000000000..69b8f938892d --- /dev/null +++ b/.changeset/light-meals-press.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Skips updating content layer files if content is unchanged diff --git a/packages/astro/src/content/mutable-data-store.ts b/packages/astro/src/content/mutable-data-store.ts index 7f125ed4b4d3..23ea782ba587 100644 --- a/packages/astro/src/content/mutable-data-store.ts +++ b/packages/astro/src/content/mutable-data-store.ts @@ -213,6 +213,11 @@ export default new Map([\n${lines.join(',\n')}]); const tempFile = filePath instanceof URL ? new URL(`${filePath.href}.tmp`) : `${filePath}.tmp`; try { + const oldData = await fs.readFile(filePath, 'utf-8').catch(() => ''); + if (oldData === data) { + // If the data hasn't changed, we can skip the write + return; + } // Write it to a temporary file first and then move it to prevent partial reads. await fs.writeFile(tempFile, data); await fs.rename(tempFile, filePath);