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

add options in chokidar to use polling #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chiefjester
Copy link

- fixes sveltejs#109 
- chokidar is a transitive dependency of livereload, so passing an option to chokidar is relatively safe
- the fix was inspired by rollup/rollup#1666 (comment)
- tested on both macOS and Ubuntu 19 (via WSL2)
@frederikhors
Copy link
Contributor

Already discussed before about chokidar.

@chiefjester
Copy link
Author

@frederikhors, can you give me more context? Can you give me a link on where it was discussed?

@Conduitry
Copy link
Member

Chokidar being the source of problems came up in #29 and #77. I don't think forcing everyone to use polling is the correct solution when there are comparatively so few systems that experience this, and polling is more resource intensive than listening for filesystem events. A note in the readme might be nice though.

@chiefjester
Copy link
Author

@Conduitry hey 👋🏻. Thank you for jumping in. The main problem is actually coming from rollup

There's also a 3-year-old issue that keeps creeping back in.

It defaults to native fs.watch which is problematic to other file systems, as taken from Node's documentation:

Caveats#
The fs.watch API is not 100% consistent across platforms and is unavailable in some situations.

The recursive option is only supported on macOS and Windows.

While we can fix this in the rollup layer, the issue was closed just by adding a configuration. This repo is a template starter for developers new to Svelte. It's going to be a problem for people switching to Windows now that WSL2 is pretty stable, and is about to go GA. Their first experience would leave a bad taste having a non-working live-reload from the get-go.

Would you be open to adding a different file watcher like your library cheap-watch that'll handle file watching across different environments? I believe sapper has already adopted this.

My goal here is to have a good out of the box experience to developers discovering Svelte. I don't think adding a README would cut it. DMing you in Discord as well.

@ghost
Copy link

ghost commented Oct 11, 2020

I would ask for this problem to be tackled as well. I fixed it now using the solution proposed here, using WSL2 on Windows 10 as well.

I don't know what's causing the problem, but I agree with @thisguychris, this problem makes it really unattractive for new devs that are just getting into Svelte if the template is not working, especially since no one has the time to wait for a complete rebuild every time they change a few characters or CSS colors. In practice, Live Reload is an indispensable feature, IMO. And it just sucks if it doesn't work out of the box, at least for WSL2 users, it seems.

@antony
Copy link
Member

antony commented Nov 25, 2020

Is there a reliable way to detect a system for which this is necessary?

@Conduitry
Copy link
Member

It's a known bug in WSL2 that watch events don't fire for changes to files on the host (Windows) filesystem. I don't think the default template should cater to that. As far as I know, the suggested workaround for the time being (and what I have been doing since updating from WSL1 to WSL2, to good success), is to have the project and files you're watching live inside the WSL environment, and not on the Windows filesystem.

@antony
Copy link
Member

antony commented Jan 6, 2021

Can I propose that we close this PR based on the comments from @Conduitry above?

@chiefjester
Copy link
Author

Hi, @Conduitry 👋, Sorry for the confusion. This bug is also prevalent on a Linux machine.

It's a known bug in WSL2 that watch events don't fire for changes to files on the host (Windows) filesystem.

I think you mistook WSL with WSL2, and if you are sure it's WSL2, then I didn't test using the Windows File system. My project is in the Linux filesystem, so non of the possible bug you mention applies here.

I tested and replicated the bug in Ubuntu Machine, not just WSL2.

Also, as per Node docs.

The fs.watch API is not 100% consistent across platforms and is unavailable in some situations.

And that's the reason why I was trying to DM you last year (though I never got a reply) 😢 . So maybe we can brainstorm. I was about to propose to replace chokidar altogether with something you wrote, which is already being used in rollup.

@antony, no problem closing on my side. it's still a bug though 😞

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stops watching files after first change
4 participants