Skip to content

Commit cb29742

Browse files
committed
fix(app): remove pierre diff virtualization
1 parent 039c601 commit cb29742

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 & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { sampledChecksum } from "@opencode-ai/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)
@@ -707,34 +630,12 @@ function TextViewer<T>(props: TextFileProps<T>) {
707630
return Math.max(1, total)
708631
}
709632

710-
const bytes = createMemo(() => {
711-
const value = local.file.contents as unknown
712-
if (typeof value === "string") return value.length
713-
if (Array.isArray(value)) {
714-
return value.reduce(
715-
(sum, part) => sum + (typeof part === "string" ? part.length + 1 : String(part).length + 1),
716-
0,
717-
)
718-
}
719-
if (value == null) return 0
720-
return String(value).length
721-
})
722-
723-
const virtual = createMemo(() => bytes() > VIRTUALIZE_BYTES)
724-
725-
const virtuals = createLocalVirtualStrategy(() => viewer.wrapper, virtual)
726-
727633
const lineFromMouseEvent = (event: MouseEvent): MouseHit => mouseHit(event, parseLine)
728634

729635
const applySelection = (range: SelectedLineRange | null) => {
730636
const current = instance
731637
if (!current) return false
732638

733-
if (virtual()) {
734-
current.setSelectedLines(range)
735-
return true
736-
}
737-
738639
const root = viewer.getRoot()
739640
if (!root) return false
740641

@@ -833,10 +734,7 @@ function TextViewer<T>(props: TextFileProps<T>) {
833734
const notify = () => {
834735
notifyRendered({
835736
viewer,
836-
isReady: (root) => {
837-
if (virtual()) return root.querySelector("[data-line]") != null
838-
return root.querySelectorAll("[data-line]").length >= lineCount()
839-
},
737+
isReady: (root) => root.querySelectorAll("[data-line]").length >= lineCount(),
840738
onReady: () => {
841739
applySelection(viewer.lastSelection)
842740
viewer.find.refresh({ reset: true })
@@ -855,17 +753,11 @@ function TextViewer<T>(props: TextFileProps<T>) {
855753
createEffect(() => {
856754
const opts = options()
857755
const workerPool = getWorkerPool("unified")
858-
const isVirtual = virtual()
859-
860-
const virtualizer = virtuals.get()
861756

862757
renderViewer({
863758
viewer,
864759
current: instance,
865-
create: () =>
866-
isVirtual && virtualizer
867-
? new VirtualizedFile<T>(opts, virtualizer, codeMetrics, workerPool)
868-
: new PierreFile<T>(opts, workerPool),
760+
create: () => new PierreFile<T>(opts, workerPool),
869761
assign: (value) => {
870762
instance = value
871763
},
@@ -892,7 +784,6 @@ function TextViewer<T>(props: TextFileProps<T>) {
892784
onCleanup(() => {
893785
instance?.cleanUp()
894786
instance = undefined
895-
virtuals.cleanup()
896787
})
897788

898789
return <ViewerShell mode="text" viewer={viewer} class={local.class} classList={local.classList} />
@@ -988,8 +879,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
988879
adapter,
989880
)
990881

991-
const virtuals = createSharedVirtualStrategy(() => viewer.container)
992-
993882
const large = createMemo(() => {
994883
if (local.fileDiff) {
995884
const before = local.fileDiff.deletionLines.join("")
@@ -1052,7 +941,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1052941
createEffect(() => {
1053942
const opts = options()
1054943
const workerPool = large() ? getWorkerPool("unified") : getWorkerPool(props.diffStyle)
1055-
const virtualizer = virtuals.get()
1056944
const beforeContents = typeof local.before?.contents === "string" ? local.before.contents : ""
1057945
const afterContents = typeof local.after?.contents === "string" ? local.after.contents : ""
1058946
const done = preserve(viewer)
@@ -1067,10 +955,7 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1067955
renderViewer({
1068956
viewer,
1069957
current: instance,
1070-
create: () =>
1071-
virtualizer
1072-
? new VirtualizedFileDiff<T>(opts, virtualizer, virtualMetrics, workerPool)
1073-
: new FileDiff<T>(opts, workerPool),
958+
create: () => new FileDiff<T>(opts, workerPool),
1074959
assign: (value) => {
1075960
instance = value
1076961
},
@@ -1108,7 +993,6 @@ function DiffViewer<T>(props: DiffFileProps<T>) {
1108993
onCleanup(() => {
1109994
instance?.cleanUp()
1110995
instance = undefined
1111-
virtuals.cleanup()
1112996
dragSide = undefined
1113997
dragEndSide = undefined
1114998
})

0 commit comments

Comments
 (0)