Skip to content

fix: stop repeated preview refreshes during rapid edits - #5612

Merged
0hmX merged 2 commits into
tscircuit:mainfrom
0hmX:fix/coalesce-dev-updates-20261027
Oct 28, 2026
Merged

0hmX merged 2 commits into
tscircuit:mainfrom
0hmX:fix/coalesce-dev-updates-20261027

Conversation

@0hmX

@0hmX 0hmX commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

0hmx@dots

Rapid filesystem saves currently trigger an immediate file-server upload for every watcher event. This can rebuild the browser preview repeatedly, echo browser-originated writes back to the server, and leave concurrent uploads in flight.

Coalesce saves with a 250 ms trailing debounce and a 1 s maximum wait. Sync one batch at a time, reading current file contents when processing it and retaining edits received during an upload. Keep Chokidar's 100 ms atomic-save normalization explicit, suppress unchanged-content uploads (including browser writeback), and drain active work before shutting down the HTTP server. New local dependencies are uploaded before their importing source.

The delay is an interaction tradeoff, not a universal standard: Chokidar documents atomic saves, webpack documents aggregating saves before rebuilding, and Lodash documents trailing debounce with maxWait. A bounded batch avoids the indefinite postponement that an unbounded quiet-period wait can cause during continuous edits.

Validation on macOS with Bun 1.3.14:

  • New native TSX watcher tests cover single saves, a five-save burst, continuous editing, atomic rename saves, identical-content saves, ignored generated cache output, deletion, and disposal. Queue tests cover in-flight edits, errors/recovery, and cancellation. Additional regressions verify exact binary-byte comparison and browser text/binary writeback without duplicate uploads.
  • The burst regression fails on the original code: five saves produced five uploads; the patch produces one and retains the final source.
  • After review fixes, all 8 coalescing tests pass and the complete dev-server test group passes 31/31.
  • Repository formatting, TypeScript check, and CLI build pass.
  • ChatGPT in-app browser: five rapid fixture saves changed four uploads/two completed runs to one upload/one completed run when combined with the companion runframe fix. The selected view survived, syntax errors remained visible, and an atomic save recovered to the latest value. No document reload occurred during saves.

The companion runframe PR #5927 handles active/pending render scheduling and keeps the previous completed preview visible. This CLI change also works with existing runframe versions. The full CLI command suite was not run locally; all five hosted Linux test shards, Windows tests, smoke init, formatting, types, dependency policy, and dependency ownership checks passed on 3c8cc4672f36ec12787655433edd3db0f76f5114. No board-design changes are included.

Each PR can be reviewed independently. The combined behavior reaches standard CLI installations after the runframe fix is released and incorporated into the standalone browser bundle distributed with tscircuit; both changes are already active together in the tested local installation.

Review feedback addressed in 3c8cc46: store cached contents consistently as byte buffers, removing the new typeof/Buffer.isBuffer guard, and split every added coalescing test into a separate file with shared fixture setup.

@0hmX
0hmX marked this pull request as ready for review October 27, 2026 18:41
@0hmX
0hmX marked this pull request as draft October 27, 2026 18:41
@0hmX
0hmX marked this pull request as ready for review October 27, 2026 18:45
Comment thread lib/dev/DevServer.ts Resolved
@0hmX 0hmX changed the title fix: coalesce rapid saves in the dev server fix: stop repeated preview refreshes during rapid edits Oct 28, 2026
@0hmX
0hmX merged commit c8892c1 into tscircuit:main Oct 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants