GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: #101 OGP fetch に AbortController を実装して cancel 可能化 by ymnao · Pull Request #137 · ymnao/scripta

Conversation

@ymnao

@ymnao ymnao commented Jun 4, 2026

Copy link
Copy Markdown
Owner

概要

OGP fetch の cancel 経路を実装し、文書切替時に in-flight な fetch を中断可能にする。さらに複数 view が同じ URL の loading entry を共有する状況下で起きる膠着・誤 abort・stuck race を順次解消した。

関連 Issue

Closes #101

移行 Stage

  • Stage 5: OGP / PDF / アップデート

変更内容

中核機能 (commit d0d58da)

  • httpFetch に signal?: AbortSignal を追加。pre-aborted は即時 reject、in-flight 中は req.destroy で既存の close/error 経路に合流
  • ogp.ts に in-flight Map + cancelOgpFetch を追加。ogp:cancel IPC handler を追加
  • preload で window.api.ogpCancel(...) を contextBridge 経由公開、renderer ラッパ cancelOgpFetch を src/lib/commands.ts に追加
  • LinkCardDecorationPlugin.destroy() で in-flight cancel。文書切替は AppLayout の editorKey 増分で MarkdownEditor が unmount → plugin destroy で自然に発火

/simplify レビュー反映 (commit 72a8571)

  • ErrorKind に \"ABORTED\" を追加。serializeIpcError は err.name を IPC 越しに保たないため、renderer 側 err.name === \"AbortError\" 検出はデッドコードだった。fetchOgpImpl で AbortError → StructuredError(\"ABORTED\") に変換し、renderer は getErrorKind(err) === \"ABORTED\" で判別

レビュー指摘 P2-1 / P2-2 / P3 反映 (commit 447a9ca)

  • P2-2 (URL キー Map の後勝ち上書きで後発を誤 abort): in-flight Map を Map<requestId, AbortController> に変更。IPC を ogp:fetch(requestId, url) / ogp:cancel(requestId) に。renderer は crypto.randomUUID() で requestId を発行し、自身の requestId だけを cancel
  • P2-1 (ABORTED catch が共有 loading を壊す): ABORTED catch で ogpCache.delete をやめ、LOADING_STALE_MS = 60s の stale 検出を導入
  • P3 (DNS 中の abort 効かず最大 5s 残留): fetchWithRedirects ループ頭で signal.aborted を再チェック

追加レビュー反映 (commit de48ae1)

  • P2 (stuck loading で active view が無期限膠着): CacheEntry.loading に owner requestId を持たせ、ABORTED 時は自分が開始した loading だけを ogpCache.delete し、直後に window.dispatchEvent で scripta:ogp-cache-invalidated を broadcast。他 plugin の listener が view.dispatch を発火 → 即時 re-fetch
  • P3 (DNS lookup 中の abort): pinSafeLookup / lookupWithTimeout に optional signal を追加し、Promise.race の参加者として abort を加える。ogp.ts から signal を伝播し、catch は controller.signal.aborted も判定対象にする

完了通知の broadcast 統一 (commit c3f2d72)

  • P2-A (成功通知が開始元 view にしか届かない): ABORTED だけでなく loaded / error 完了でも broadcastOgpCacheInvalidated を発火し、待機中の他 view を即時に起こす
  • P2-B (destroy 後の late-success で loading が膠着): success / error の cache 更新と broadcast は destroyed フラグに関係なく実行(listener 側の destroyed 判定で自身の view dispatch は自動的に skip される)
  • 自身の view.dispatch({}) を完了 handler から削除し、listener 経由に統一

動作確認

  • typecheck (pnpm typecheck) green
  • lint (pnpm lint) green
  • unit test (pnpm test) — 1964 passed / 2 skipped
  • e2e renderer-only (pnpm test:e2e) — 160 passed
  • build (pnpm build) green
  • legacy-residue (pnpm check:legacy-residue) green
  • 実 Electron 上での動作確認: pnpm dev 起動 → 外部 URL を含む md を開き、loading 中に文書切替 → 元に戻して再 fetch されることを目視確認

補足

実 Electron e2e (pnpm test:e2e:electron) はローカル sandbox 環境では Mach port 権限エラーで launch できないため、CI 上での実行に委ねる。

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ymnao added 5 commits June 4, 2026 00:38
@ymnao
fix: #101 OGP fetch に AbortController を実装して cancel 可能化
d0d58da
- httpFetch に signal?: AbortSignal を追加。pre-aborted は即時 reject、in-flight 中の abort
  は req.destroy で発火し既存の close/error 経路で reject に合流する
- ogp.ts に URL→Set<AbortController> の in-flight Map と cancelOgpFetch を追加。
  fetchOgpImpl は controller を 1 つ作って Map に register、finally で必ず unregister
- ogp:cancel IPC handler を追加し preload で window.api.ogpCancel(url) として公開、
  renderer 側ラッパ cancelOgpFetch を src/lib/commands.ts に追加
