Skip to content

Watch-mode does not work in a specific situation #642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
konekotech opened this issue Jan 25, 2025 · 8 comments
Closed

Watch-mode does not work in a specific situation #642

konekotech opened this issue Jan 25, 2025 · 8 comments
Labels
upstream Caused in upstream, not in this repo

Comments

@konekotech
Copy link

konekotech commented Jan 25, 2025

Version of Marp Tool

Marp CLI v4.1.1

Operating System

macOS

Environment

  • OS version: macOS Sequoia 15.2
  • Node.js version: Node.js 22.11.0

How to reproduce

  1. Create a markdown and a CSS file in Vim / NeoVIm (e.g: slide.md and theme.css)
  2. Edit and save
  3. Open another tab in the terminal, and run marp ./slide.md --theme ./theme.css --preview
  4. Edit markdown file again, and save

Expected behavior

Saving will be reflected on the preview window.

Actual behavior

Saving is not reflected on the preview window. It does not change.

Additional information

When I tried this in VS Code terminal (using Marp-CLI, not VSCode extention one), the saving was reflected on preview window.
However, when I use another terminals such as WezTerm and iTerm2, this issue occured.

@konekotech konekotech changed the title Watching does not work in a specific situation Watch-mode does not work in a specific situation Jan 25, 2025
@yhatt
Copy link
Member

yhatt commented Jan 25, 2025

I have tried to reproduce on iTerm2, and I met only first once that the file change event was not fired. When tried the exactly same operation after logged out from macOS, I've confirmed that the file change event is correctly tracking in all of 4-5 times try. Probably it would mean that the difference of using terminal emulator is not root cause of that issue.

Some issues about watching file system has been reported before, but any issue was not resolved clearly.

@yhatt yhatt added the help wanted Extra attention is needed label Feb 21, 2025
@konekotech
Copy link
Author

Dear yhatt,

I read issues you showed me, and it looks that watch-mode does not work with custom css without VS Code.

I use this marp environment in usual.

https://github.com/konekotech/marp-env-public

When I remove - --theme ./.styles/$THEME.css in package.json in this environment, the watch-mode worked with my neovim environment.

@yhatt
Copy link
Member

yhatt commented Mar 12, 2025

The latest Marp CLI v4.1.2, with --debug="marp-cli:watcher" option, has become to able to track the chokidar's event, and inspect what the kind of the file event was fired while the watch mode. If it is still reproducible, try --debug="marp-cli:watcher" option for tracking the event from chokidar.

@polarnik

This comment has been minimized.

@yhatt

This comment has been minimized.

@konekotech
Copy link
Author

I tried running --debug="marp-cli:watcher", and here’s what I found:

With VSCode

When the file changes, the log outputs the following, and the preview updates correctly:

  marp-cli:watcher Chokidar event: [change] slide.md +10s
[  INFO ] slide.md => slide.html

With Wezterm (Neovim)

When the file changes, the log outputs the following, but the preview does not update:

  marp-cli:watcher Chokidar event: [unlink] slide.md +14s

@konekotech
Copy link
Author

I added set backupcopy = "yes" in my neovim settings, and it works correctly even with NeoVim!!!!!

The issue occurs because Neovim saves files by creating a temporary file, deleting the original (unlink event), and then renaming the temp file, whereas VSCode directly modifies the file (change event). This behavior is controlled by the backupcopy setting in Neovim.

Setting backupcopy=yes forces Neovim to overwrite the file directly, preventing the unlink event.

@yhatt
Copy link
Member

yhatt commented Apr 2, 2025

That behavior has been called "Atomic write" and provided by Vim and Vim-based editors.

chokidar should be already handling that case by default, by detecting the set of unlink event and add event, and transforming the event into change. At least my Neovim in my Mac will trigger change event correctly even if backupcopy has been set as no or auto.
https://github.com/paulmillr/chokidar?tab=readme-ov-file#errors:~:text=be%20suppressed%20silently.-,atomic,-(default%3A%20true

According to the behavior you've described, the second action for the atomic save in your editor was simply renaming the backup file. Probably it could not detect this change as the add event by chokidar.

The documentation of Neovim is already mentioned to problem of file watchers, to consider switching the backupcopy option value to yes.

@yhatt yhatt added upstream Caused in upstream, not in this repo and removed help wanted Extra attention is needed labels Apr 2, 2025
@yhatt yhatt closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Caused in upstream, not in this repo
Projects
None yet
Development

No branches or pull requests

3 participants