A tab body keys memos and effects off `scope` (the diff pane resolves its
media/html routes from it, the editor restores its preview scroll, the side
chat rebuilds its prose-rewrite cache), but the tab cell built
`{ sessionId, cwd }` fresh on every render. Every such dependency therefore
looked changed whenever the cell re-rendered — which the memo comparator
allows exactly when a COMPARED field moves: `expanded` on a directory toggle,
plus `revealed`, `localeRevision`, `tabsVersion`. The diff preview then
re-ran its whole-document rewrite and its content tab re-issued a whole-file
`fs.read`, flashing its loading row.
`useSessionScope` is now the one place a scope for a component tree is built;
the tab cell, the diff tab, the native tab adapter, and the shell's badge /
rightActions / `+` menu / lifecycle-callback seams all use it. Those last
ones are documented external plug-in surfaces, so a plug-in memoizing on
`scope` stops churning on every unrelated re-render too.
Stabilizing the object removes the only path the diff pane's `content` tab
had to re-read after the file changed on disk, so the header's refresh button
now drives it explicitly (the pane owns the gesture; the loader no longer
leaks its internal counter).
Seven comments asserted that the scope object's identity churns on every
render; that premise is gone, so the ones that still apply say what they
actually guard.
56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
/**
|
|
* The diff tab: one change opened from the changes tab, like VSCode's diff
|
|
* editor. A worktree ref loads the file's unified diff (`git diff`, staged or
|
|
* not; untracked files — which git diff never covers — render as a full-file
|
|
* addition from their content), a commit ref loads the commit's full patch
|
|
* (`git.show`-style). The header carries a refresh button because the tab
|
|
* stays mounted while the changes tab's staging/discard operations change the
|
|
* very content it shows. Loading IS the shared `useGitDiffTarget` hook (the
|
|
* changes tab's inline preview runs the same one, so the staged-side and
|
|
* untracked fallbacks and the per-file fold cache cannot drift apart);
|
|
* rendering goes through the shared {@link DiffFiles} renderer.
|
|
*/
|
|
import { IconRefreshOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
import type { SessionScope } from './api.ts'
|
|
import type { SidebarDiffRef } from './state.ts'
|
|
import { DiffFiles } from './diff/DiffFiles.tsx'
|
|
import { useGitDiffTarget } from './diff/use-git-diff.ts'
|
|
import { t } from './locales.ts'
|
|
import css from './sidebar.module.css'
|
|
|
|
export function DiffTab(props: { scope: SessionScope; diff: SidebarDiffRef }) {
|
|
const { scope, diff } = props
|
|
const { loading, error, diffText, untracked, refresh, resolveFold } = useGitDiffTarget(diff, scope)
|
|
|
|
return (
|
|
<div className={css.gitDiffTab}>
|
|
<div className={css.gitDiffTabHeader}>
|
|
<span className={css.gitDiffTabTitle} title={diff.kind === 'worktree' ? diff.path : `${diff.hash} ${diff.subject}`}>
|
|
{diff.kind === 'worktree' ? diff.path : `${diff.hash} ${diff.subject}`}
|
|
</span>
|
|
<button
|
|
type="button"
|
|
className={css.iconButton}
|
|
aria-label={t('refresh')}
|
|
title={t('refresh')}
|
|
onClick={refresh}
|
|
>
|
|
<IconRefreshOutlineRegular size={14} />
|
|
</button>
|
|
</div>
|
|
{loading && <div className={css.gitPlaceholder}>{t('loading')}</div>}
|
|
{!loading && error !== null && <div className={css.gitError}>{t('diffLoadError')}: {error}</div>}
|
|
{!loading && error === null && diffText !== null && (
|
|
<>
|
|
{untracked !== undefined
|
|
? <DiffFiles diff="" untrackedPath={diff.kind === 'worktree' ? diff.path : ''} untrackedContent={untracked} />
|
|
: <DiffFiles diff={diffText} resolveFold={resolveFold} />}
|
|
{diffText === '' && untracked === undefined && (
|
|
<div className={css.gitEmpty}>{t('diffEmpty')}</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|