mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(diffs): keep note sessions compiler compatible
This commit is contained in:
@@ -79,7 +79,7 @@
|
||||
3 src/renderer/src/components/crash-report/use-crash-report-copy.ts
|
||||
1 src/renderer/src/components/dashboard/useAgentBucketCounts.ts
|
||||
1 src/renderer/src/components/dashboard/useLiveDashboardSnapshot.ts
|
||||
2 src/renderer/src/components/diff-comments/DiffCommentCard.tsx
|
||||
1 src/renderer/src/components/diff-comments/DiffCommentCard.tsx
|
||||
5 src/renderer/src/components/diff-comments/DiffCommentPopover.tsx
|
||||
1 src/renderer/src/components/diff-comments/diff-comment-draft-zone.ts
|
||||
1 src/renderer/src/components/diff-comments/useDiffCommentDecorator.tsx
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Profiler, StrictMode } from 'react'
|
||||
import { act, cleanup, fireEvent, render, within } from '@testing-library/react'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { DiffCommentCard } from './DiffCommentCard'
|
||||
import { DiffCommentFileSession } from './diff-comment-session'
|
||||
import { DiffCommentFileSession, type DiffCommentDraftSession } from './diff-comment-session'
|
||||
import {
|
||||
DiffCommentSessionScope,
|
||||
useDiffCommentFileSession,
|
||||
@@ -211,7 +211,7 @@ it.each([
|
||||
const a = file.openDraft({ lineNumber: 5 }, async () => request.promise)!
|
||||
a.setBody('Draft A')
|
||||
const pending = file.submitDraft(a, () => request.promise, 'Draft A')
|
||||
let b = null
|
||||
let b: DiffCommentDraftSession | null = null
|
||||
if (outcome.includes('b')) {
|
||||
b = file.openDraft({ lineNumber: 9 }, async () => true)!
|
||||
b.setBody('Draft B')
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
import { useLayoutEffect, useRef } from 'react'
|
||||
import { useLayoutEffect, useRef, useState } from 'react'
|
||||
|
||||
export function useLocalDiffCommentSession<T extends { dispose(): void }>(
|
||||
create: () => T,
|
||||
external?: T
|
||||
): T {
|
||||
const owned = useRef<T | null>(null)
|
||||
if (!external && !owned.current) {
|
||||
owned.current = create()
|
||||
const [local, setLocal] = useState<T | null>(() => (external ? null : create()))
|
||||
let owned = local
|
||||
if (!external && !owned) {
|
||||
owned = create()
|
||||
setLocal(owned)
|
||||
}
|
||||
const revision = useRef(0)
|
||||
const local = owned.current
|
||||
const revision = useRef({ value: 0 })
|
||||
useLayoutEffect(() => {
|
||||
const retained = ++revision.current
|
||||
const lifetime = revision.current
|
||||
const retained = ++lifetime.value
|
||||
return () => {
|
||||
// Effect replay reacquires the owner before actual teardown.
|
||||
queueMicrotask(() => {
|
||||
if (revision.current === retained) {
|
||||
local?.dispose()
|
||||
if (lifetime.value === retained) {
|
||||
owned?.dispose()
|
||||
}
|
||||
})
|
||||
}
|
||||
}, [local])
|
||||
return external ?? local!
|
||||
}, [owned])
|
||||
return external ?? owned!
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DiffCommentSessionScope } from '../../diff-comments/diff-comment-sessio
|
||||
import { useDiffCommentView } from '../../diff-comments/use-diff-comment-owner'
|
||||
import { diffCommentOwnerKey } from '@/store/slices/diff-comments/diff-comment-owner'
|
||||
import { editorViewPlacement } from '@/store/slices/editor/tabs/editor-view-placement'
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react'
|
||||
import React, { useCallback, useMemo, useState } from 'react'
|
||||
import { useAppStore } from '@/store'
|
||||
import { useWorkspaceFileBrowserActionPredicate } from '@/lib/browser/documents/file-preview'
|
||||
import { useVisibleWorktreeDiffComments } from '../../diff-comments/use-visible-worktree-diff-comments'
|
||||
@@ -48,10 +48,11 @@ type CombinedDiffViewerProps = {
|
||||
|
||||
export default function CombinedDiffViewer(props: CombinedDiffViewerProps): React.JSX.Element {
|
||||
const { owner, comments } = useDiffCommentView(props.file.worktreeId, props.file)
|
||||
const previousScope = useRef('unresolved')
|
||||
const scope = owner ? diffCommentOwnerKey(owner) : previousScope.current
|
||||
if (owner) {
|
||||
previousScope.current = scope
|
||||
const resolvedScope = owner ? diffCommentOwnerKey(owner) : null
|
||||
const [previousScope, setPreviousScope] = useState(resolvedScope ?? 'unresolved')
|
||||
const scope = resolvedScope ?? previousScope
|
||||
if (scope !== previousScope) {
|
||||
setPreviousScope(scope)
|
||||
}
|
||||
const knownNoteIds = useMemo(
|
||||
() => (comments ? new Set(comments.map((note) => note.id)) : undefined),
|
||||
|
||||
Reference in New Issue
Block a user