Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Fix javascript live preview for linux #528

Merged
merged 4 commits into from
Sep 6, 2019

Conversation

gabbifish
Copy link
Contributor

@gabbifish gabbifish commented Sep 6, 2019

Closes #517.

This was a fun one to investigate. The bug, at its core, was the fact that different editors have different approaches to saving files--some, like vim, actually delete and re-create an entire file when saving its contents. Different file notification APIs across different operating systems track changes to files differently; in the case of the Linux file watcher in the notify crate (inotify) this watcher will stop watching a file once it has been deleted; vim deletes files regularly when saving new contents (https://unix.stackexchange.com/questions/188873/using-inotifywait-along-with-vim).

I wasn't familiar with the live preview code, so I spent time reading through it. Ultimately I couldn't find any bugs that could cause the behavior I observed. Something we noticed was that webpack workers watch directories and worked just fine with vim, implying that watching a directory for javascript workers would also work (inotify would continue to watch the index.js file even if vim deleted and re-created it).

This PR may also need to be replicated for #522, given that the Rust live preview service also watches an individual javascript file.

This PR also reduces noisy output by the live preview service. Notifying over directories produced a large amount of repeated "Detected change during cooldown..." terminal output.

…ng an entire directory produces a lot of 'Cooldown' text)
@gabbifish gabbifish added regression Something is broken, but works in previous releases status - needs review labels Sep 6, 2019
@gabbifish gabbifish added this to the 1.3.0 milestone Sep 6, 2019
@gabbifish gabbifish merged commit 9dca091 into master Sep 6, 2019
@delete-merged-branch delete-merged-branch bot deleted the gabbi/fix-linux-live-preview branch September 6, 2019 19:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
regression Something is broken, but works in previous releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrangler preview --watch only detects the first change (on Linux)
4 participants