Skip to content

Commit

Permalink
fix: wait for content layer sync before starting dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Dec 23, 2024
1 parent 5ab724c commit b55a149
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-pugs-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes race condition where dev server would attempt to load collections before the content had loaded
4 changes: 2 additions & 2 deletions packages/astro/src/content/content-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ export class ContentLayer {
shouldClear = true;
}

if (currentConfigDigest && previousConfigDigest !== currentConfigDigest) {
if (previousConfigDigest && previousConfigDigest !== currentConfigDigest) {
logger.info('Content config changed');
shouldClear = true;
}
if (process.env.ASTRO_VERSION && previousAstroVersion !== process.env.ASTRO_VERSION) {
if (previousAstroVersion && previousAstroVersion !== process.env.ASTRO_VERSION) {
logger.info('Astro version changed');
shouldClear = true;
}
Expand Down
42 changes: 21 additions & 21 deletions packages/astro/src/core/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,6 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevS
}
}

// Start listening to the port
const devServerAddressInfo = await startContainer(restart.container);
logger.info(
'SKIP_FORMAT',
msg.serverStart({
startupTime: performance.now() - devStart,
resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
host: restart.container.settings.config.server.host,
base: restart.container.settings.config.base,
}),
);

if (isPrerelease) {
logger.warn('SKIP_FORMAT', msg.prerelease({ currentVersion }));
}
if (restart.container.viteServer.config.server?.fs?.strict === false) {
logger.warn('SKIP_FORMAT', msg.fsStrictWarning());
}

await attachContentServerListeners(restart.container);

let store: MutableDataStore | undefined;
try {
const dataStoreFile = getDataStoreFile(restart.container.settings, true);
Expand Down Expand Up @@ -133,6 +112,27 @@ export default async function dev(inlineConfig: AstroInlineConfig): Promise<DevS
await contentLayer.sync();
}

// Start listening to the port
const devServerAddressInfo = await startContainer(restart.container);
logger.info(
'SKIP_FORMAT',
msg.serverStart({
startupTime: performance.now() - devStart,
resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
host: restart.container.settings.config.server.host,
base: restart.container.settings.config.base,
}),
);

if (isPrerelease) {
logger.warn('SKIP_FORMAT', msg.prerelease({ currentVersion }));
}
if (restart.container.viteServer.config.server?.fs?.strict === false) {
logger.warn('SKIP_FORMAT', msg.fsStrictWarning());
}

await attachContentServerListeners(restart.container);

logger.info(null, green('watching for file changes...'));

return {
Expand Down

0 comments on commit b55a149

Please sign in to comment.