From 3a1e181137431eface85681f3dfbabe135161561 Mon Sep 17 00:00:00 2001 From: Wout Date: Mon, 20 Apr 2026 09:08:28 +0200 Subject: [PATCH] Fix reload after rebuilds of the target extension A reload should not be triggerd when watching Crystal files to do a CSS rebuild. Only changes to CSS files should trigger a CSS reload. --- src/bun/lucky.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/bun/lucky.js b/src/bun/lucky.js index 26bc3c954..cf0970dc0 100644 --- a/src/bun/lucky.js +++ b/src/bun/lucky.js @@ -276,9 +276,11 @@ export default { }, async watch() { + const cssBase = ['css'] + const jsBase = ['js', 'ts', 'jsx', 'tsx'] const extras = this.config.watchExtensions || {} - const cssExts = ['css', ...(extras.css || [])] - const jsExts = ['js', 'ts', 'jsx', 'tsx', ...(extras.js || [])] + const cssExts = [...cssBase, ...(extras.css || [])] + const jsExts = [...jsBase, ...(extras.js || [])] const handler = (event, filename) => { if (!filename) return @@ -306,12 +308,20 @@ export default { console.log(` ▸ ${normalizedFilename} changed`) ;(async () => { try { - if (cssExts.includes(ext)) await this.buildCSS() - else if (jsExts.includes(ext)) await this.buildJS() - else if (base.includes('.')) await this.copyStaticAssets() + let kind = null + if (cssExts.includes(ext)) { + await this.buildCSS() + if (cssBase.includes(ext)) kind = 'css' + } else if (jsExts.includes(ext)) { + await this.buildJS() + if (jsBase.includes(ext)) kind = 'full' + } else if (base.includes('.')) { + await this.copyStaticAssets() + kind = 'full' + } await this.writeManifest() - this.reload(ext === 'css' ? 'css' : 'full') + if (kind) this.reload(kind) } catch (err) { console.error(' ✖ Build error:', err.message) if (err.errors) for (const e of err.errors) console.error(e)