Watch mode causes all marp output files to refresh
Repro: I run the CLI marp command to compile with the --w flag Result: All open html files generated by marp will continuously refresh. Problem created: This drains memory and also makes it difficult to look at other files.
Request: Is it possible for the watch mode to only refresh marp output files it is being run in? Additional Suggestion: It might be a good idea to have a timeout for watch mode - so that it terminates after say, ten minutes of no activity in the watched file.
Thank you for the work you do!
Result: All open html files generated by marp will continuously refresh.
Marp CLI's --watch follows the conventions of common front-end build tools to automatically refresh the browser that is opening result HTML converted from targeted Markdowns when it changes.
Even if you're watching multiple Marp Markdowns, conversion and refresh are supposed to work only in the output HTML of a changed Markdown.
Request: Is it possible for the watch mode to only refresh marp output files it is being run in?
I don't know the actual command to run Marp CLI you're using, but Marp CLI already should watch and refresh only specified Markdowns to run.
marp --watch ./foo.md ./bar.md
In this case, Marp CLI will watch only the change of foo.md and bar.md. For example, even if co-located ./non-target.md on the same directory was changed, conversion and refresh are not supposed to trigger by Marp CLI.
If you still feel Marp CLI runs something unexpected, please share more specific steps to reproduce it with minimal examples: A command you're actually running, the expected behavior, actual behavior, the structure of project directory, and more to reproduce. (Recommend to use a bug report form)
Apologies for the delay in my reply. I have copied the template and added the details below.
Version of Marp Tool: @marp-team/marp-cli v4.0.3 (w/ @marp-team/marp-core v4.0.0) Operating System: Windows Environment
- OS version: Windows 10 Home Version 2009, OS Build 19045.5854
- Node.js version: v22.11.0
File directory: Root ├───Year 10 │ ├───Equations and Formulas │ │ └───images │ ├───Measurement and Surds │ │ └───images │ └───Quadratic Expressions and Equations │ └───images └───Year 9 ├───Algebraic Expressions │ └───images └───Indices └───images
Repro
- Run
marp .\indices.md --html --theme .\gradient.css -winYear 9/Indices
Expected behavior
- Only indices.html refreshes
Actual behavior
- Html files from all the other directories refresh too, if they are open in the browser.
- The files don't actually show any changes from their source md files, they are just visibily refreshing approximately every 5 seconds
HTML files generated with the --watch (-w) option enabled will have the script for connecting to Marp CLI watch server injected. This script will try to reconnect to the server every 5 seconds if the HTML file cannot connect when opened.
https://github.com/marp-team/marp-cli/blob/main/src/templates/watch/watch.ts
HTML files with watch mode support will refresh automatically when reconnected, to ensure all changes during the lost connection are reflected. This includes changes to assets used by slides, manual editing, modifications by third-party tools, and removal of files.
Currently we are not detecting whether the HTML is targeted by Marp CLI's watch mode when re-connected, because we have not found the behavior that is efficient, secure, and feels natural for every operation.
For now, if you do not want unexpected refreshes, we recommend to convert not focused slides into HTML without --watch first. That's like distinguishing working Markdown files from completed files.
# Convert all (completed) Markdown files
marp ./root
# Enable watch mode only for active Markdown files
marp ./root/xxx/yyy/zzz.md --watch