Skip to content

Commit

Permalink
fix: do not generate a stub for content types (#12909)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Jan 6, 2025
1 parent 96dade6 commit 011fa0f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-hotels-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a case where `astro:content` types would be erased when restarting the dev server
10 changes: 5 additions & 5 deletions packages/astro/src/core/sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,15 @@ export async function syncInternal({
settings.timer.end('Sync content layer');
} else {
const paths = getContentPaths(settings.config, fs);
// Content is synced after writeFiles. That means references are not created
// To work around it, we create a stub so the reference is created and content
// sync will override the empty file
if (
paths.config.exists ||
// Legacy collections don't require a config file
(settings.config.legacy?.collections && fs.existsSync(paths.contentDir))
) {
// We only create the reference, without a stub to avoid overriding the
// already generated types
settings.injectedTypes.push({
filename: CONTENT_TYPES_FILE,
content: '',
});
}
}
Expand All @@ -182,7 +180,9 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
for (const { filename, content } of settings.injectedTypes) {
const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
fs.mkdirSync(dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, content, 'utf-8');
if (content) {
fs.writeFileSync(filepath, content, 'utf-8');
}
references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
}

Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export interface AstroSettings {
latestAstroVersion: string | undefined;
serverIslandMap: NonNullable<SSRManifest['serverIslandMap']>;
serverIslandNameMap: NonNullable<SSRManifest['serverIslandNameMap']>;
injectedTypes: Array<InjectedType>;
// This makes content optional. Internal only so it's not optional on InjectedType
injectedTypes: Array<Omit<InjectedType, 'content'> & Partial<Pick<InjectedType, 'content'>>>;
/**
* Determine if the build output should be a static, dist folder or a adapter-based server output
* undefined when unknown
Expand Down

0 comments on commit 011fa0f

Please sign in to comment.