Repository navigation
Conversation
- search.astro: 非 200 走错误分支,ready/error 事件派发到 document(消费者只监听 document) - fetch-dedup/memos-adapter: 处理 finally 派生 Promise 的 rejection,避免未处理拒绝 - diagram-panzoom-script: reinit 前 AbortController 中止旧监听器 - immersive-reading-utils: 说明 TOC 按需重绑与全局监听一次性守卫的分工
👷 Deploy request for demo-firefly pending review.Visit the deploys page to approve it
|
审阅者指南实现为清理 Promise 添加拒绝处理,同时原样返回原始请求 Promise。
移除先前图表初始化时注册的中止监听器,并将每个控件和交互监听器关联到当前初始化的 signal。
为当前页面重新绑定目录导航,在初始化后更新可见状态,并保留全局监听器的一次性保护机制。
用户界面使 Pagefind 加载失败事件能够传递给文档级监听器,并让高级搜索组件处理 ready 或 error 事件。
提示和命令使用 Sourcery
自定义使用体验访问你的控制面板,即可:
获取帮助Original review guide in EnglishReviewer's GuideImplementationAttach rejection handling to the cleanup promises while returning the original request promises unchanged.
Abort listeners from prior diagram initializations and associate each control and interaction listener with the current initialization’s signal.
Rebind the TOC navigation for the current page, update visibility after initialization, and retain the one-time guard for global listeners.
UIMake Pagefind loading failures reach document-level listeners and have the advanced search component handle either ready or error events.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
你好——我发现了 4 个问题
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/utils/immersive-reading-utils.ts" line_range="205" />
<code_context>
IR.toc = document.getElementById("immersive-toc");
+ // TOC 容器随 Swup 换页被替换,须在每次 init 重绑;仅在首次 init 注册全局监听
bindImmersiveTOCNav();
- updateImmersiveReadingVisibility();
// 跨 Swup 切到另一篇文章时若仍在沉浸态,重建目录(SSR 锚点已过期)
</code_context>
<issue_to_address>
**Immersive controls keep stale visibility**
When initialization or Swup navigation occurs before a resize or another visibility update, `initImmersiveReading()` refreshes `IR.btn` without calling `updateImmersiveReadingVisibility()`, so the new button keeps its SSR `hide` class or stale visibility. Desktop readers cannot enter immersive reading when it is enabled with `defaultOn` false, and controls can remain visible where immersive reading is unavailable.
Call `updateImmersiveReadingVisibility()` after refreshing the page’s button references in `initImmersiveReading()`.
Also at `src/utils/immersive-reading-utils.ts:204`.
</issue_to_address>
### Comment 2
<location path="src/plugins/diagram-panzoom-script.js" line_range="34" />
<code_context>
container.dataset.pzInit = "true";
+ // reinit 时旧监听器须随旧控制栏一起移除,否则每次重试多留一组回调
+ if (container._pzAbort) container._pzAbort.abort();
+ container._pzAbort = new AbortController();
+ var signal = container._pzAbort.signal;
</code_context>
<issue_to_address>
**Diagram retries accumulate interaction handlers**
When a diagram container is reinitialized, `_diagramPanZoomReinit()` aborts the previous signal, but the container’s pointer and double-click listeners do not use it. Each retry leaves stale callbacks and targets attached, so a gesture runs multiple handlers and diagram interactions behave incorrectly.
Pass the current abort signal to every pointer and double-click listener registered on the container.
Also at `src/plugins/diagram-panzoom-script.js:35`, `src/plugins/diagram-panzoom-script.js:105-106`.
</issue_to_address>
### Comment 3
<location path="src/pages/search.astro" line_range="37" />
<code_context>
} catch (error) {
console.warn("Pagefind script not found or failed to load.");
- window.dispatchEvent(new Event('pagefindloaderror'));
+ document.dispatchEvent(new CustomEvent('pagefindloaderror'));
}
}
</code_context>
<issue_to_address>
**Search stays unusable after load failure**
When the Pagefind HEAD probe or script import fails, `AdvancedSearch` listens for `pagefindready` but not `pagefindloaderror`, so the failure event does not initialize it and `initialized` remains false. Searches return without querying Pagefind, leaving the search page unusable.
Handle `pagefindloaderror` in `AdvancedSearch` and initialize an appropriate failure or fallback state.
</issue_to_address>
### Comment 4
<location path="src/pages/search.astro" line_range="37" />
<code_context>
} catch (error) {
console.warn("Pagefind script not found or failed to load.");
- window.dispatchEvent(new Event('pagefindloaderror'));
+ document.dispatchEvent(new CustomEvent('pagefindloaderror'));
}
}
</code_context>
<issue_to_address>
**Concurrent loaders race initialization**
When the page-local and Navbar loader requests complete with different outcomes, the search page starts its own Pagefind load while `AdvancedSearch` also starts the Navbar loader. If those independent requests produce different outcomes, `Search.svelte` handles both the error and ready events, initializing twice; the Navbar loader can also replace a successfully loaded `window.pagefind` with its empty-result fallback, so search returns no results despite the other load succeeding.
Use one shared, deduplicated Pagefind loading promise and dispatch a single terminal event for its outcome.
</issue_to_address>Sourcery 评估
等待批准。 请先处理 4 项发现。
阻塞性发现:src/utils/immersive-reading-utils.ts:205、src/plugins/diagram-panzoom-script.js:34、src/pages/search.astro:37、src/pages/search.astro:37
Original comment in English
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/utils/immersive-reading-utils.ts" line_range="205" />
<code_context>
IR.toc = document.getElementById("immersive-toc");
+ // TOC 容器随 Swup 换页被替换,须在每次 init 重绑;仅在首次 init 注册全局监听
bindImmersiveTOCNav();
- updateImmersiveReadingVisibility();
// 跨 Swup 切到另一篇文章时若仍在沉浸态,重建目录(SSR 锚点已过期)
</code_context>
<issue_to_address>
**Immersive controls keep stale visibility**
When initialization or Swup navigation occurs before a resize or another visibility update, `initImmersiveReading()` refreshes `IR.btn` without calling `updateImmersiveReadingVisibility()`, so the new button keeps its SSR `hide` class or stale visibility. Desktop readers cannot enter immersive reading when it is enabled with `defaultOn` false, and controls can remain visible where immersive reading is unavailable.
Call `updateImmersiveReadingVisibility()` after refreshing the page’s button references in `initImmersiveReading()`.
Also at `src/utils/immersive-reading-utils.ts:204`.
</issue_to_address>
### Comment 2
<location path="src/plugins/diagram-panzoom-script.js" line_range="34" />
<code_context>
container.dataset.pzInit = "true";
+ // reinit 时旧监听器须随旧控制栏一起移除,否则每次重试多留一组回调
+ if (container._pzAbort) container._pzAbort.abort();
+ container._pzAbort = new AbortController();
+ var signal = container._pzAbort.signal;
</code_context>
<issue_to_address>
**Diagram retries accumulate interaction handlers**
When a diagram container is reinitialized, `_diagramPanZoomReinit()` aborts the previous signal, but the container’s pointer and double-click listeners do not use it. Each retry leaves stale callbacks and targets attached, so a gesture runs multiple handlers and diagram interactions behave incorrectly.
Pass the current abort signal to every pointer and double-click listener registered on the container.
Also at `src/plugins/diagram-panzoom-script.js:35`, `src/plugins/diagram-panzoom-script.js:105-106`.
</issue_to_address>
### Comment 3
<location path="src/pages/search.astro" line_range="37" />
<code_context>
} catch (error) {
console.warn("Pagefind script not found or failed to load.");
- window.dispatchEvent(new Event('pagefindloaderror'));
+ document.dispatchEvent(new CustomEvent('pagefindloaderror'));
}
}
</code_context>
<issue_to_address>
**Search stays unusable after load failure**
When the Pagefind HEAD probe or script import fails, `AdvancedSearch` listens for `pagefindready` but not `pagefindloaderror`, so the failure event does not initialize it and `initialized` remains false. Searches return without querying Pagefind, leaving the search page unusable.
Handle `pagefindloaderror` in `AdvancedSearch` and initialize an appropriate failure or fallback state.
</issue_to_address>
### Comment 4
<location path="src/pages/search.astro" line_range="37" />
<code_context>
} catch (error) {
console.warn("Pagefind script not found or failed to load.");
- window.dispatchEvent(new Event('pagefindloaderror'));
+ document.dispatchEvent(new CustomEvent('pagefindloaderror'));
}
}
</code_context>
<issue_to_address>
**Concurrent loaders race initialization**
When the page-local and Navbar loader requests complete with different outcomes, the search page starts its own Pagefind load while `AdvancedSearch` also starts the Navbar loader. If those independent requests produce different outcomes, `Search.svelte` handles both the error and ready events, initializing twice; the Navbar loader can also replace a successfully loaded `window.pagefind` with its empty-result fallback, so search returns no results despite the other load succeeding.
Use one shared, deduplicated Pagefind loading promise and dispatch a single terminal event for its outcome.
</issue_to_address>Sourcery assessment
Approval pending. 4 findings to address first.
Blocking findings: src/utils/immersive-reading-utils.ts:205, src/plugins/diagram-panzoom-script.js:34, src/pages/search.astro:37, src/pages/search.astro:37
- Share Navbar Pagefind loader with the search page and handle load failure. - Update immersive button visibility after init. - Abort diagram panzoom listeners when the diagram reinitializes.
背景
复核客户端生命周期时发现若干独立缺陷,本 PR 逐项修复。
变更
src/pages/search.astro):HEAD 探测非 200 时原本裸return,pagefindready/pagefindloaderror既不派发也派发到window;而消费者AdvancedSearch.svelte/Search.svelte只监听document。现在非 200 走既有 catch 分支,两个事件统一派发到document(与常驻 Navbar 加载器一致),失败时仍能结束搜索页加载态。src/utils/fetch-dedup.ts,src/utils/memos-adapter.ts):promise.finally(清理)产生的派生 Promise 在请求失败时无人处理,触发unhandledrejection。现在对派生 Promise 追加空 catch;原 Promise 仍原样返回给调用方,错误语义不变。src/utils/immersive-reading-utils.ts):initImmersiveReading()被astro:page-load每次触发,TOC 点击监听本应按需重绑(容器随换页替换),但补充注释明确全局监听只在__immersiveReadingInit守卫内注册,避免误读为泄漏。src/plugins/diagram-panzoom-script.js):window._diagramPanZoomReinit()重置pzInit后重绑控制栏按钮,每次重试遗留旧回调。现在每次 init 用AbortController先中止旧监听器,并把 signal 传给控制栏 click 监听。验证
pnpm run check:0 errors / 0 warnings / 0 hintsastro build:40 page(s) builtbiome check改动 5 文件:无 fixes applieddist/search/index.html中两处pagefindready/pagefindloaderror均已派发到document,与消费者监听目标一致。Sourcery 摘要
修复客户端搜索、请求去重、沉浸阅读和图表交互的生命周期问题,确保错误事件可达、请求失败后可安全清理,并避免监听器重复累积。
问题修复:
改进:
Original summary in English
Sourcery 总结
修复客户端对搜索加载、去重请求、沉浸式阅读和图表交互的生命周期处理。
Bug 修复:
增强功能:
Original summary in English
Summary by Sourcery
Fix client-side lifecycle handling for search loading, deduplicated requests, immersive reading, and diagram interactions.
Bug Fixes:
Enhancements: