Repository navigation
fix(nitro): attach the definitions watcher before scanning - #424
Merged
Merged
Conversation
fs/promises watch() attaches nothing until the first next(), so a directory or file created between the root check (or the initial scan) and the start of iteration reported no event, and development servers never rebuilt for it.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Thank you for following the naming conventions! 🙏 |
commit: |
This branch was successfully deployed
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.
Port of #423 to the stable 0.x line. The Nitro definitions watcher could miss a directory created after the dev server started, so nothing rebuilt and new tools stayed invisible until a restart.
watch()fromnode:fs/promisesreturns an async generator, and the OS watch is only attached on the firstnext(). The watcher readwatchableRoot()(or ran its initial scan) and only then started iterating, so anything created in between produced no event.mkdir -p server/mcp/toolscreates each level milliseconds apart while the watcher follows it down one level per event, so it regularly lands in that gap; this is what madesees a definitions directory that did not exist yetflaky on the v1 stack. The watcher now requestsnext()first and checks or scans afterwards. Each round gets its ownAbortController, so leaving an ancestor closes its watch and settles the pending request.To try the PR build in a Nitro app, install it and add a definitions folder while
nitro devruns:To run the watcher tests from this branch:
Before and after
The race depends on scheduling, so both sides get the same one-line fault injection in a throwaway worktree: one extra event-loop turn between reading the root and attaching the watch.
Before (
30cd17d, main):After (
5d32ac9):The code matches #423 except for one detail: on main an ancestor watch only re-checked the root on
renameevents, and it now re-checks on every event, as the v1 branch already does.AbortSignal.anyneeds Node 20.3; the package declares>=20, whilenitroitself already requires 20.19. There is no deterministic regression test, because the gap can't be forced through the public API, so the existing test stays the guard. Windows is covered only by this PR's CI run.ELI5
The dev server watches a folder so it notices when you add a new tool file. It used to look at the folder first and only then start listening, so a folder created in that split second went unnoticed. Now it starts listening first and looks second.