diff --git a/.changeset/stupid-teachers-yell.md b/.changeset/stupid-teachers-yell.md new file mode 100644 index 000000000000..a00ccceb5603 --- /dev/null +++ b/.changeset/stupid-teachers-yell.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Cleans up content layer sync during builds and programmatic `sync()` calls diff --git a/packages/astro/src/core/dev/container.ts b/packages/astro/src/core/dev/container.ts index 0ca40cd74b3a..063681f2717c 100644 --- a/packages/astro/src/core/dev/container.ts +++ b/packages/astro/src/core/dev/container.ts @@ -120,6 +120,7 @@ export async function createContainer({ logger, skip: { content: true, + cleanup: true, }, force: inlineConfig?.force, manifest, diff --git a/packages/astro/src/core/sync/index.ts b/packages/astro/src/core/sync/index.ts index 823470e970b1..9e2a2de22d4c 100644 --- a/packages/astro/src/core/sync/index.ts +++ b/packages/astro/src/core/sync/index.ts @@ -45,6 +45,8 @@ export type SyncOptions = { skip?: { // Must be skipped in dev content?: boolean; + // Cleanup can be skipped in dev as some state can be reused on updates + cleanup?: boolean; }; manifest: ManifestData; }; @@ -141,6 +143,10 @@ export async function syncInternal({ store, }); await contentLayer.sync(); + if (!skip?.cleanup) { + // Free up memory (usually in builds since we only need to use this once) + contentLayer.dispose(); + } settings.timer.end('Sync content layer'); } else { const paths = getContentPaths(settings.config, fs);