-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[Feature] Automatically detect safe-write #221
Comments
I was able to reproduce this on Mac OS as well. However, the problem goes away when I remove |
That's weird. I just tried without |
Can you commit the new code (the code without |
I'd just changed the code in the example repo to remove |
I can't seem to reproduce this in any way |
I've done some poking around, and it seems like chokidar isn't firing diff --git a/src/Bundler.js b/src/Bundler.js
index bb21004..cd0cf1f 100644
--- a/src/Bundler.js
+++ b/src/Bundler.js
@@ -176,7 +176,8 @@ class Bundler extends EventEmitter {
// FS events on macOS are flakey in the tests, which write lots of files very quickly
// See https://github.com/paulmillr/chokidar/issues/612
this.watcher = new FSWatcher({
- useFsEvents: process.env.NODE_ENV !== 'test'
+ useFsEvents: process.env.NODE_ENV !== 'test',
+ usePolling: true
});
this.watcher.on('change', this.onChange.bind(this)); |
I've found the problem. It has to do with the way many text editors write files, and is actually addressed by the webpack documentation: https://webpack.github.io/docs/webpack-dev-server.html#working-with-editors-ides-supporting-safe-write. To quote:
I suppose the reason I'd never had this problem before is because I'd always configured webpack to watch the directory instead of individual files. This means this isn't really a parcel bug, but it is likely an issue that other people will face as well (I've tried editing the file with IntelliJ IDEA, vim and gedit, and they all behaved the same), so it might be worth adding an extra recursive watcher for e.g. the root directory so you can receive events for these 'new' files and rebuild. |
Wow thanks for hunting this down! I would have never figured that out. Do you guys think we should add a warning about this in the documentation? |
We should maybe add an option to the cli to enable polling for the people who have this activated in their IDE? (because this isn't really an option as standard for performance reasons) |
Personally, I think watching the directory would solve it completely (though I could be wrong), but in the meantime adding a warning and a cli flag for usePolling seem like good options to me. |
isn't use polling poking the files every now and then, you might be right though? |
Is there a way to detect “safe write”? Maybe we can dynamically fallback to polling when we detect it. |
When you look at the raw fs events from chokidar, at least on Linux, on a safe-written file change you get a |
|
Here using VSCode the same behavior happen, VSCode + OS X High Sierra, HRM only works once. |
This is an IDE related issue @juniovitorino turn off safe-write and it should work |
I'm also having problems with safe-write when using Visual Studio 2017 combined with From what I can tell the safe-write process in Visual Studio looks like this when saving a file (
@DeMoorJasper @kasbah maybe this will break the test: const temp = __dirname + '/input/5jrvappx.wht~';
const file = __dirname + '/input/local.js';
const backup = __dirname + '/input/local.js~RF46beda4b.TMP';
function simulateSafewrite(content) {
fs.writeFileSync(temp, content);
fs.renameSync(file, backup);
fs.renameSync(temp, file);
fs.unlinkSync(backup);
} |
I would also add that coming from Meteor which works well with editors which use safe write, this seems like something which should be fixable and it should not require disabling safe write, which is at most a workaround and cannot be seen as simply a solution. |
See here relevant code in Meteor. |
Some related issues:
It seems So it seems we should try to fix |
I think I fixed this. If you want to test it, just install See paulmillr/chokidar#791 for more details. |
@mitar awesome work, hope it'll get merged into chokidar 🎉 |
Strange. It works great for me for PyCharm. Make sure you really use that forked version and that it So I added to my "devDependencies": {
"chokidar": "git://github.com/mitar/chokidar.git"
} And it works then. |
I have copied your entry verbatim.
Still, hot reload works only on the first edit in neovim. Afterwards it is broken. |
Sorry. Not sure why there was that Markdown in JSON. I edited my comment before accordingly. |
Ah right. Still, I have fixed this, removed |
I have installed chokidar-cli, which I presume uses the version from your repo, and running |
My PR has been merged into upstream |
Should be fixed in Chokidar, closing this issue. Feel free to open a new issue if this persists. (Do note that this fix has not been released yet and might take some time before your node_modules are up to date with the chokidar fix.) |
Shouldn't then this issue be closed once Also, before closing this issue, documentation for parcel should be updated to not advise anymore to disable safe write. |
chokidar reverted @mitar's workaround because it broke another tool and this is broken again. My setup:
Writing a tiny chokidar script shows that chokidar isn't seeing the changes when it's watching particular files: const chokidar = require('chokidar')
chokidar.watch('src/content.ts').on('change', console.log) Chokidar sees the first change to the file, but not the second and subsequent. Watching the directory instead fixes this. I think parcel should watch the whole directory and filter names on linux. This gives a quick fix that won't break any other tools. |
Obviously another fix would be to just pin chokidar at 2.1.3 or 2.1.4 for now. I'm doing that locally with: // package.json
"resolutions": {
"parcel/**/chokidar": "2.1.3"
} Which is a yarn feature: https://yarnpkg.com/en/docs/selective-version-resolutions |
This fixed it for me, many thanks. |
How and from where to remove it? |
How to do this in VS Code? |
Should this issue be reopened since the fix in chokidar was reverted? |
🐛 Bug report
While the parcel dev server or the watcher is running, changes in a file are sent to the browser correctly, but only the first time I save changes in the file. The second time, parcel doesn't rebuild (there is no console output) and the module doesn't reload in the browser. Other files will still reload, but also only once.
Even when refreshing in the browser, the changes aren't shown. I have to restart parcel for it to show the latest changes again.
Reproduction
Here's a minimal sample that shows the problem for me: https://github.com/Edootjuh/parcelrepro
To reproduce:
parcel index.html
http://localhost:1234
in browser. The page showsa b
The same happens with
parcel watch index.html
🌍 Your Environment
The text was updated successfully, but these errors were encountered: