fix(compiler): fix file watcher sometimes doesn't trigger rebuild#6191
Merged
christian-bromann merged 2 commits intostenciljs:mainfrom Mar 11, 2025
Merged
fix(compiler): fix file watcher sometimes doesn't trigger rebuild#6191christian-bromann merged 2 commits intostenciljs:mainfrom
christian-bromann merged 2 commits intostenciljs:mainfrom
Conversation
The existing implementation was running into the `lastTsBuilder && !timeoutId` condition with a `timeoutId` 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: - remove the extra `rebuildTimer` which was arguably confusing - remove the clearTimeout override Since we immediately call `clearTimeout(timeoutId)` in the `setTimeout` override, we don't stack up rebuild requests. After applying these changes the watcher behaves beautifully. fixes: stenciljs#6190
Contributor
Author
|
@christian-bromann Sorry about the formatting error — overlooked the prettier scripts. I fixed it in f977746 using |
Member
No worries at all, happens to me all the time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/corebuild 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 testand 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.excludeFilestsconfig.jsonoption did not work.The existing implementation was running into the
lastTsBuilder && !timeoutIdcondition with atimeoutIdbeing 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
setTimeoutto wait for pending builds.This allows to:
rebuildTimerwhich was arguably confusingSince we immediately call
clearTimeout(timeoutId)in thesetTimeoutoverride, we don't stack up rebuild requests.