Skip to content

fix(dev): preserve SQL hashes in HMR dumps#3816

Open
danlg wants to merge 1 commit into
nuxt:mainfrom
danlg:fix-hmr-sql-dump-hashes
Open

fix(dev): preserve SQL hashes in HMR dumps#3816
danlg wants to merge 1 commit into
nuxt:mainfrom
danlg:fix-hmr-sql-dump-hashes

Conversation

@danlg

@danlg danlg commented Jul 15, 2026

Copy link
Copy Markdown

Summary

  • keep generated row hashes when HMR updates the compressed SQL dump
  • keep browser HMR queries unchanged
  • cover both matching collections in the existing HMR test

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

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

@danlg is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/content@3816

commit: f2d99ce

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The HMR file change handler now passes the complete collection insert object to broadcast. Broadcasting executes insert.queries and annotates manifest dump SQL entries with the insert hash. The HMR hook payload derives its query list from the insert object, and the multi-collection test verifies hash suffixes in both collection dumps.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preserving SQL hashes in HMR dumps.
Description check ✅ Passed The description is directly related to the HMR dump hashing fix and updated test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e7e1269 and f2d99ce.

📒 Files selected for processing (2)
  • src/utils/dev.ts
  • test/multi-collection-hmr.test.ts

Comment thread src/utils/dev.ts
Comment on lines +211 to 213
if (insert) {
await Promise.all(insert.queries.map(query => db.exec(query)))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant