From 0f222b2de4aba969af638cffab8267106b86ea74 Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sun, 22 Nov 2026 15:20:25 -0500 Subject: [PATCH 1/2] fix(changes): open source at the selected revision --- client/e2e/changes.spec.ts | 38 ++++++++++++ client/src/changelens/ChangeLensView.tsx | 60 +++++++++++++++++-- .../src/changelens/panel/ChunkInspector.tsx | 3 +- client/src/changelens/panel/HunkDiff.tsx | 4 +- client/src/changelens/types.ts | 12 ++++ client/src/components/CodeModal/CodeModal.tsx | 16 ++++- .../components/CodeModal/CodeModalHeader.tsx | 11 ++++ .../components/CodeModal/MetricsSidebar.tsx | 2 +- client/src/components/Treemap.tsx | 2 +- docs/CODE_MAP.md | 2 +- server/app/services/changelens/models.py | 10 ++++ server/app/services/changelens/service.py | 50 ++++++++++++++++ server/tests/test_change_lens.py | 46 ++++++++++++++ 13 files changed, 241 insertions(+), 15 deletions(-) diff --git a/client/e2e/changes.spec.ts b/client/e2e/changes.spec.ts index 3a4d2d0c..0c1abd08 100644 --- a/client/e2e/changes.spec.ts +++ b/client/e2e/changes.spec.ts @@ -61,4 +61,42 @@ test.describe("Changes view on the acceptance repo", () => { await page.screenshot({ path: path.join(SHOTS, "changes-net.png") }); expect(errors).toEqual([]); }); + + test("deleted code opens at the base revision without disturbing its diff", async ({ page }) => { + const base = execFileSync("git", ["rev-parse", "main"], { cwd: repo, encoding: "utf8" }).trim(); + const id = "src/worker.ts::legacyCleanup"; + await page.goto(`/?${new URLSearchParams({ repo, view: "changes" })}`); + await lensReady(page); + await chunk(page, id).click(); + const inspector = page.locator(`[data-chunk-inspector="${id}"]`); + await inspector.locator('[data-action="open-diff"]').click(); + const diff = page.locator("[data-hunk-diff]"); + await expect(diff).toContainText("legacyCleanup"); + + const fetched = page.waitForRequest((r) => { + const url = new URL(r.url()); + return url.pathname === "/api/files/content" && url.searchParams.get("ref") === base; + }); + await inspector.locator('[data-action="open-code"]').click(); + expect(new URL((await fetched).url()).searchParams.get("path")).toBe(path.join(repo, "src/worker.ts")); + const code = page.getByRole("dialog"); + await expect(code.locator('[data-source-side="base"]')).toHaveAttribute("title", base); + await expect(code.locator(".code-modal-content")).toContainText("export function legacyCleanup"); + await expect(code.getByRole("link", { name: "Open in VS Code" })).toHaveCount(0); + await page.keyboard.press("Escape"); + await expect(code).toHaveCount(0); + await expect(chunk(page, id)).toHaveAttribute("data-selected", ""); + await expect(diff).toContainText("legacyCleanup"); + + // An unavailable Git object must not fall back to the checked-out file. + const requests: string[] = []; + await page.route("**/api/files/content?**", async (route) => { + requests.push(new URL(route.request().url()).searchParams.get("ref") ?? "disk"); + await route.fulfill({ status: 404, body: "Missing Git object" }); + }); + await inspector.locator('[data-action="open-code"]').click(); + await expect(code).toContainText(`Source unavailable at base ${base.slice(0, 7)}`); + await expect(code.locator(".code-modal-content")).toHaveCount(0); + expect(requests).toEqual([base]); + }); }); diff --git a/client/src/changelens/ChangeLensView.tsx b/client/src/changelens/ChangeLensView.tsx index db8430e8..c2b41edb 100644 --- a/client/src/changelens/ChangeLensView.tsx +++ b/client/src/changelens/ChangeLensView.tsx @@ -2,11 +2,12 @@ // It owns the fetches and the URL state; the map and the panel pieces get // everything through props. -import { createEffect, createMemo, createSignal, For, on, onCleanup, onMount, Show, untrack, type JSX } from "solid-js"; +import { createEffect, createMemo, createSignal, For, lazy, on, onCleanup, onMount, Show, untrack, type JSX } from "solid-js"; import { ArrowRight } from "lucide-solid"; import { Button } from "../components/ui/Button"; import { atFromTreePath, baseName, splitAt } from "../navigation/location"; import { go, location } from "../navigation/store"; +import { findTreeNodeByPath } from "../utils/dataProcessing"; import { ViewTools } from "../viz/viewToolbar"; import { fetchChangeLens, fetchHunk, LensError, type LensQuery } from "./api"; import BranchNotice, { historyApplies, isOffMain } from "./BranchNotice"; @@ -15,12 +16,13 @@ import { inScope, type RepoNode } from "./layout"; import Legend from "./Legend"; import LensMap from "./LensMap"; import { ChunkInspector, CommitRail, HunkDiff, ReviewBuckets } from "./panel"; -import type { ChangeLensPayload, LensChunk, LensHunkDiff } from "./types"; +import type { ChangeLensPayload, LensChunk, LensHunkDiff, LensSourceLocation } from "./types"; import { lens, setLens } from "./urlState"; import WindowBar from "./WindowBar"; /** Below this width the panel moves under the map. */ const NARROW_PX = 900; +const CodeModal = lazy(() => import("../components/CodeModal/CodeModal")); interface ScanNode { name: string; @@ -76,8 +78,6 @@ export default function ChangeLensView(props: { data: ScanNode | null; /** Absolute path of the scan root. */ rootPath: string; - /** Open a file or scope in the code viewer. */ - onOpenAt: (at: string, line?: number) => void; }) { const query = createMemo( () => { @@ -188,6 +188,33 @@ export default function ChangeLensView(props: { ); /** The selected commit's step when that commit changed the chunk, else the whole window. */ const stepOf = (chunk: string) => (commit()?.chunkIds.includes(chunk) ? commit()!.sha : undefined); + const [source, setSource] = createSignal(null); + const [sourceError, setSourceError] = createSignal(); + const [sourceLoading, setSourceLoading] = createSignal(false); + let sourceRequest = 0; + createEffect(on([query, selected, commit], () => { + sourceRequest++; + setSource(null); + setSourceError(undefined); + setSourceLoading(false); + })); + const openCode = async (chunk: LensChunk) => { + const q = query(); + if (!q || loading()) return; + const id = ++sourceRequest; + setSourceError(undefined); + setSourceLoading(true); + try { + const target = (await fetchHunk(q, chunk.id, stepOf(chunk.id))).source; + if (id !== sourceRequest) return; + if (target) setSource(target); + else setSourceError("No source is available for this chunk at the selected revisions."); + } catch (e) { + if (id === sourceRequest) setSourceError(e instanceof Error ? e.message : String(e)); + } finally { + if (id === sourceRequest) setSourceLoading(false); + } + }; const openHunk = (chunk: string, sha?: string) => { setHunk({ chunk, commit: sha ?? stepOf(chunk) }); if (lens().chunk !== chunk) setLens({ chunk }); @@ -401,7 +428,7 @@ export default function ChangeLensView(props: {
- setHunk(null)} /> + setHunk(null)} />
@@ -414,12 +441,33 @@ export default function ChangeLensView(props: { setLens({ chunk })} />
- props.onOpenAt(scanPath(base(), chunk.path), chunk.startLine)} /> + + + +
)} + + {(target) => { + const filePath = `${target.repoRoot.replace(/\/$/, "")}/${target.path}`; + return ( + setSource(null)} + /> + ); + }} + ); } diff --git a/client/src/changelens/panel/ChunkInspector.tsx b/client/src/changelens/panel/ChunkInspector.tsx index af5d40b7..4ae45347 100644 --- a/client/src/changelens/panel/ChunkInspector.tsx +++ b/client/src/changelens/panel/ChunkInspector.tsx @@ -126,6 +126,7 @@ export function ChunkInspector(props: { chunk: LensChunk | null; onOpenHunk: (chunkId: string, commit?: string) => void; onOpenCode: (chunk: LensChunk) => void; + sourceBusy?: boolean; }) { // Bars scale against the largest |Δ| of each metric across the window. const maxAbs = createMemo(() => { @@ -193,7 +194,7 @@ export function ChunkInspector(props: { - diff --git a/client/src/changelens/panel/HunkDiff.tsx b/client/src/changelens/panel/HunkDiff.tsx index be9c6ab4..ee4b12f6 100644 --- a/client/src/changelens/panel/HunkDiff.tsx +++ b/client/src/changelens/panel/HunkDiff.tsx @@ -53,7 +53,7 @@ function Line(props: { line: DiffLine }) { } /** The diff text behind one chunk, with line numbers and word highlights. Esc closes it. */ -export function HunkDiff(props: { diff: LensHunkDiff | null; loading: boolean; error?: string; onClose: () => void }) { +export function HunkDiff(props: { diff: LensHunkDiff | null; loading: boolean; error?: string; ignoreEscape?: boolean; onClose: () => void }) { const hunks = createMemo(() => (props.diff ? parseUnifiedDiff(props.diff.diff) : [])); const counts = createMemo(() => { let added = 0; @@ -68,7 +68,7 @@ export function HunkDiff(props: { diff: LensHunkDiff | null; loading: boolean; e onMount(() => { const onKey = (e: KeyboardEvent) => { - if (e.key === "Escape" && !e.defaultPrevented) props.onClose(); + if (e.key === "Escape" && !e.defaultPrevented && !props.ignoreEscape) props.onClose(); }; window.addEventListener("keydown", onKey); onCleanup(() => window.removeEventListener("keydown", onKey)); diff --git a/client/src/changelens/types.ts b/client/src/changelens/types.ts index af29c6f6..4e758bc7 100644 --- a/client/src/changelens/types.ts +++ b/client/src/changelens/types.ts @@ -205,6 +205,16 @@ export interface ChangeLensPayload { } /** `GET /api/change-lens/hunk`: the diff text behind one chunk. */ +export interface LensSourceLocation { + repoRoot: string; + path: string; + side: "base" | "head"; + /** Null only for a working-tree file. */ + revision: string | null; + startLine: number; + endLine: number; +} + export interface LensHunkDiff { chunkId: string; path: string; @@ -216,4 +226,6 @@ export interface LensHunkDiff { diff: string; /** Set when the diff was clipped. */ truncated: boolean; + /** The side containing the chunk, or null when neither side has source. */ + source?: LensSourceLocation | null; } diff --git a/client/src/components/CodeModal/CodeModal.tsx b/client/src/components/CodeModal/CodeModal.tsx index 87ff3d8b..ec0cc739 100644 --- a/client/src/components/CodeModal/CodeModal.tsx +++ b/client/src/components/CodeModal/CodeModal.tsx @@ -31,8 +31,10 @@ interface CodeModalProps { onClose: () => void; fileNode?: any; scopeNode?: any; - /** Read the file from this git commit (compare mode) instead of the disk. */ + /** Read the file from this Git revision instead of the disk. */ gitRef?: string | null; + /** The side selected in Changes, shown beside the source path. */ + revisionSide?: "base" | "head"; /** The scanned root, so the header can show a repo-relative path. */ rootPath?: string; } @@ -124,7 +126,7 @@ export default function CodeModal(props: CodeModalProps) { eLine >= sLine; setLineFilterEnabled(hasRange); - if (guessLangFromPath(props.filePath) === "md") { + if (guessLangFromPath(props.filePath) === "md" && !props.revisionSide) { setViewMode("preview"); } else { setViewMode("code"); @@ -427,6 +429,8 @@ export default function CodeModal(props: CodeModalProps) { filePath={props.filePath!} rootPath={props.rootPath} baseName={baseName()} + gitRef={props.gitRef} + revisionSide={props.revisionSide} onClose={props.onClose} rawCode={rawCode} hasLineRange={hasLineRange} @@ -501,7 +505,13 @@ export default function CodeModal(props: CodeModalProps) { fallback={ error() ?? highlightError()} + error={() => { + const failure = error(); + if (failure && props.gitRef && props.revisionSide) { + return `Source unavailable at ${props.revisionSide} ${props.gitRef.slice(0, 7)}. ${failure}`; + } + return failure ?? highlightError(); + }} highlightedHtml={highlightedHtml} filePath={() => props.filePath} baseName={baseName()} diff --git a/client/src/components/CodeModal/CodeModalHeader.tsx b/client/src/components/CodeModal/CodeModalHeader.tsx index 9372a989..c6522edd 100644 --- a/client/src/components/CodeModal/CodeModalHeader.tsx +++ b/client/src/components/CodeModal/CodeModalHeader.tsx @@ -64,6 +64,8 @@ export function CodeModalHeader(props: { /** The scanned root; the path shows relative to it. */ rootPath?: string; baseName: string; + gitRef?: string | null; + revisionSide?: "base" | "head"; onClose: () => void; rawCode: () => string; @@ -100,6 +102,13 @@ export function CodeModalHeader(props: { > {dir()} + + {(side) => ( + + {side() === "base" ? "Base" : "Head"} · {props.gitRef?.slice(0, 7) ?? "Working tree"} + + )} + @@ -184,6 +193,7 @@ export function CodeModalHeader(props: { icon={ - + diff --git a/docs/CODE_MAP.md b/docs/CODE_MAP.md index dbdb3956..5a3de177 100644 --- a/docs/CODE_MAP.md +++ b/docs/CODE_MAP.md @@ -213,7 +213,7 @@ Which code chunks a branch or a time window edited. User guide: `site/src/docs/p | Hunks per commit and base → head (`git diff -U0`), renames | `server/app/services/changelens/hunks.py` | | Blob parsing with the scan's analyzers (one parse per side, by blob sha), Markdown headings, generated/vendored files | `server/app/services/changelens/blobs.py` | | Chunks: hunk → innermost named scope, file/heading/range chunks, base ↔ head pairing (exact, renamed-file, moved, uncertain), touches, reverted, metrics before → after, review buckets (`COMPLEX_AT`) | `server/app/services/changelens/chunks.py` | -| Chunk-limited unified diff for one chunk | `server/app/services/changelens/textdiff.py`, `service.py` (`hunk_diff`) | +| Chunk-limited unified diff and revision-bound source location for one chunk | `server/app/services/changelens/textdiff.py`, `service.py` (`hunk_diff`); `client/src/changelens/ChangeLensView.tsx` opens that side in `CodeModal` | | Acceptance repo (every case of the issue) and the client's fixture payloads | `server/tests/fixtures/change_lens_repo.py` (`--write-payloads` writes `client/src/changelens/fixture*.json`), `server/tests/test_change_lens.py` | | The view: fetches, URL state (`cw`, `cm`, `cl`, `cc`, `cs`, `clens`, `chist`, custom refs), selection kept across results, repo ↔ scan paths | `client/src/changelens/ChangeLensView.tsx`, `api.ts`, `urlState.ts` | | Toolbar: window presets and Custom form, Touched/Net, Only edits/In repo, color metric with Now/Δ | `client/src/changelens/WindowBar.tsx` | diff --git a/server/app/services/changelens/models.py b/server/app/services/changelens/models.py index 728f78b3..8c769b3e 100644 --- a/server/app/services/changelens/models.py +++ b/server/app/services/changelens/models.py @@ -161,6 +161,15 @@ class ChangeLensPayload(LensModel): metric_ids: list[str] +class LensSourceLocation(LensModel): + repo_root: str + path: str + side: Literal["base", "head"] + revision: Optional[str] # null only for a working-tree file + start_line: int + end_line: int + + class LensHunkDiff(LensModel): chunk_id: str path: str @@ -170,6 +179,7 @@ class LensHunkDiff(LensModel): to: str diff: str truncated: bool + source: Optional[LensSourceLocation] = None model_config = ConfigDict( alias_generator=lambda name: "from" if name == "from_" else to_camel(name), populate_by_name=True diff --git a/server/app/services/changelens/service.py b/server/app/services/changelens/service.py index 2d19a873..0844754f 100644 --- a/server/app/services/changelens/service.py +++ b/server/app/services/changelens/service.py @@ -19,6 +19,7 @@ LensEndpoint, LensHunkDiff, LensSelection, + LensSourceLocation, LensSummary, ) from app.services.changelens.window import LensError, Params, Window, iso, local_timezone, resolve @@ -169,6 +170,43 @@ def _change_at(line: Lineage, sha: str): return next((c for c in line.changes if c.sha == sha), None) +def _source_location( + window: Window, + draft: engine.Draft, + old_ref: Optional[BlobRef], + new_ref: Optional[BlobRef], + old_scope: Optional[Scope], + new_scope: Optional[Scope], + old_revision: Optional[str], + new_revision: Optional[str], + recorded: list[Hunk], + commit: Optional[str], +) -> Optional[LensSourceLocation]: + """Open the side that still contains the chunk, using the same blobs as the diff.""" + is_head = new_ref is not None and (not draft.is_symbol or new_scope is not None) + ref, scope = (new_ref, new_scope) if is_head else (old_ref, old_scope) + revision = new_revision if is_head else old_revision + if ref is None or (draft.is_symbol and scope is None) or (not ref.disk and revision is None): + return None + if scope: + start, end = scope.start, scope.end + elif commit is None and (is_head or draft.chunk.status == "deleted"): + start, end = draft.chunk.start_line, draft.chunk.end_line + else: + spans = [(h.new_start, h.new_lines) if is_head else (h.old_start, h.old_lines) for h in recorded] + spans = [(s, n) for s, n in spans if s > 0 and n > 0] + start = min((s for s, _ in spans), default=1) + end = max((s + n - 1 for s, n in spans), default=start) + return LensSourceLocation( + repo_root=str(window.repo), + path=ref.path, + side="head" if is_head else "base", + revision=None if ref.disk else revision, + start_line=start, + end_line=end, + ) + + def hunk_diff(path: Path, params: Params, chunk_id: str, commit: Optional[str] = None) -> dict: built, _ = build_lens(path, params) draft = built.drafts.get(chunk_id) @@ -181,10 +219,13 @@ def hunk_diff(path: Path, params: Params, chunk_id: str, commit: Optional[str] = new_ref: Optional[BlobRef] = None old_scope: Optional[Scope] = None new_scope: Optional[Scope] = None + old_revision: Optional[str] = None + new_revision: Optional[str] = None recorded: list[Hunk] = [] if commit is None: old_ref, new_ref = draft.base_file.base, line.head old_scope, new_scope = draft.base, draft.head + old_revision, new_revision = window.base_tree, window.tip.sha recorded = draft.net.hunks label_from, label_to = window.base.label, _head_endpoint(built).label else: @@ -195,8 +236,13 @@ def hunk_diff(path: Path, params: Params, chunk_id: str, commit: Optional[str] = sha = next((s for s in draft.touches if s.startswith(commit)), None) if commit == WORKTREE: label_from, label_to = window.tip.label, "Working tree" + old_revision = window.tip.sha else: label_from, label_to = f"{commit[:7]}^", commit[:7] + selected = next((c for c in window.commits if c.sha == sha), None) + if selected: + old_revision = selected.parents[0] if selected.parents else None + new_revision = selected.sha if sha is not None: recorded = draft.touches[sha].hunks if draft.is_symbol: @@ -248,6 +294,10 @@ def owned(side: str, start: int, count: int) -> list[bool]: to=label_to, diff=text, truncated=truncated, + source=_source_location( + window, draft, old_ref, new_ref, old_scope, new_scope, + old_revision, new_revision, recorded, commit, + ), ).wire() diff --git a/server/tests/test_change_lens.py b/server/tests/test_change_lens.py index 0f7f57f5..48e18b1b 100644 --- a/server/tests/test_change_lens.py +++ b/server/tests/test_change_lens.py @@ -179,6 +179,35 @@ def test_api_serves_the_payload_and_refuses_a_folder_outside_git(repo, tmp_path) assert client.get("/api/change-lens", params={"path": str(tmp_path)}).status_code == 409 +def test_source_follows_the_exact_diff_side_and_revision(repo, touched): + client = TestClient(app) + chunk = "src/worker.ts::legacyCleanup" + removed = by_id(touched)[chunk] + source = service.hunk_diff(repo, Params(), chunk)["source"] + assert source == { + "repoRoot": str(repo), + "path": "src/worker.ts", + "side": "base", + "revision": _rev(repo, "main"), + "startLine": removed["baseStartLine"], + "endLine": removed["baseEndLine"], + } + params = {"path": str(repo / source["path"])} + old = client.get("/api/files/content", params={**params, "ref": source["revision"]}) + assert old.status_code == 200 + assert "export function legacyCleanup" in old.text.splitlines()[source["startLine"] - 1] + assert "legacyCleanup" not in client.get("/api/files/content", params=params).text + + deletion = next(c for c in touched["commits"] if c["subject"] == "worker: remove legacyCleanup") + step = service.hunk_diff(repo, Params(), chunk, deletion["sha"])["source"] + assert step["side"] == "base" and step["revision"] == _rev(repo, f"{deletion['sha']}^") + cap = next(c for c in touched["commits"] if c["subject"] == "retry: cap the attempt limit") + head = service.hunk_diff(repo, Params(), "src/worker.ts::retryJob", cap["sha"])["source"] + assert head["side"] == "head" and head["revision"] == cap["sha"] + worktree = service.hunk_diff(repo, Params(), "src/worker.ts::formatLog", WORKTREE)["source"] + assert worktree["side"] == "head" and worktree["revision"] is None + + # -- small repos, one per rule --------------------------------------------------- @@ -212,6 +241,23 @@ def fn(name: str, k: int) -> str: return f"export function {name}(x: number) {{\n const v = x + {k};\n return v;\n}}\n" +def test_deleted_source_uses_its_base_path_after_a_rename(tmp_path): + repo = Mini(tmp_path / "r") + base = repo.commit("base", {"old.ts": fn("stay", 1) + fn("gone", 2)}) + repo.git("checkout", "--quiet", "-b", "feature") + repo.git("mv", "old.ts", "new.ts") + repo.git("commit", "--quiet", "-m", "rename") + head = repo.commit("remove gone", {"new.ts": fn("stay", 1)}) + params = Params(window="custom", mode="net", base=base, head=head) + payload = service.build_payload(repo.path, params) + gone = next(c for c in payload["chunks"] if c["name"] == "gone") + source = service.hunk_diff(repo.path, params, gone["id"])["source"] + assert source["side"] == "base" + assert source["revision"] == base + assert source["path"] == "old.ts" + assert (source["startLine"], source["endLine"]) == (5, 8) + + def test_time_window_leaves_out_what_an_upstream_merge_brought_in(tmp_path): repo = Mini(tmp_path / "r") repo.commit("base", {"a.ts": fn("a", 1), "c.ts": fn("c", 1), "up.ts": fn("up", 1)}) From 38524520267f78b1730b6c10456eba2a78fdc020 Mon Sep 17 00:00:00 2001 From: Byron Wall Date: Sun, 22 Nov 2026 15:24:24 -0500 Subject: [PATCH 2/2] fix(changes): keep source tied to the active commit diff --- client/e2e/changes.spec.ts | 19 +++++++++++++++++++ client/src/changelens/ChangeLensView.tsx | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/client/e2e/changes.spec.ts b/client/e2e/changes.spec.ts index 0c1abd08..cf99b76d 100644 --- a/client/e2e/changes.spec.ts +++ b/client/e2e/changes.spec.ts @@ -99,4 +99,23 @@ test.describe("Changes view on the acceptance repo", () => { await expect(code.locator(".code-modal-content")).toHaveCount(0); expect(requests).toEqual([base]); }); + + test("Open code follows a commit diff opened from the chunk's touch strip", async ({ page }) => { + const git = (...args: string[]) => execFileSync("git", args, { cwd: repo, encoding: "utf8" }).trim(); + const removedAt = git("log", "-1", "--format=%H", "--grep=worker: remove legacyCleanup"); + const previous = git("rev-parse", `${removedAt}^`); + expect(previous).not.toBe(git("rev-parse", "main")); + const id = "src/worker.ts::legacyCleanup"; + await page.goto(`/?${new URLSearchParams({ repo, view: "changes" })}`); + await lensReady(page); + await chunk(page, id).click(); + const inspector = page.locator(`[data-chunk-inspector="${id}"]`); + await inspector.locator(`[data-touch="${removedAt}"]`).click(); + const diff = page.locator("[data-hunk-diff]"); + await expect(diff).toContainText(removedAt.slice(0, 7)); + await inspector.locator('[data-action="open-code"]').click(); + const code = page.getByRole("dialog"); + await expect(code.locator('[data-source-side="base"]')).toHaveAttribute("title", previous); + await expect(code.locator(".code-modal-content")).toContainText("export function legacyCleanup"); + }); }); diff --git a/client/src/changelens/ChangeLensView.tsx b/client/src/changelens/ChangeLensView.tsx index c2b41edb..88626569 100644 --- a/client/src/changelens/ChangeLensView.tsx +++ b/client/src/changelens/ChangeLensView.tsx @@ -192,7 +192,7 @@ export default function ChangeLensView(props: { const [sourceError, setSourceError] = createSignal(); const [sourceLoading, setSourceLoading] = createSignal(false); let sourceRequest = 0; - createEffect(on([query, selected, commit], () => { + createEffect(on([query, selected, commit, hunk], () => { sourceRequest++; setSource(null); setSourceError(undefined); @@ -205,7 +205,9 @@ export default function ChangeLensView(props: { setSourceError(undefined); setSourceLoading(true); try { - const target = (await fetchHunk(q, chunk.id, stepOf(chunk.id))).source; + const active = hunk(); + const step = active?.chunk === chunk.id ? active.commit : stepOf(chunk.id); + const target = (await fetchHunk(q, chunk.id, step)).source; if (id !== sourceRequest) return; if (target) setSource(target); else setSourceError("No source is available for this chunk at the selected revisions.");