Skip to content

fix(vite): make read git branch call async#2793

Merged
aidanhb merged 2 commits into
mainfrom
aidan/vite
Apr 23, 2026
Merged

fix(vite): make read git branch call async#2793
aidanhb merged 2 commits into
mainfrom
aidan/vite

Conversation

@aidanhb
Copy link
Copy Markdown
Contributor

@aidanhb aidanhb commented Apr 23, 2026

So server doesn't hang if git branch read hangs

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

@aidanhb has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 38 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 53 minutes and 38 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 10e32fad-e9c3-48ae-864e-64882199d3d5

📥 Commits

Reviewing files that changed from the base of the PR and between 7a947f9 and aa30301.

📒 Files selected for processing (1)
  • js/app/packages/app/vite.base.ts
📝 Walkthrough

Walkthrough

The Vite base configuration file is updated to use asynchronous Git branch detection instead of synchronous calls. The git-branch:update websocket handler now executes git rev-parse --abbrev-ref HEAD asynchronously and imports the exec function from Node's child_process module.

Changes

Cohort / File(s) Summary
Async Git branch detection
js/app/packages/app/vite.base.ts
Converts synchronous readGitBranch() to asynchronous readGitBranchAsync() implementation. Updates websocket connection to execute git rev-parse --abbrev-ref HEAD via exec and adds corresponding node:child_process import.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with 'fix:' prefix, is under 72 characters (42 chars), and accurately summarizes the main change of converting synchronous git branch reading to asynchronous.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of making the git branch read call async to prevent server hangs.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
js/app/packages/app/vite.base.ts (1)

60-66: ⚠️ Potential issue | 🟡 Minor

Watcher callback still uses synchronous readGitBranch().

The stated goal of this PR is to prevent the dev server from hanging if reading the git branch hangs, but the chokidar watcher.on('all', ...) handler at line 64 still calls the synchronous readGitBranch(). A hanging git rev-parse triggered by a HEAD change would still block the Node event loop here. Consider switching this call site to readGitBranchAsync() as well for consistency with the connection handler, and so the sync version can eventually be retired.

♻️ Proposed change
-      watcher.on('all', () => {
-        server.ws.send({
-          type: 'custom',
-          event: 'git-branch:update',
-          data: readGitBranch(),
-        });
-      });
+      watcher.on('all', () => {
+        readGitBranchAsync().then((branch) => {
+          server.ws.send({
+            type: 'custom',
+            event: 'git-branch:update',
+            data: branch,
+          });
+        });
+      });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/app/packages/app/vite.base.ts` around lines 60 - 66, The watcher callback
currently calls the synchronous readGitBranch(), which can block the event loop;
change the watcher.on('all', ...) handler to call readGitBranchAsync() instead
(e.g., make the callback async or use readGitBranchAsync().then(...).catch(...))
and pass the resolved branch data into server.ws.send({ type: 'custom', event:
'git-branch:update', data: ... }); ensure you handle rejections (log or send a
safe fallback value) to avoid unhandled promise rejections and preserve
non-blocking behavior used in the connection handler.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@js/app/packages/app/vite.base.ts`:
- Around line 34-40: The Promise executor in readGitBranchAsync currently uses
the parameter name "resolve", which shadows the top-level "resolve" import from
node:path; rename the executor parameter (e.g. to "resolvePromise" or "res") to
avoid the shadowing and improve readability and update any corresponding usages
inside readGitBranchAsync (the exec callback's resolve call) to the new name so
the function behavior remains unchanged.

---

Outside diff comments:
In `@js/app/packages/app/vite.base.ts`:
- Around line 60-66: The watcher callback currently calls the synchronous
readGitBranch(), which can block the event loop; change the watcher.on('all',
...) handler to call readGitBranchAsync() instead (e.g., make the callback async
or use readGitBranchAsync().then(...).catch(...)) and pass the resolved branch
data into server.ws.send({ type: 'custom', event: 'git-branch:update', data: ...
}); ensure you handle rejections (log or send a safe fallback value) to avoid
unhandled promise rejections and preserve non-blocking behavior used in the
connection handler.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7e384eeb-ec46-4fb6-918e-855dbdebc83e

📥 Commits

Reviewing files that changed from the base of the PR and between c4d1938 and 7a947f9.

📒 Files selected for processing (1)
  • js/app/packages/app/vite.base.ts

Comment thread js/app/packages/app/vite.base.ts
@aidanhb aidanhb merged commit c8eb4e3 into main Apr 23, 2026
29 of 31 checks passed
@aidanhb aidanhb deleted the aidan/vite branch April 23, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant