mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 13:05:14 +03:00
fix(app): stop aborted signals from pinning disposed timeline DOM (#58432)
This commit is contained in:
committed by
GitHub
Unverified
parent
75adbe903c
commit
dddec8f3c1
@@ -2,6 +2,7 @@ import { Predicate } from "effect"
|
||||
import { createEffect, createMemo, createSignal, on, onCleanup, type Accessor } from "solid-js"
|
||||
import { createStore, reconcile } from "solid-js/store"
|
||||
import { useFilteredList } from "@opencode/ui/hooks"
|
||||
import { abort } from "@opencode/util/abort"
|
||||
import { createComposerAttachments, type ComposerAttachmentConfig } from "../attachments/attachments"
|
||||
import type { Upload } from "../attachments/uploads"
|
||||
import { resolveBlobUrl } from "@/runtime/persistence/drafts"
|
||||
@@ -163,15 +164,15 @@ export function createComposerEditor(input: {
|
||||
const [found, setFound] = createStore<{ query: string; files: ComposerSuggestion[] }>({ query: "", files: [] })
|
||||
let fileQuery: string | undefined
|
||||
let fileAbort = new AbortController()
|
||||
onCleanup(() => fileAbort.abort())
|
||||
onCleanup(() => abort(fileAbort))
|
||||
|
||||
// Debounced and abortable: each keystroke or close replaces the pending file search instead of queueing behind it.
|
||||
const findFiles = (query?: string) => {
|
||||
if (query === fileQuery) return
|
||||
fileAbort.abort()
|
||||
const abort = new AbortController()
|
||||
abort(fileAbort)
|
||||
const controller = new AbortController()
|
||||
fileQuery = query
|
||||
fileAbort = abort
|
||||
fileAbort = controller
|
||||
|
||||
if (query === undefined) return
|
||||
|
||||
@@ -179,14 +180,14 @@ export function createComposerEditor(input: {
|
||||
|
||||
const timer = setTimeout(
|
||||
() =>
|
||||
void Promise.resolve(input.searchContextFiles(query, abort.signal)).then(
|
||||
(files) => !abort.signal.aborted && setFound({ query, files }),
|
||||
void Promise.resolve(input.searchContextFiles(query, controller.signal)).then(
|
||||
(files) => !controller.signal.aborted && setFound({ query, files }),
|
||||
() => undefined,
|
||||
),
|
||||
150,
|
||||
)
|
||||
|
||||
abort.signal.addEventListener("abort", () => clearTimeout(timer), { once: true })
|
||||
controller.signal.addEventListener("abort", () => clearTimeout(timer), { once: true })
|
||||
}
|
||||
|
||||
const contextList = useFilteredList<ComposerSuggestion>({
|
||||
|
||||
@@ -22,6 +22,7 @@ import { showToast } from "@/shell/notifications/toast"
|
||||
import { formatServerError } from "@/runtime/server/errors"
|
||||
import { Skill } from "@opencode/schema/skill"
|
||||
import { Session } from "@opencode/schema/session"
|
||||
import { abort } from "@opencode/util/abort"
|
||||
import { parseSessionMention } from "@opencode/util/session-mention"
|
||||
import { createKnownServerSessions, createServerSessionEntries } from "@/shell/commands/palette"
|
||||
import { matchesSessionTitle } from "./session-match"
|
||||
@@ -68,7 +69,7 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
|
||||
const pathImages = new Map<string, Promise<string | undefined>>()
|
||||
const pathImageReads = new AbortController()
|
||||
onCleanup(() => {
|
||||
pathImageReads.abort()
|
||||
abort(pathImageReads)
|
||||
pathImages.forEach((url) => void url.then((value) => value && URL.revokeObjectURL(value)))
|
||||
})
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { abort } from "@opencode/util/abort"
|
||||
import { isLineRangeHash, parsePathLineSuffix } from "@opencode/util/path"
|
||||
import type { ReadMarkdownImage } from "../context/markdown"
|
||||
|
||||
@@ -73,7 +74,7 @@ export function createMarkdownImages(read: ReadMarkdownImage) {
|
||||
const paths = new Set(images.map((image) => image.dataset.localImage))
|
||||
entries.forEach((entry, path) => {
|
||||
if (paths.has(path)) return
|
||||
entry.controller.abort()
|
||||
abort(entry.controller)
|
||||
|
||||
if (entry.url) URL.revokeObjectURL(entry.url)
|
||||
entries.delete(path)
|
||||
@@ -114,7 +115,7 @@ export function createMarkdownImages(read: ReadMarkdownImage) {
|
||||
},
|
||||
dispose() {
|
||||
entries.forEach((entry) => {
|
||||
entry.controller.abort()
|
||||
abort(entry.controller)
|
||||
|
||||
if (entry.url) URL.revokeObjectURL(entry.url)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useI18n } from "@opencode/ui/context/i18n"
|
||||
import { abort } from "@opencode/util/abort"
|
||||
import { checksum } from "@opencode/util/encode"
|
||||
import {
|
||||
type ComponentProps,
|
||||
@@ -897,7 +898,7 @@ export function Markdown(
|
||||
})
|
||||
|
||||
onCleanup(() => {
|
||||
lifetime.abort()
|
||||
abort(lifetime)
|
||||
images?.dispose()
|
||||
|
||||
if (copyCleanup) copyCleanup()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { expect, test } from "bun:test"
|
||||
import { abort } from "./abort.js"
|
||||
|
||||
test("aborts with an AbortError that does not record the caller's stack", () => {
|
||||
const controller = new AbortController()
|
||||
function disposeComponent() {
|
||||
abort(controller)
|
||||
}
|
||||
|
||||
disposeComponent()
|
||||
|
||||
expect(controller.signal.aborted).toBe(true)
|
||||
expect(controller.signal.reason).toBeInstanceOf(DOMException)
|
||||
expect(controller.signal.reason.name).toBe("AbortError")
|
||||
expect(String(controller.signal.reason.stack)).not.toContain("disposeComponent")
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
// `controller.abort()` makes a new DOMException that records the caller's stack, and V8 keeps every frame's function
|
||||
// and closure alive until something reads `.stack`. Aborting from a Solid cleanup or update then pins the whole batch
|
||||
// it ran in, disposed computations and detached DOM included, for as long as the signal is reachable. This reason is
|
||||
// made once, so its stack holds only this module's load.
|
||||
const reason = new DOMException("signal is aborted without reason", "AbortError")
|
||||
|
||||
export function abort(controller: AbortController) {
|
||||
controller.abort(reason)
|
||||
}
|
||||
Reference in New Issue
Block a user