- LinkCardDecorationPlugin.destroy() で fetchingUrls 全件に対し cancelOgpFetch を発行。
  AbortError catch では cache を error 状態にせず entry を削除して次回 retry を許可
- 文書切替は AppLayout で editorKey が増分されて MarkdownEditor が unmount するため、
  plugin destroy が必ず発火する → 別途 hook で cancel する必要は無い
- e2e / vitest の api mock に ogpCancel を追加

Closes #101
@ymnao
refactor: #101 OGP cancel 経路を ErrorKind="ABORTED" 採用+ Map<url, AbortC…
72a8571
…ontroller> 単純化

/simplify の指摘反映:

- ErrorKind に "ABORTED" を追加(src/types/errors.ts, src/lib/errors.ts)。serializeIpcError
  は err.name を IPC 越しに保たないため、renderer 側の err.name === "AbortError" 検出は
  デッドコードだった。fetchOgpImpl で AbortError → StructuredError("ABORTED") へ変換し、
  renderer は getErrorKind(err) === "ABORTED" で判別する
- inFlight Map を Set<AbortController> から AbortController 単一値へ簡素化。register/
  unregister helpers を削除し、unregister は identity check(後発上書き時の race を許容)
- fetchOgpImpl の test-only signal? 引数を削除。テストは cancelOgpFetch 経路で同等の
  カバレッジを確保
- link-cards destroy() の snapshot-then-clear を単純な for...of + clear() に
- 冗長な justification コメントを 1 行化
- fetchWithRedirects の signal.aborted 早期 throw を削除(httpFetch の pre-aborted で十分)
- link-cards.test の view.destroy() 後の mounted.pop() を削除(afterEach の destroy は
  idempotent)
@ymnao
fix: #101 OGP cancel を requestId ベース化+ loading entry 巻き添え防止+ DNS 中 ab…
447a9ca
…ort 対策

レビュー指摘 (P2-1 / P2-2 / P3) を反映:

P2-2: cancel が他 view の後発 request を誤 abort する問題
- main: inFlight Map のキーを URL → requestId に変更
- IPC: ogp:fetch(requestId, url) / ogp:cancel(requestId)
- preload + commands.ts + e2e mock も requestId シグネチャへ更新
- renderer: 各 fetch ごとに crypto.randomUUID() を発行し、destroy 時は自身の
  requestId だけを cancel する

P2-1: ABORTED catch が共有 loading entry を消して他 view の card を空にする問題
- renderer の ABORTED catch では ogpCache を触らない(loading entry は他 plugin
  が完了待ち中の可能性があるため)
- 開始者が cancel された等で stuck になった loading 用に LOADING_STALE_MS = 60s
  を導入。古い loading は次の update で別 plugin が re-fetch する

P3: DNS / pinSafeLookup 中の abort が効かず最大 5s 残る問題
- fetchWithRedirects のループ頭で signal.aborted チェックを復活(少なくとも次の
  hop の DNS には進まない、文書切替時の即時性を確保)

テスト:
- requestId-scoped cancel で他 req に影響しないことを担保するユニットテスト追加
- link-cards.test を requestId シグネチャへ更新
@ymnao
fix: #101 loading owner 識別+ DNS lookup 中の abort 対応で残存 race を解消
de48ae1
P2 (新しい): cancel 後の stuck loading で active view が無期限に膠着する問題
- CacheEntry.loading に owner requestId を持たせる
- ABORTED catch では「自分が開始した loading」だけを ogpCache.delete し、他 view
  には影響させない
- delete 直後に window.dispatchEvent で scripta:ogp-cache-invalidated を broadcast、
  生存中の他 plugin が listener 経由で view.dispatch を発火 → fetchMissingOgp で
  即時 re-fetch する。これにより「LOADING_STALE_MS=60s 待ち」が hot path から外れ、
  fallback として残るだけになる
- LinkCardDecorationPlugin の constructor で listener 登録、destroy で removeEventListener

P3: DNS lookup 中の abort が効かず最大 REQUEST_TIMEOUT_MS 残る問題
- pinSafeLookup / lookupWithTimeout に optional signal を追加
- Promise.race の参加者として「signal abort」を加え、DNS 待ち中の cancel に即応
- ogp.ts が pinSafeLookup(host, timeout, signal) で signal を伝播
- ogp.ts の catch は AbortError instance に加え controller.signal.aborted も判定し、
  DNS-abort 経由(カスタム ABORT_ERR エラー)も ABORTED kind へ変換

テスト:
- ssrf-guard.test に「pre-aborted signal で即時 reject」「mid-DNS-lookup abort」を追加
- link-cards.test に「ABORTED catch が cache 削除 + broadcast を発火する」を追加
@ymnao
fix: #101 全 fetch completion で broadcast 発火+ destroyed でも cache 更新
c3f2d72
loading entry を plugin 間で共有しているのに通知が開始者ローカルに閉じている問題を
解消するため、ABORTED だけでなく loaded / error 完了でも cache invalidation を broadcast
する。また destroy 後に fetch が成功で resolve する race でも cache を必ず更新する。

