Skip to content

Commit 7a878aa

Browse files
authored
docs: document --watch-hmr and atomic-save caveat (#3186)
1 parent e669494 commit 7a878aa

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

runtime/getting_started/command_line_interface.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ from expanding the glob:
127127
deno run --watch --watch-exclude='*.js' main.ts
128128
```
129129

130+
### Hot module replacement
131+
132+
`deno run` also supports the `--watch-hmr` flag, which hot-replaces changed
133+
modules in the running process instead of restarting it. This keeps your
134+
application's state across edits. If hot replacement fails, the process falls
135+
back to a full restart.
136+
137+
```shell
138+
deno run --watch-hmr main.ts
139+
```
140+
141+
#### Editors with atomic save
142+
143+
Some editors use "atomic save" (also called safe write), where the editor writes
144+
your changes to a temporary file and then renames it over the original on each
145+
save. On Linux this replaces the file with a new one on disk, which can detach
146+
the file watcher used by `--watch-hmr` after the first change. The symptom is
147+
that hot replacement works once and then stops detecting further edits to that
148+
module.
149+
150+
If you hit this, disable atomic save in your editor:
151+
152+
- **Helix**: set `[editor] atomic-save = false` (it is enabled by default).
153+
- **Neovim/Vim**: set `:set backupcopy=yes`.
154+
155+
Plain `--watch` is not affected, because each change triggers a full restart
156+
that re-establishes the watchers.
157+
130158
## Where to go next
131159

132160
For deeper coverage of the topics this page only hints at:

0 commit comments

Comments
 (0)