Skip to content

Commit f88d0f7

Browse files
zrosenbauerclaude
andauthored
fix(packages/cli): disable persistent build cache on config-reload restart (#67)
Rspress's persistent build cache (`buildCache.cacheDigest`) only tracks sidebar/nav structure and the Rspress version. It is unaware of zpress-specific config values (title, theme, colors, `source.define` compile-time constants). When only those values changed, the stale cached build output was served, making config changes appear to have no effect. Additionally, `configFilePath: ''` meant the file-based `buildDependencies` invalidation path was a no-op, so no config file change could bust the cache. Disable the persistent build cache on config-reload restarts by passing `performance: { buildCache: false }` via `extraBuilderConfig`. The initial cold start still benefits from the cache; only restarts triggered by config changes bypass it to force a fresh Rsbuild compilation. Co-authored-by: Claude <noreply@anthropic.com>
1 parent c808623 commit f88d0f7

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@zpress/cli': patch
3+
---
4+
5+
Fix config changes not propagating during dev
6+
7+
Disable Rspress's persistent build cache on config-reload restarts. The cache's digest only tracks sidebar/nav structure, so changes to title, theme, colors, and other `source.define` values were invisible to it, causing stale output to be served after a restart.

packages/cli/src/lib/rspress.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ interface ServerInstance {
4141
readonly close: () => Promise<void>
4242
}
4343

44+
/**
45+
* Internal options for `startServer` that control rebuild behaviour.
46+
*/
47+
interface StartServerOptions {
48+
/** When true, disables the persistent build cache for this invocation. */
49+
readonly skipBuildCache: boolean
50+
}
51+
4452
/**
4553
* Callback invoked when the dev server should restart due to config changes.
4654
*/
@@ -66,7 +74,10 @@ export async function startDevServer(
6674
// oxlint-disable-next-line functional/no-let -- mutable server instance for restart capability
6775
let serverInstance: ServerInstance | null = null
6876

69-
async function startServer(config: ZpressConfig): Promise<boolean> {
77+
async function startServer(
78+
config: ZpressConfig,
79+
internalOptions: StartServerOptions
80+
): Promise<boolean> {
7081
const rspressConfig = createRspressConfig({
7182
config,
7283
paths,
@@ -85,6 +96,11 @@ export async function startDevServer(
8596
port,
8697
strictPort: true,
8798
},
99+
// Disable persistent build cache on config-reload restarts.
100+
// Rspress's cacheDigest only covers sidebar/nav structure,
101+
// so changes to title, theme, colors, source.define values
102+
// etc. would serve stale cached output without this.
103+
...buildCacheOverride(internalOptions),
88104
},
89105
})
90106
return true
@@ -95,7 +111,7 @@ export async function startDevServer(
95111
}
96112

97113
// Start initial server — exit if it fails on first boot
98-
const started = await startServer(options.config)
114+
const started = await startServer(options.config, { skipBuildCache: false })
99115
if (!started) {
100116
process.exit(1)
101117
}
@@ -128,8 +144,8 @@ export async function startDevServer(
128144
serverInstance = null
129145
}
130146

131-
// Start new server with fresh config
132-
const restarted = await startServer(newConfig)
147+
// Start new server with fresh config (bypass persistent cache)
148+
const restarted = await startServer(newConfig, { skipBuildCache: true })
133149
if (restarted) {
134150
process.stdout.write('✅ Dev server restarted\n\n')
135151
} else {
@@ -233,6 +249,26 @@ function createCloseEvent(httpServer: Server | null): Promise<unknown[]> | null
233249
return once(httpServer, 'close')
234250
}
235251

252+
/**
253+
* Return a performance config override that disables persistent build cache
254+
* on config-reload restarts.
255+
*
256+
* Rspress's persistent cache (`buildCache.cacheDigest`) only tracks sidebar/nav
257+
* structure. Changes to title, theme, colors, and `source.define` values are
258+
* invisible to it, causing stale cached output. Disabling the cache on restart
259+
* forces a fresh Rsbuild compilation with the updated config values.
260+
*
261+
* @private
262+
* @param options - Internal server options
263+
* @returns Partial Rsbuild config with cache override, or empty object
264+
*/
265+
function buildCacheOverride(options: StartServerOptions): Record<string, unknown> {
266+
if (options.skipBuildCache) {
267+
return { performance: { buildCache: false } }
268+
}
269+
return {}
270+
}
271+
236272
/**
237273
* Extract the underlying HTTP server from a Rspress/Rsbuild server instance.
238274
*

0 commit comments

Comments
 (0)