Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not generate a stub for content types #12909

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading