Repository navigation
fix(flame): restart the dev server when a workspace package rebuilds - #427
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
Important
The recursive watcher on a sibling's dist/ dies silently when that directory is deleted and recreated — which core, markdown and themes-colors do on every build/clean (rm -rf dist). After a full rebuild with identical output, later real changes to that package no longer restart the dev server. Reproduced against dev-watch.ts; details inline.
Reviewed changes — the full diff at 895839c: the new restart-on-rebuild path, the supervisor, the HMR reconnect script, workspace wiring and tests.
dev-watch.ts— resolves the four@docubook/*siblings from their main entry (skippingnode_modulescopies), fingerprintsdist/**/*.{js,mjs,css}+styles.css, and debouncesfs.watchevents into oneonChangeper real content change.server.ts/server.impl.ts— the deadresolveMdxContentSrc()watcher is removed; a supervised server exits with code 75 on a package change, an unsupervised one logs a hint.bin/dev-supervisor.mjs+cli.js—flame devis respawned on exit 75 only when a sibling is workspace-linked;FLAME_DEV_SUPERVISE=0/1overrides, SIGINT/SIGTERM are forwarded and end supervision.- HMR client (
html.ts,html.shared.ts) — on SSE error it pollsHEADwith backoff and reloads once the server answers, instead of a fixed 2 s reload. Both servers build the client bundle before listening, so the probe only succeeds when the new process is actually ready. - Workspace wiring —
vite build --watch --emptyOutDir=falsedev scripts, turbodev→^build, rootpnpm dev, docs and a flame patch changeset.
Verified locally under Node 24: the three new/changed test files pass (74 tests), tsc --noEmit and oxlint are clean, and Vite's CLI does honor --emptyOutDir=false (a sentinel file in dist/ survives it and is wiped by a plain vite build).
claude-fable-5-1 | 𝕏
…ated A recursive fs.watch is bound to the directory it was opened on. The build and clean scripts of core, markdown and themes-colors run `rm -rf dist`, so after a full rebuild of a sibling package (identical output, no restart) the old dist/ watcher went silent and later real rebuilds never restarted the dev server (pullfrog review on #427). The package-root watcher already sees `dist` being removed or created; re-attach the dist/ watcher then, and on a watcher error. Covered by a test that removes and recreates dist/ before a real change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
fdae301 to
2f2ea88
Compare
The dev server's component watcher never started: it resolved @docubook/markdown/package.json, which the package does not export (ERR_PACKAGE_PATH_NOT_EXPORTED). It also watched markdown/src, while flame loads the package from dist/, and only rebuilt the client bundle while server rendering kept the modules it loaded at startup. - .docu/node/dev-watch.ts resolves workspace-linked @DocuBook packages (core, markdown, ui-react, themes-colors) from their main entry, skips installed copies, and watches dist/ plus styles.css. A content fingerprint ignores identical rebuilds and half-written output. The dist/ watcher is re-attached when dist/ is recreated, since build and clean scripts `rm -rf dist`. - On a real change the Bun and Node/Deno dev servers exit with code 75. bin/dev-supervisor.mjs, used by `flame dev` only when a sibling package is linked from the workspace, starts a fresh server. FLAME_DEV_SUPERVISE=0/1 opts out or forces it. - The HMR client now waits for the server to answer before reloading once, instead of reloading after a fixed 2 seconds. - Library packages get `dev: vite build --watch --emptyOutDir=false` (keeps tsc declarations in dist; ui-react aligned), turbo dev depends on ^build, root `pnpm dev` runs flame with its dependencies, and flame's own dev script goes through the CLI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2f2ea88 to
40be040
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the delta since the prior review at 895839c (force-pushed into the same single commit, now 40be040, which is the same content rebased onto main): the fix for the dead dist/ watcher and its regression test.
- Re-attached the
dist/watcher on removal/recreation —watchWorkspacePackages()keeps the recursive watcher in a per-packagedistWatcher;attachDist()closes and re-opens it when the root watcher reportsdist(and on a watchererror), swallowing awatch()throw ifdist/vanished again. The root watcher now closes itself onerrorinstead of crashing the process, andwatchersbecame aSetso re-attached watchers are still closed by the stop function. - Added the remove-and-recreate regression test —
rm -rf dist→ identical rewrite → no change reported; a real change afterwards → one change.
Verified under Node 24: dev-watch.test.ts passed 5/5 runs, dev-supervisor + server-routing tests pass, tsc --noEmit and oxlint are clean. A direct fs.watch probe confirms the design assumptions: writes inside dist/ emit nothing on the non-recursive root watcher (so attachDist() does not churn during normal vite build --watch rebuilds), while rm -rf dist and mkdir dist each surface as exactly one rename:dist there — which is the event the re-attach keys on. The prior review thread is resolved.
claude-fable-5-1 | 𝕏
There was a problem hiding this comment.
✅ Pullfrog addressed all of its review feedback on this PR.
No code changes were needed. The single thread in review 5652982979 (the dist/ watcher dying after rm -rf dist) is already fixed on the PR head 40be040: attachDist() in dev-watch.ts re-attaches the recursive watcher on the package root's dist event and on watcher error, and the "keeps reporting changes after a full rebuild recreates dist/" regression test is present and passing. The thread was already resolved; I left a short reply pointing at the current commit since the previously referenced SHA (2f2ea88) was squashed away.
Verification: npx vitest run .docu/__tests__/dev-watch.test.ts — 8 passed, 1 failed. The failure is resolves flame's sibling packages in this monorepo, which needs the sibling packages' dist/ built (not built in this shell) and is unrelated to the review thread.
claude-fable-5-1 | 𝕏

Summary
flame devwas meant to pick up changes to sibling packages (@docubook/markdownand others) while it runs. That never worked. This PR makes it work end to end: rebuild a workspace package and the dev server restarts by itself, so server rendering and the browser bundle load the new code together. Open pages reload once the server answers again.Projects that install flame from npm are unaffected: they keep a single-process dev server.
Why the old watcher never worked
The watcher was added in #347 (
resolveMdxContentSrc()inserver.tsandserver.impl.ts) and had three problems:require.resolve("@docubook/markdown/package.json"), which throwsERR_PACKAGE_PATH_NOT_EXPORTED, because markdown'sexportslists only.and./styles.css.markdown/src, but flame imports the package fromdist/(exports["."]). Rebuilding flame's client bundle after asrcedit therefore changed nothing.mdx.ts) keeps the modules it imported at startup. A client-only rebuild would have mixed old SSR HTML with a new client, causing hydration mismatches.What this PR does
1. Restart on rebuild:
.docu/node/dev-watch.tsandbin/dev-supervisor.mjsresolveWorkspacePackages()resolves@docubook/core,markdown,ui-reactandthemes-colorsfrom their main entry, so nopackage.jsonexport is needed. It walks up to the package root and skips installed copies undernode_modules.watchWorkspacePackages()watches each package'sdist/(recursively) and its rootstyles.css. After a 400 ms quiet period it compares a content fingerprint (SHA-256 over the built JS/CSS):vite build --watchstarting up, and a whitespace-only source edit, cause no restart)dist/(entry missing) is retried later rather than triggering a restartserver.tsfor Bun,server.impl.tsfor Node/Deno) exit with code 75.flame devruns the server underbin/dev-supervisor.mjs, which respawns it on code 75, forwards SIGINT/SIGTERM, and never restarts after a stop signal. The supervisor is only enabled when a sibling package is linked from the workspace.FLAME_DEV_SUPERVISE=0opts out (it then logs "restartflame devto load it"), and=1forces the supervisor on.2. HMR reconnect
Previously the browser reloaded 2 s after the HMR connection dropped, whether or not the server was back. A restart that takes longer (a cold client build here took up to 13 s) left the page on a connection error. The client now polls
HEADwith backoff (250 ms up to 2 s) and reloads once the server answers.3. Workspace wiring
core,markdown,themes-colors: newdevscript,vite build --watch --emptyOutDir=false.ui-react: its existingvite build --watchgains--emptyOutDir=false. A plain watch build emptiesdist/and deletes thetscdeclarations, which broke flame's typecheck while dev was running (reproduced here).turbo.json:devnow depends on^build.pnpm dev:turbo dev --filter=@docubook/flame....devscript:bun bin/cli.js dev(through the CLI, so the supervisor applies) instead ofbun .docu/node/server.ts.CONTRIBUTING.mdandARCHITECTURE.mddocument the workflow.Verification
End-to-end, real processes, on Node and on Bun. Supervised
flame dev, markdown'svite build --watch, and a Chromium page kept open throughout:flame devstarts supervised; the child getsFLAME_DEV_SUPERVISED=1vite build --watchinitial build (identical output)TabsMdx.tsx(identical output)data-dev-probeattribute on the Tabs rootflame devThe temporary edit was reverted, and
git diffonpackages/markdown/srcis empty afterwards.FLAME_DEV_SUPERVISE=0: no child process, and on a rebuild it logs the hint instead of restarting.pnpm dev: builds the four dependencies, starts four watchers plus flame, and serves 200, with 0 restarts during startup.@docubook/flame: 33 files, 666 tests passed (14 new).tsc --noEmitreports 0 errors, and lint and prettier pass.dev-watch.test.ts: workspace vs installed resolution, fingerprint (identical, changed, mid-rebuild,styles.css), the watcher (one callback per real change, none for identical or half-written output), and the constants contract with the supervisor. Ran 10 times, 0 flakes.dev-supervisor.test.ts: respawn on 75, the supervised env flag, passthrough of other exit codes, no restart after SIGTERM (fails without the!stoppingguard), and workspace detection.server-routing.test.ts: the HMR client runs against a fake EventSource, fetch and timers. It reloads exactly once, only after the server answers, and fails against the old script.pnpm test:release-planpassed (6 scenarios).deno run -A <entry>for it, and CI's Deno job only builds.Review follow-up (pullfrog)
Correct.
fs.watchis bound to the directory it was opened on. Thebuild/cleanscripts ofcore,markdownandthemes-colorsrunrm -rf dist, so a full rebuild of a sibling with identical output (no restart) left a dead watcher, and later real rebuilds never restarted the server. My first end-to-end check missed this becausevite build --watchkeeps thedist/directory.Fixed in this PR's single commit (the follow-up was squashed in). The package-root watcher already sees
distbeing removed or created, and now re-attaches thedist/watcher at that point (and on a watcher error). A new test removes and recreatesdist/with identical output (no change reported), then writes a real change (reported). It fails without the re-attach and passed 10 of 10 runs.End to end on Node: with supervised
flame devrunning,pnpm --filter @docubook/markdown build(rm -rf dist, identical output) caused 0 restarts, and the following real change throughvite build --watchcaused 1 restart with SSR and client both updated.Notes for reviewers
pnpm exec/pnpm run,NODE_PATHpoints at the workspace store, so resolution falls back there. For an installed project that store is its ownnode_modules, so detection still says "installed". One test fixture had to account for this.themes-colorsalso exports passthroughthemes/*andsyntax/*files outsidedist/. Edits to those are not watched; onlydist/andstyles.cssare.bin/dev-supervisor.mjs, which the CLI loads as plain JS, anddev-watch.ts. A test asserts that they match.Changeset
@docubook/flame: patch. The library packages only gaindevscripts, so they need no changeset.🤖 Generated with Claude Code