Skip to content

Commit a685ca6

Browse files
committed
watch: split reload-signal (CSS) from template-signal (templates)
CSS changes still write .clay/reload-signal → full nodemon restart, which gives the browser a fresh ETag for the stable CSS URL. Template changes now write .clay/template-signal → html.init() in-process (~100ms), no restart needed. Previously both used reload-signal which broke CSS visibility when we replaced nodemon.restart() with html.init(). Made-with: Cursor
1 parent 274d7c0 commit a685ca6

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lib/cmd/vite/scripts.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,9 @@ async function watch(options = {}) {
12961296
.then(() => {
12971297
stopStyleTick();
12981298
console.log(clr.styles('[styles]') + clr.rebuilt(` Rebuilt (${Date.now() - start}ms)`));
1299-
// Reuse the same reload-signal as templates so start.js/nodemon
1300-
// restarts the server and the browser picks up the new CSS.
1299+
// Write reload-signal so start.js/nodemon restarts the server — a full
1300+
// restart is needed because CSS has stable URLs and the browser won't
1301+
// re-fetch without either a new URL or an ETag change from a new process.
13011302
return fs.ensureDir(CLAY_DIR)
13021303
.then(() => fs.writeFile(path.join(CLAY_DIR, 'reload-signal'), String(Date.now())))
13031304
.catch(() => {});
@@ -1325,7 +1326,10 @@ async function watch(options = {}) {
13251326
fontWatcher.on('change', rebuildFonts).on('add', rebuildFonts).on('unlink', rebuildFonts);
13261327

13271328
// ── Template watcher ─────────────────────────────────────────────────────────
1328-
const RELOAD_SIGNAL = path.join(CLAY_DIR, 'reload-signal');
1329+
// Separate signals so each trigger is handled correctly server-side:
1330+
// reload-signal → nodemon.restart() in start.js (CSS: full restart busts browser cache)
1331+
// template-signal → html.init() in renderers.js (templates: fast in-process re-register)
1332+
const TEMPLATE_SIGNAL = path.join(CLAY_DIR, 'template-signal');
13291333

13301334
const rebuildTemplates = debounce((changedFile) => {
13311335
if (changedFile) console.log(clr.templates('[templates]') + ' Changed: ' + clr.file(rel(changedFile)));
@@ -1336,10 +1340,10 @@ async function watch(options = {}) {
13361340
.then(() => {
13371341
stopTemplateTick();
13381342
console.log(clr.templates('[templates]') + clr.rebuilt(` Rebuilt (${Date.now() - start}ms)`));
1339-
// Write the reload-signal file so that the app server (start.js / nodemon)
1340-
// picks up the template change without needing to poll thousands of files.
1343+
// Write template-signal so renderers.js calls html.init() in-process
1344+
// (~100ms) without a full server restart.
13411345
return fs.ensureDir(CLAY_DIR)
1342-
.then(() => fs.writeFile(RELOAD_SIGNAL, String(Date.now())))
1346+
.then(() => fs.writeFile(TEMPLATE_SIGNAL, String(Date.now())))
13431347
.catch(() => {}); // non-fatal if signal can't be written
13441348
})
13451349
.catch(e => { stopTemplateTick(); console.error(clr.templates('[templates]') + clr.error(` rebuild failed: ${e.message}`)); });

0 commit comments

Comments
 (0)