P2-A: 成功完了の通知が開始元 view にしか届かない
- 旧コードは then() で `view.dispatch({})` のみ呼んでおり、loading を共有している
  他 view (同 URL を含む別 EditorView) には通知されなかった → 他 view は次の編集 /
  viewport change まで空カードのまま
- 完了経路 (loaded / error) で broadcastOgpCacheInvalidated を発火し、生存中の他
  plugin の listener から view.dispatch を再発火させる(abort と同じ機構)
- 自身の view 再描画も listener 経由に統一(重複した明示 view.dispatch を削除)

P2-B: destroy 後の成功 resolve で loading が更新されない
- 旧 then() は `if (this.destroyed) return` を cache 更新より前に置いていた → cancel
  と通信完了の race で成功が勝つと loading のまま放置され、待機 view が膠着
- cache 更新と broadcast は destroyed フラグに関係なく実行する。listener 側の
  destroyed 判定で自分の view へは dispatch しない(他 view への通知だけ走る)

合わせて broadcastOgpCacheInvalidated ヘルパを抽出し、3 経路で共有。

テスト:
- successful fetch が broadcast を発火することを検証
- destroy 後の late-success でも broadcast が走ることを検証
- 既存テストの URL を test ごとにユニーク化(モジュールスコープな ogpCache の
  汚染防止)
Copilot AI review requested due to automatic review settings June 4, 2026 16:44
Copilot AI reviewed Jun 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ymnao
ymnao merged commit 8b0f6f6 into main Jun 4, 2026
7 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ymnao
ymnao deleted the fix/ogp-cancel-abort-controller branch June 4, 2026 17:01
ymnao added a commit that referenced this pull request Jun 5, 2026
@ymnao @claude
docs: CHANGELOG を v0.2.0 リリース内容に更新
0598509
- Fixed にバグ修正クラスタをロールアップ追記 (#116 #117 #120 #124 #130 #131 #132 #134 #135 #136 #137)
- Added に手動アップデートチェック (#98 → #138) を追記
- Dependencies を Phase α 反映の実バージョンに更新
  (electron 42.3.3 / biome 2.4.16 / zustand 5.0.14 / js-yaml 4.2.0 /
   dompurify 3.4.8 / marked 18.0.4 / lucide-react 1.17.0 /
   @codemirror/view 6.43.0 / vite 8.0.14 / vitest 4.1.7)
- リリース日を _(unreleased)_ に、旧リポ表記を scripta-tauri (private) に、
  footer URL を ymnao/scripta に修正

Co-Authored-By: Claude Opus 4.8 <[email protected]>
ymnao added a commit that referenced this pull request Jun 5, 2026
@ymnao @claude
release: v0.2.0 (Electron 版初回リリース) (#61)
be27030
* release: v0.2.0

- package.json:version 0.0.0 → 0.2.0
- CHANGELOG.md 新設(旧 Tauri 版から Electron への完全書き直し版として
  Added / Changed / Fixed / Dependencies / Security / 既知の制限 を記載)

closes #27

* docs: v0.2.0 リリース運用注釈と README の表現を release-ready に更新

レビュー指摘反映:
- README.md: "v0.2.0 を予定" / "リリース後 ... 取得できる予定" を
  リリース後にも valid な表現へ書き換え(merge → tag push 後に
  Releases ページが publish される前提)
- docs/parity-checklist.md § 12: 「必須 4 項目は tag push 前に
  手動検証で pass させ、検証ログを Release Notes に追記する」
  というリリース運用を冒頭に明示

* docs: CHANGELOG リリース日と parity-checklist リリース運用を実態に合わせる

レビュー指摘反映:
- CHANGELOG.md: リリース日を 2026-05-13 → 2026-05-14 (publish/tag 日に揃える)
- docs/parity-checklist.md § 12: release.yml が tag push 後に
  draft Release を `--generate-notes` で自動生成する流れに合わせ、
  「Release Notes 追記 → tag push」を「tag push → draft 自動生成
  → 生成された draft に検証ログ追記 → publish」の正しい順序へ修正

* docs: CHANGELOG を v0.2.0 リリース内容に更新

- Fixed にバグ修正クラスタをロールアップ追記 (#116 #117 #120 #124 #130 #131 #132 #134 #135 #136 #137)
- Added に手動アップデートチェック (#98 → #138) を追記
- Dependencies を Phase α 反映の実バージョンに更新
  (electron 42.3.3 / biome 2.4.16 / zustand 5.0.14 / js-yaml 4.2.0 /
   dompurify 3.4.8 / marked 18.0.4 / lucide-react 1.17.0 /
   @codemirror/view 6.43.0 / vite 8.0.14 / vitest 4.1.7)
- リリース日を _(unreleased)_ に、旧リポ表記を scripta-tauri (private) に、
  footer URL を ymnao/scripta に修正

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

fix: OGP fetch に AbortController を実装して cancel 可能化

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ymnao
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.