Skip to content
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

Add option to use polling instead of filesystem events when watching for filesystem changes #2793

Closed
qwerty01 opened this issue Nov 13, 2021 · 2 comments · Fixed by #3138
Closed
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.

Comments

@qwerty01
Copy link

qwerty01 commented Nov 13, 2021

Describe the problem

Currently sveltekit uses cheap-watch to detect when files have changed while running the dev server (https://github.com/sveltejs/kit/blob/master/packages/kit/src/core/dev/index.js#L76). cheap-watch makes use of fs.watch, which uses a system-specific event callback when a file changes.

Unfortunately, when listening for events on a network drive (such as when using docker with a mapped folder), no events are emitted when files are changed. Other similar tools have an option to use filesystem polling instead of event callbacks, such as chokidar: https://github.com/paulmillr/chokidar#performance:

usePolling (default: false). Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU utilization, consider setting this to false. It is typically necessary to set this to true to successfully watch files over a network

Describe the proposed solution

I believe the most flexible solution would be to switch to a different filesystem watcher that supports polling as well as filesystem events (such as chokidar). Configuring the module could then be achieved through the svelte.config.js file and a link directly to the module's documentation can be added to the current documentation for configuring watch settings.

Alternatives considered

Another option could be to use a secondary module for polling the filesystem and have a config option in svelte.config.js to either use polling or filesystem events.

Importance

would make my life easier

Additional Information

The current use case for me is to enable developing in docker. Currently, filesystem watching doesn't work at all due to network shares not triggering filesystem events, so HMR does not work. Everything works when running locally so it's not a showstopper, but it would be nice to have support for dockerized development environments.

@bluwy bluwy added feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. labels Nov 13, 2021
@bluwy
Copy link
Member

bluwy commented Nov 13, 2021

One possible solution is to use Vite's file watcher from the dev server as well, which uses chokidar. I'm not sure how that would affect HMR, but it may be doable.

@Rich-Harris
Copy link
Member

in #3138 we switched to using Vite's chokidar instance, so you can configure the watcher via the Vite config: https://vitejs.dev/config/#server-watch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants