fix(dev): skip temporary files in content watcher to prevent crashes#3784
fix(dev): skip temporary files in content watcher to prevent crashes#3784
Conversation
Editors and AI tools that use non-atomic writes (write to temp file, then rename) create intermediate files like `example.md.tmp.153372`. The content watcher picks these up and attempts to parse them, which throws an unhandled rejection because the extension is unsupported, crashing the dev server. Skip files matching common temporary patterns before attempting to parse: *.tmp, *.tmp.*, files ending with ~, and Emacs lock files (.#*). Fixes nuxt#3759
|
Someone is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughA guard clause was added to the Nuxt Content dev watcher's onChange handler to detect and skip temporary and editor backup files before processing. The implementation extracts the file basename and returns early if it matches common temporary file patterns including .tmp, files ending with Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/utils/dev.ts`:
- Line 121: The regex in the if condition that inspects basename uses a
capturing group and only allows numeric .tmp suffixes; replace
/\.tmp(\.\d+)*$|~$|^\.#|^\~/ with a non-capturing, broader pattern like
/\.tmp(?:\..+)*$|~$|^\.#|^~/ so it no longer uses a capturing group and matches
any suffix after .tmp (e.g., .tmp.swp); update the if (/.../.test(basename))
expression in src/utils/dev.ts accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
|
|
||
| // Skip temporary files created by editors and tools during non-atomic writes | ||
| const basename = path.split('/').pop() || '' | ||
| if (/\.tmp(\.\d+)*$|~$|^\.#|^\~/.test(basename)) { |
There was a problem hiding this comment.
Fix temp-file regex to pass CI and match *.tmp.* broadly.
On Line 121, the regex has an unused capturing group (failing ESLint) and currently narrows .tmp.* to numeric suffixes only. That can still let temp files like foo.tmp.swp reach parsing.
Proposed fix
- if (/\.tmp(\.\d+)*$|~$|^\.#|^\~/.test(basename)) {
+ if (/\.tmp(?:\..+)?$|~$|^\.#|^~/.test(basename)) {
return
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (/\.tmp(\.\d+)*$|~$|^\.#|^\~/.test(basename)) { | |
| if (/\.tmp(?:\..+)?$|~$|^\.#|^~/.test(basename)) { | |
| return | |
| } |
🧰 Tools
🪛 GitHub Actions: ci / 0_ubuntu.txt
[error] 121-121: ESLint: Capturing group number 1 is defined but never used. (regexp/no-unused-capturing-group)
🪛 GitHub Actions: ci / ubuntu
[error] 121-121: ESLint: Capturing group number 1 is defined but never used. (regexp/no-unused-capturing-group)
🪛 GitHub Check: ubuntu
[failure] 121-121:
Useless identity escapes with non-syntax characters are forbidden
[failure] 121-121:
Unnecessary escape character: ~
[failure] 121-121:
Unnecessary escape character: ~
[failure] 121-121:
Capturing group number 1 is defined but never used
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/utils/dev.ts` at line 121, The regex in the if condition that inspects
basename uses a capturing group and only allows numeric .tmp suffixes; replace
/\.tmp(\.\d+)*$|~$|^\.#|^\~/ with a non-capturing, broader pattern like
/\.tmp(?:\..+)*$|~$|^\.#|^~/ so it no longer uses a capturing group and matches
any suffix after .tmp (e.g., .tmp.swp); update the if (/.../.test(basename))
expression in src/utils/dev.ts accordingly.
Description
Editors and AI tools that use non-atomic writes create intermediate files like
example.md.tmp.153372in content directories. The content watcher picks these up and attempts to parse them, throwing an unhandled rejection that crashes the dev server:Reproduction
npm run devtouch content/example.md.tmp.153372Root Cause
The
onChangehandler in the dev watcher passes all files that match the collection's glob pattern through to the parser. Since the glob matches broadly (e.g. all files undercontent/), temp files with compound extensions pass through micromatch but fail at the parser which doesn't support the extension.Fix
Add an early return in
onChangefor files matching common temporary file patterns before any parsing is attempted:*.tmp,*.tmp.*(most editors/tools)~(Vim swap).#*and~*(Emacs lock files)Changes
src/utils/dev.ts: Skip temp files at the start ofonChangeFixes #3759