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

Component css gets reloaded with css-loader on any file change #131

Closed
non25 opened this issue Sep 8, 2020 · 0 comments · Fixed by #151
Closed

Component css gets reloaded with css-loader on any file change #131

non25 opened this issue Sep 8, 2020 · 0 comments · Fixed by #151

Comments

@non25
Copy link
Contributor

non25 commented Sep 8, 2020

Hi dear devs and contributors.

I've noticed this behavior trying to reduce watch mode reload times when using tailwind+postcss through svelte-preprocess by monitoring with speed monitoring webpack plugin.

On any non-component change in the project with 20 components that uses in-component css there's 40 seconds of wait due to reloading of all Component.svelte.css in _virtualFiles.

I've been messing around with virtual.js for some hours trying to fix this.

Tried to pass fs.statSync(this.resourcePath)'s to use with virtual css file. Though that non-authentic VirtualFileStats triggered watcher to reload. Didn't work.

console.logged contents of _statStorage, _readFileStorage, _virtualFiles in compiler.inputFileSystem.purge and compiler.inputFileSystem._writeVirtualFile.
It appears that original purge doesn't clear any of that containers, commenting it's code doesn't change anything.
compiler.inputFileSystem.purge does trigger on any change.

var originalPurge = compiler.inputFileSystem.purge;
compiler.inputFileSystem.purge = function() {
if (originalPurge) {
originalPurge.call(this, arguments);
}
if (this._virtualFiles) {
Object.keys(this._virtualFiles).forEach(
function(file) {
var data = this._virtualFiles[file];
setData(this._statStorage, file, [null, data.stats]);
setData(this._readFileStorage, file, [null, data.contents]);
}.bind(this)
);
}
};

While we at it, what is the purpose of this?

const watchRunHook = (watcher, callback) => {
this._watcher = watcher.compiler || watcher;
callback();
};
if (compiler.hooks) {
compiler.hooks.watchRun.tapAsync('VirtualModulesPlugin', watchRunHook);
} else {
compiler.plugin('watch-run', watchRunHook);
}

Also there's an issue with similar task and problem, where author solved it by decorating NodeWatchFileSystem.
webpack/webpack#5824
Don't know if that is a good idea...

The main question is why watcher reloads virtual css files when they weren't changed...
Would like to get some insight into this.

non25 added a commit to non25/svelte-loader that referenced this issue Jan 13, 2021
Fixes sveltejs#139, Fixes sveltejs#131, Fixes sveltejs#126

Co-authored-by: Smittyvb <me@smitop.com>
non25 added a commit to non25/svelte-loader that referenced this issue Jan 13, 2021
Fixes sveltejs#139, Fixes sveltejs#131, Fixes sveltejs#126

Co-authored-by: Smittyvb <me@smitop.com>
non25 added a commit to non25/svelte-loader that referenced this issue Jan 13, 2021
Fixes sveltejs#139, Fixes sveltejs#131, Fixes sveltejs#126

Co-authored-by: Smittyvb <me@smitop.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant