fix(dev): preserve SQL hashes in HMR dumps#3816
Conversation
|
@danlg is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
📝 WalkthroughWalkthroughThe HMR file change handler now passes the complete collection insert object to Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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`:
- Around line 211-213: Update the insert execution block in the surrounding
database setup flow to replace Promise.all with a for...of loop over
insert.queries, awaiting each db.exec(query) before starting the next so the
initial INSERT precedes dependent UPDATE statements.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f6a4a3ba-3055-4b95-9e2f-7afb71573e94
📒 Files selected for processing (2)
src/utils/dev.tstest/multi-collection-hmr.test.ts
| if (insert) { | ||
| await Promise.all(insert.queries.map(query => db.exec(query))) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win
Execute multi-part queries sequentially to prevent race conditions.
Based on the definition of generateCollectionInsert, it can split large contents into an initial INSERT query followed by dependent UPDATE queries. Executing them concurrently via Promise.all introduces a race condition where the UPDATE statements may run before the INSERT completes, causing them to silently affect 0 rows or fail.
Use a for...of loop to ensure they execute sequentially in the correct order.
🐛 Proposed fix
- if (insert) {
- await Promise.all(insert.queries.map(query => db.exec(query)))
- }
+ if (insert) {
+ for (const query of insert.queries) {
+ await db.exec(query)
+ }
+ }📝 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 (insert) { | |
| await Promise.all(insert.queries.map(query => db.exec(query))) | |
| } | |
| if (insert) { | |
| for (const query of insert.queries) { | |
| await db.exec(query) | |
| } | |
| } |
🧰 Tools
🪛 OpenGrep (1.25.0)
[ERROR] 212-212: Dynamic command passed to child_process.exec/execSync. Use child_process.execFile or spawn with an argument array instead.
(coderabbit.command-injection.exec-js)
🤖 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` around lines 211 - 213, Update the insert execution block
in the surrounding database setup flow to replace Promise.all with a for...of
loop over insert.queries, awaiting each db.exec(query) before starting the next
so the initial INSERT precedes dependent UPDATE statements.
Summary
Problem
The runtime importer expects every dump statement to end with
-- <hash>. HMR currently replaces the dump row with the raw INSERT, so the importer treats the whole INSERT as the hash, strips it, and can pass an empty SQL statement to SQLite (The supplied SQL string contains no statements).Test
pnpm exec vitest run test/multi-collection-hmr.test.ts