Skip to content

Commit f961fba

Browse files
Apply PR #21537: fix(app): remove pierre diff virtualization
2 parents e290700 + cb29742 commit f961fba

File tree

4 files changed

+13
-321
lines changed

4 files changed

+13
-321
lines changed

packages/ui/src/components/file-ssr.tsx

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DIFFS_TAG_NAME, FileDiff, VirtualizedFileDiff } from "@pierre/diffs"
1+
import { DIFFS_TAG_NAME, FileDiff } from "@pierre/diffs"
22
import { type PreloadFileDiffResult, type PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"
33
import { createEffect, onCleanup, onMount, Show, splitProps } from "solid-js"
44
import { Dynamic, isServer } from "solid-js/web"
@@ -13,7 +13,6 @@ import {
1313
notifyShadowReady,
1414
observeViewerScheme,
1515
} from "../pierre/file-runtime"
16-
import { acquireVirtualizer, virtualMetrics } from "../pierre/virtualizer"
1716
import { File, type DiffFileProps, type FileProps } from "./file"
1817

1918
type DiffPreload<T> = PreloadMultiFileDiffResult<T> | PreloadFileDiffResult<T>
@@ -26,7 +25,6 @@ function DiffSSRViewer<T>(props: SSRDiffFileProps<T>) {
2625
let container!: HTMLDivElement
2726
let fileDiffRef!: HTMLElement
2827
let fileDiffInstance: FileDiff<T> | undefined
29-
let sharedVirtualizer: NonNullable<ReturnType<typeof acquireVirtualizer>> | undefined
3028

3129
const ready = createReadyWatcher()
3230
const workerPool = useWorkerPool(props.diffStyle)
@@ -51,14 +49,6 @@ function DiffSSRViewer<T>(props: SSRDiffFileProps<T>) {
5149

5250
const getRoot = () => fileDiffRef?.shadowRoot ?? undefined
5351

54-
const getVirtualizer = () => {
55-
if (sharedVirtualizer) return sharedVirtualizer.virtualizer
56-
const result = acquireVirtualizer(container)
57-
if (!result) return
58-
sharedVirtualizer = result
59-
return result.virtualizer
60-
}
61-
6252
const setSelectedLines = (range: DiffFileProps<T>["selectedLines"], attempt = 0) => {
6353
const diff = fileDiffInstance
6454
if (!diff) return
@@ -92,27 +82,15 @@ function DiffSSRViewer<T>(props: SSRDiffFileProps<T>) {
9282

9383
onCleanup(observeViewerScheme(() => fileDiffRef))
9484

95-
const virtualizer = getVirtualizer()
9685
const annotations = local.annotations ?? local.preloadedDiff.annotations ?? []
97-
fileDiffInstance = virtualizer
98-
? new VirtualizedFileDiff<T>(
99-
{
100-
...createDefaultOptions(props.diffStyle),
101-
...others,
102-
...local.preloadedDiff.options,
103-
},
104-
virtualizer,
105-
virtualMetrics,
106-
workerPool,
107-
)
108-
: new FileDiff<T>(
109-
{
110-
...createDefaultOptions(props.diffStyle),
111-
...others,
112-
...local.preloadedDiff.options,
113-
},
114-
workerPool,
115-
)
86+
fileDiffInstance = new FileDiff<T>(
87+
{
88+
...createDefaultOptions(props.diffStyle),
89+
...others,
90+
...(local.preloadedDiff.options ?? {}),
91+
},
92+
workerPool,
93+
)
11694

11795
applyViewerScheme(fileDiffRef)
11896

@@ -163,8 +141,6 @@ function DiffSSRViewer<T>(props: SSRDiffFileProps<T>) {
163141
onCleanup(() => {
164142
clearReadyWatcher(ready)
165143
fileDiffInstance?.cleanUp()
166-
sharedVirtualizer?.release()
167-
sharedVirtualizer = undefined
168144
})
169145

170146
return (

packages/ui/src/components/file.tsx

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { sampledChecksum } from "@opencode-ai/shared/util/encode"
22
import {
3-
DEFAULT_VIRTUAL_FILE_METRICS,
43
type DiffLineAnnotation,
54
type FileContents,
65
type FileDiffMetadata,
@@ -10,10 +9,6 @@ import {
109
type FileOptions,
1110
type LineAnnotation,
1211
type SelectedLineRange,
13-
type VirtualFileMetrics,
14-
VirtualizedFile,
15-
VirtualizedFileDiff,
16-
Virtualizer,
1712
} from "@pierre/diffs"
1813
import { type PreloadFileDiffResult, type PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"
1914
import { createMediaQuery } from "@solid-primitives/media"
@@ -40,19 +35,10 @@ import {
4035
readShadowLineSelection,
4136
} from "../pierre/file-selection"
4237
import { createLineNumberSelectionBridge, restoreShadowTextSelection } from "../pierre/selection-bridge"
43-
import { acquireVirtualizer, virtualMetrics } from "../pierre/virtualizer"
4438
import { getWorkerPool } from "../pierre/worker"
4539
import { FileMedia, type FileMediaOptions } from "./file-media"
4640
import { FileSearchBar } from "./file-search"
4741

48-
const VIRTUALIZE_BYTES = 500_000
49-
50-
const codeMetrics = {
51-
...DEFAULT_VIRTUAL_FILE_METRICS,
52-
lineHeight: 24,
53-
fileGap: 0,
54-
} satisfies Partial<VirtualFileMetrics>
55-
5642
type SharedProps<T> = {
5743
annotations?: LineAnnotation<T>[] | DiffLineAnnotation<T>[]
5844
selectedLines?: SelectedLineRange | null
@@ -386,11 +372,6 @@ type AnnotationTarget<A> = {
386372
rerender: () => void
387373
}
388374

389-
type VirtualStrategy = {
390-
get: () => Virtualizer | undefined
391-
cleanup: () => void
392-
}
393-
394375
function useModeViewer(config: ModeConfig, adapter: ModeAdapter) {
395376
return useFileViewer({
396377
enableLineSelection: config.enableLineSelection,
@@ -532,64 +513,6 @@ function scrollParent(el: HTMLElement): HTMLElement | undefined {
532513
}
533514
}
534515

535-
function createLocalVirtualStrategy(host: () => HTMLDivElement | undefined, enabled: () => boolean): VirtualStrategy {
536-
let virtualizer: Virtualizer | undefined
537-
let root: Document | HTMLElement | undefined
538-
539-
const release = () => {
540-
virtualizer?.cleanUp()
541-
virtualizer = undefined
542-
root = undefined
543-
}
544-
545-
return {
546-
get: () => {
547-
if (!enabled()) {
548-
release()
549-
return
550-
}
551-
if (typeof document === "undefined") return
552-
553-
const wrapper = host()
554-
if (!wrapper) return
555-
556-
const next = scrollParent(wrapper) ?? document
557-
if (virtualizer && root === next) return virtualizer
558-
559-
release()
560-
virtualizer = new Virtualizer()
561-
root = next
562-
virtualizer.setup(next, next instanceof Document ? undefined : wrapper)
563-
return virtualizer
564-
},
565-
cleanup: release,
566-
}
567-
}
568-
569-
function createSharedVirtualStrategy(host: () => HTMLDivElement | undefined): VirtualStrategy {
570-
let shared: NonNullable<ReturnType<typeof acquireVirtualizer>> | undefined
571-
572-
const release = () => {
573-
shared?.release()
574-
shared = undefined
575-
}
576-
577-
return {
578-
get: () => {
579-
if (shared) return shared.virtualizer
580-
581-
const container = host()
582-
if (!container) return
583-
584-
const result = acquireVirtualizer(container)
585-
if (!result) return
586-
shared = result
587-
return result.virtualizer
588-
},
589-
cleanup: release,
590-
}
591-
}
592-
593516
function parseLine(node: HTMLElement) {
594517
if (!node.dataset.line) return
595518
const value = parseInt(node.dataset.line, 10)
@@ -688,7 +611,7 @@ function ViewerShell(props: {
688611
// ---------------------------------------------------------------------------
689612

690613
function TextViewer<T>(props: TextFileProps<T>) {
691-
let instance: PierreFile<T> | VirtualizedFile<T> | undefined
614+
let instance: PierreFile<T> | undefined
692615
let viewer!: Viewer
693616

694617
const [local, others] = splitProps(props, textKeys)
@@ -708,36 +631,12 @@ function TextViewer<T>(props: TextFileProps<T>) {
708631
return Math.max(1, total)
709632
}
710633

711-
const bytes = createMemo(() => {
712-
const value = local.file.contents as unknown
713-
if (typeof value === "string") return value.length
714-
if (Array.isArray(value)) {
715-
return value.reduce(
716-
// oxlint-disable-next-line no-base-to-string -- array parts coerced intentionally
717-
(sum, part) => sum + (typeof part === "string" ? part.length + 1 : String(part).length + 1),
718-
0,
719-
)
720-
}
721-
if (value == null) return 0
722-
// oxlint-disable-next-line no-base-to-string -- file contents cast to unknown, coercion is intentional
723-
return String(value).length
724-
})
725-
726-
const virtual = createMemo(() => bytes() > VIRTUALIZE_BYTES)
727-
728-
const virtuals = createLocalVirtualStrategy(() => viewer.wrapper, virtual)
729-
730634
const lineFromMouseEvent = (event: MouseEvent): MouseHit => mouseHit(event, parseLine)
731635

732636
const applySelection = (range: SelectedLineRange | null) => {
733637
const current = instance
734638
if (!current) return false
735639

736-
if (virtual()) {
737-
current.setSelectedLines(range)
738-
return true
739-
}
740-
741640
const root = viewer.getRoot()
742641
if (!root) return false
743642

@@ -836,10 +735,7 @@ function TextViewer<T>(props: TextFileProps<T>) {
836735
const notify = () => {
837736
notifyRendered({
838737
viewer,
839-
isReady: (root) => {
840-
if (virtual()) return root.querySelector("[data-line]") != null
841-
return root.querySelectorAll("[data-line]").length >= lineCount()
842-
},
738+
isReady: (root) => root.querySelectorAll("[data-line]").length >= lineCount(),
843739
onReady: () => {
844740
applySelection(viewer.lastSelection)
845741
viewer.find.refresh({ reset: true })
@@ -858,17 +754,11 @@ function TextViewer<T>(props: TextFileProps<T>) {
858754
createEffect(() => {
859755
const opts = options()
860756
const workerPool = getWorkerPool("unified")
861-
const isVirtual = virtual()
862-
863-
const virtualizer = virtuals.get()
864757

865758
renderViewer({
866759
viewer,
867760
current: instance,
868-
create: () =>
869-
isVirtual && virtualizer
870-
? new VirtualizedFile<T>(opts, virtualizer, codeMetrics, workerPool)
871-
: new PierreFile<T>(opts, workerPool),
761+
create: () => new PierreFile<T>(opts, workerPool),
872762
assign: (value) => {
873763
instance = value
874764
},
@@ -895,7 +785,6 @@ function TextViewer<T>(props: TextFileProps<T>) {
895785
onCleanup(() => {
896786
instance?.cleanUp()
897787
instance = undefined
898-
virtuals.cleanup()
899788
})
900789

901790
return <ViewerShell mode="text" viewer={viewer} class={local.class} classList={local.classList} />
@@ -991,8 +880,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
991880
adapter,
992881
)
993882

994-
const virtuals = createSharedVirtualStrategy(() => viewer.container)
995-
996883
const large = createMemo(() => {
997884
if (local.fileDiff) {
998885
const before = local.fileDiff.deletionLines.join("")
@@ -1055,7 +942,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1055942
createEffect(() => {
1056943
const opts = options()
1057944
const workerPool = large() ? getWorkerPool("unified") : getWorkerPool(props.diffStyle)
1058-
const virtualizer = virtuals.get()
1059945
const beforeContents = typeof local.before?.contents === "string" ? local.before.contents : ""
1060946
const afterContents = typeof local.after?.contents === "string" ? local.after.contents : ""
1061947
const done = preserve(viewer)
@@ -1070,10 +956,7 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1070956
renderViewer({
1071957
viewer,
1072958
current: instance,
1073-
create: () =>
1074-
virtualizer
1075-
? new VirtualizedFileDiff<T>(opts, virtualizer, virtualMetrics, workerPool)
1076-
: new FileDiff<T>(opts, workerPool),
959+
create: () => new FileDiff<T>(opts, workerPool),
1077960
assign: (value) => {
1078961
instance = value
1079962
},
@@ -1111,7 +994,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1111994
onCleanup(() => {
1112995
instance?.cleanUp()
1113996
instance = undefined
1114-
virtuals.cleanup()
1115997
dragSide = undefined
1116998
dragEndSide = undefined
1117999
})

0 commit comments

Comments
 (0)