fix(compiler): fix file watcher sometimes doesn't trigger rebuild #6191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the current behavior?
GitHub Issue Number: #6190
The file watcher sometimes fails to trigger a rebuild:
This is caused by the "Back up files before saving" option in my editor.
When this option is disabled the file watcher works just fine.
However, the "Back up files before saving" option is enabled per default and Stencil should be able to handle this.
What is the new behavior?
After applying these changes the watcher behaves beautifully with or without "Back up files before saving" option enabled.
Documentation
–
Does this introduce a breaking change?
Testing
I tested the code with a custom
@stencil/core
build in my application runningstencil build --watch --verbose
. I also made sure that the issue is not specific to my project. I installed a clean Stencil project and repeated my tests with and without the "Back up files before saving" option.I ran the test suite via
npm run test
and made sure tests are still passing. I did not add any new tests.Other information
Ignoring backup files via
watchIgnoredRegex: [/\.\w+~$/]
or using"**/*.*~"
on thewatchOptions.excludeFiles
tsconfig.json
option did not work.The existing implementation was running into the
lastTsBuilder && !timeoutId
condition with atimeoutId
being present even though there was no running build or any other good reason not to rebuild.The change simplifies the implementation by using a recursive
setTimeout
to wait for pending builds.This allows to:
rebuildTimer
which was arguably confusingSince we immediately call
clearTimeout(timeoutId)
in thesetTimeout
override, we don't stack up rebuild requests.