Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/browser/components/pr-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -763,12 +763,16 @@ function VersionBar() {
const reviews = usePRReviewSelector((s) => s.reviews);
const currentUser = usePRReviewSelector((s) => s.currentUser);

// Lazy-load version data on first mount (deferred from loadPRData)
// Lazy-load version data when commits are available (deferred from loadPRData).
// Deferring avoids a race: loadPRData populates commits asynchronously, and
// loadVersionData needs actual commits to group into versions. Without this
// guard, the mount-time effect fires before loadPRData finishes, leaving
// commits empty and the last commit's version never created.
useEffect(() => {
if (!versionDataLoaded) {
if (!versionDataLoaded && commits.length > 0) {
store.loadVersionData();
}
}, [versionDataLoaded, store]);
}, [versionDataLoaded, store, commits]);

// Map of SHA → whether it's a merge commit (for showing correct icon in dropdowns)
const isMergeCommit = useMemo(() => {
Expand Down
6 changes: 5 additions & 1 deletion src/browser/contexts/pr-review/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3506,13 +3506,17 @@ export class PRReviewStore {
* the version/commit selector is first opened. */
loadVersionData = async (): Promise<void> => {
if (this.state.versionDataLoaded) return;
const { owner, repo, pr, commits } = this.state;
const { owner, repo, pr } = this.state;

try {
const pushVersionsData = await this.github
.getPushVersions(owner, repo, pr.number)
.catch(() => [] as PushVersion[]);

// Read commits from current state — loadPRData may have populated them
// while we waited for push versions (race on initial mount).
const commits = this.state.commits;

// Merge force-push versions with commit-grouped versions
const commitVersions = groupCommitsIntoVersions(commits, 2);
const seenShas = new Set(pushVersionsData.map((v) => v.sha));
Expand Down
Loading