DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(chat): mirror follow intent off :has() to fix WKWebView scroll lag (#1187) (#1189)
Hairy41863d8763a9
diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.mdindex db0f0f8e..80fb005e 100644--- a/docs/DEVELOPMENT.md+++ b/docs/DEVELOPMENT.md@@ -72,6 +72,10 @@ The deployment owns the root attribute. This patch does not disable motion by deThe [regression tests](<../test/scroll-follow-patch.test.ts>) compare the released class with the production replacement; Rust tests run the same JavaScript contract on the actual `apply_at` file output. These are logic checks, not M5 / multi-display GPU measurements or full browser pagination coverage. Performance claims still need a same-device before/after comparison.+## Chat follow anchor++[#1187](https://github.com/dsh-tauri/deepseek-harness-desktop/issues/1187) reports laggy scrolling and pointer movement in macOS WKWebView while the same page is fine in Chrome. The compatible chat bundle keys `overflow-anchor: none` off `[data-conversation-scroll]:has(.EvIC1a_root[data-chat-following-tail])`; WebKit re-runs selector matching over the whole conversation subtree on every node removal inside that scrollport, and the follow path removes and re-inserts nodes continuously. The [patch](<../src-tauri/src/service/patch/chat_follow_anchor.rs>) mirrors the committed follow intent onto the enclosing `[data-conversation-scroll]` from `ScrollFollow.bind`/`setFollowing` and switches the rule to a plain attribute selector. A scrollport can host several followers (main conversation and process groups), so the attribute reflects whether any of them is still following and is written only when that result changes, uses the same best-effort/idempotent/anchor-skip semantics as above, and the [regression tests](<../test/chat-follow-anchor-patch.test.ts>) replay the mirroring contract against the released and patched class.+## Runtime isolation| Mode | Harness data | Store | Default loopback port |diff --git a/docs/DEVELOPMENT.zh.md b/docs/DEVELOPMENT.zh.mdindex e59460d9..8c2e9c1e 100644--- a/docs/DEVELOPMENT.zh.md+++ b/docs/DEVELOPMENT.zh.md@@ -72,6 +72,10 @@ cargo test --manifest-path src-tauri/Cargo.toml --all-features --locked[回归测试](<../test/scroll-follow-patch.test.ts>)对比原版与生产替换体;Rust 测试执行真实 `apply_at` 文件产物上的同一套 JavaScript 契约。它们验证逻辑,不代表 M5 / 多屏 GPU 实测,也不覆盖完整浏览器分页界面;性能结论仍需同设备前后对照。+## 聊天跟随锚定++[#1187](https://github.com/dsh-tauri/deepseek-harness-desktop/issues/1187) 报告 macOS WKWebView 里滚动与指针移动慢半拍,同一页面在 Chrome 正常。兼容聊天包用 `[data-conversation-scroll]:has(.EvIC1a_root[data-chat-following-tail])` 决定 `overflow-anchor: none`,跟随期间滚动容器内每次节点移除都会让 WebKit 对整棵会话子树重做选择器匹配。桌面端[补丁](<../src-tauri/src/service/patch/chat_follow_anchor.rs>)在 `ScrollFollow.bind` / `setFollowing` 里把跟随意图镜像到外层 `[data-conversation-scroll]`,规则换成普通属性选择器。同一滚动容器可能有多个跟随实例(主会话、过程分组),属性由仍在前台跟随的实例共同决定,只在结果变化时写;解绑时按剩余实例重算。最佳努力、幂等、锚点缺失跳过与上文一致;[回归测试](<../test/chat-follow-anchor-patch.test.ts>)对原版与补丁后的类跑同一套镜像契约。+## 运行时隔离| 模式 | Harness 数据 | Store | 默认回环端口 |diff --git a/src-tauri/src/service/patch/chat_follow_anchor.rs b/src-tauri/src/service/patch/chat_follow_anchor.rsnew file mode 100644index 00000000..b8b03430--- /dev/null+++ b/src-tauri/src/service/patch/chat_follow_anchor.rs@@ -0,0 +1,133 @@+//! 会话滚动跟随的 `overflow-anchor` 补丁(issue #1187)。+//!+//! WKWebView 里只要锚定规则带 `:has()`,滚动跟随期间每次节点移除都要对整棵会话子树+//! 重做选择器匹配(采样中占比近四成,表现为滚动和指针移动都慢半拍)。跟随意图本来+//! 就由 JS 持有,这里把它镜像到外层滚动容器,让 CSS 改用普通属性选择器;Chrome 不受+//! 影响是因为 Blink 的 `:has()` 失效范围更窄。++use std::path::Path;++use crate::utils::{patch_core_file, patch_dsh, PatchOutcome};++const CLIENT: &str = "node_modules/@deepseek-ai/dsh-client-ui-chat/lib/client.js";++const ORIGINAL_CSS: &str = r#"[data-conversation-scroll]:has(.EvIC1a_root[data-chat-following-tail])"#;+const PATCHED_CSS: &str = r#"[data-conversation-scroll][data-chat-following-tail]"#;++const ORIGINAL_BIND: &str = r#" bind(element) {+ ScrollFollow.owners.set(element, this);+ return () => {+ if (ScrollFollow.owners.get(element) === this) ScrollFollow.owners.delete(element);+ };+ }"#;+const PATCHED_BIND: &str = r#" bind(element) {+ this.element = element;+ this.scrollport = element.closest("[data-conversation-scroll]");+ ScrollFollow.owners.set(element, this);+ this.followAnchor();+ return () => {+ if (ScrollFollow.owners.get(element) === this) {+ ScrollFollow.owners.delete(element);+ this.followAnchor();+ this.element = void 0;+ this.scrollport = void 0;+ }+ };+ }"#;++const ORIGINAL_FOLLOW: &str = r#" setFollowing(active) {+ this.following = active;+ if (!active) this.target = null;+ }"#;+const PATCHED_FOLLOW: &str = r#" setFollowing(active) {+ this.following = active;+ if (!active) this.target = null;+ this.followAnchor();+ }+ followAnchor() {+ const scrollport = this.scrollport;+ if (scrollport === void 0 || scrollport === null) return;+ let following = false;+ ScrollFollow.owners.forEach((owner) => {+ if (owner.following && owner.scrollport === scrollport) following = true;+ });+ if (scrollport.hasAttribute("data-chat-following-tail") === following) return;+ if (following) scrollport.setAttribute("data-chat-following-tail", "");+ else scrollport.removeAttribute("data-chat-following-tail");+ }"#;++fn patch_source(source: &str) -> PatchOutcome {+ let states = [+ (ORIGINAL_CSS, PATCHED_CSS),+ (ORIGINAL_BIND, PATCHED_BIND),+ (ORIGINAL_FOLLOW, PATCHED_FOLLOW),+ ];+ if states.iter().all(|(original, patched)| {+ source.matches(original).count() == 0 && source.matches(patched).count() == 1+ }) {+ return PatchOutcome::AlreadyPatched;+ }+ if states+ .iter()+ .any(|(original, patched)| source.matches(original).count() != 1 || source.matches(patched).count() != 0)+ {+ return PatchOutcome::AnchorMissing;+ }+ let patched = states+ .iter()+ .fold(source.to_string(), |source, (original, patched)| {+ source.replacen(original, patched, 1)+ });+ PatchOutcome::Patched(patched)+}++pub fn apply_at(core_dir: &Path) -> Result<(), String> {+ patch_core_file(core_dir, CLIENT, patch_source)+}++pub fn apply(app_handle: &tauri::AppHandle) -> Result<(), String> {+ patch_dsh(app_handle, CLIENT, patch_source)+}++#[cfg(test)]+mod tests {+ use super::*;++ fn released() -> String {+ format!(+ "<script>{}{}{}</script>",+ ORIGINAL_CSS, ORIGINAL_BIND, ORIGINAL_FOLLOW+ )+ }++ #[test]+ fn patches_follow_anchor_without_has() {+ let PatchOutcome::Patched(patched) = patch_source(&released()) else {+ panic!("released source should patch");+ };+ assert!(patched.contains(PATCHED_CSS));+ assert!(!patched.contains(":has(.EvIC1a_root"));+ assert!(patched.contains("this.followAnchor();"));+ assert!(!patched.contains(ORIGINAL_BIND));+ }++ #[test]+ fn patched_source_is_idempotent() {+ let PatchOutcome::Patched(patched) = patch_source(&released()) else {+ panic!("released source should patch");+ };+ assert!(matches!(patch_source(&patched), PatchOutcome::AlreadyPatched));+ }++ #[test]+ fn changed_css_anchor_is_skipped() {+ let source = released().replace(ORIGINAL_CSS, "");+ assert!(matches!(patch_source(&source), PatchOutcome::AnchorMissing));+ }++ #[test]+ fn changed_follow_method_is_skipped() {+ let source = released().replace("this.target = null;", "this.target = void 0;");+ assert!(matches!(patch_source(&source), PatchOutcome::AnchorMissing));+ }+}diff --git a/src-tauri/src/service/patch/mod.rs b/src-tauri/src/service/patch/mod.rsindex b6041a3c..c1d16669 100644--- a/src-tauri/src/service/patch/mod.rs+++ b/src-tauri/src/service/patch/mod.rs@@ -9,6 +9,7 @@//! `workspace_view` 等),挂点统一为 `service::workflow::launch`,均为最佳努力、//! 失败仅告警。+pub(crate) mod chat_follow_anchor;pub(crate) mod composer;pub(crate) mod conversation_draft;pub(crate) mod llm_session;@@ -36,12 +37,13 @@ use std::path::Path;/// 让编排层能看见哪一条出了问题。pub(crate) fn apply_all_at(core_dir: &Path) -> Result<(), String> {#[allow(clippy::type_complexity)]- let patches: [(&str, fn(&Path) -> Result<(), String>); 14] = [+ let patches: [(&str, fn(&Path) -> Result<(), String>); 15] = [("renderer", renderer::apply_at),("mcp_startup", mcp_startup::apply_at),("composer", composer::apply_at),("conversation_draft", conversation_draft::apply_at),("scroll_follow", scroll_follow::apply_at),+ ("chat_follow_anchor", chat_follow_anchor::apply_at),("mobile_composer", mobile_composer::apply_at),("mobile_sidebar", mobile_sidebar::apply_at),("session", session::apply_at),diff --git a/src-tauri/src/service/workflow/early_plan.rs b/src-tauri/src/service/workflow/early_plan.rsindex 7419f644..6e05f86a 100644--- a/src-tauri/src/service/workflow/early_plan.rs+++ b/src-tauri/src/service/workflow/early_plan.rs@@ -254,6 +254,10 @@ pub(super) fn prepare("scroll follow reduced-motion patch",patch::scroll_follow::apply_at,),+ (+ "chat follow anchor patch",+ patch::chat_follow_anchor::apply_at,+ ),("mobile composer patch", patch::mobile_composer::apply_at),("mobile sidebar patch", patch::mobile_sidebar::apply_at),("SessionStore.remove patch", patch::session::apply_at),diff --git a/src-tauri/src/service/workflow/launch.rs b/src-tauri/src/service/workflow/launch.rsindex 35918694..a3f8e2e8 100644--- a/src-tauri/src/service/workflow/launch.rs+++ b/src-tauri/src/service/workflow/launch.rs@@ -712,6 +712,9 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {if let Err(e) = crate::service::patch::scroll_follow::apply(&app_handle) {log::warn!("Scroll follow reduced-motion patch skipped: {e}");}+ if let Err(e) = crate::service::patch::chat_follow_anchor::apply(&app_handle) {+ log::warn!("Chat follow anchor patch skipped: {e}");+ }if let Err(e) = crate::service::patch::mobile_composer::apply(&app_handle) {log::warn!("mobile composer patch failed: {e}");}diff --git a/test/chat-follow-anchor-patch.test.ts b/test/chat-follow-anchor-patch.test.tsnew file mode 100644index 00000000..82edff19--- /dev/null+++ b/test/chat-follow-anchor-patch.test.ts@@ -0,0 +1,67 @@+import { spawnSync } from 'node:child_process'+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { resolve } from 'node:path'+import { afterEach, describe, expect, it } from 'vitest'++const rust = readFileSync(resolve('src-tauri/src/service/patch/chat_follow_anchor.rs'), 'utf8')+const fixturePath = resolve('test/fixtures/chat-follow-anchor.txt')+const fixture = readFileSync(fixturePath, 'utf8')++function anchor(name: string) {+ const original = rust.match(new RegExp(`const ORIGINAL_${name}: &str = r#"([\\s\\S]*?)"#;`))?.[1]+ const patched = rust.match(new RegExp(`const PATCHED_${name}: &str = r#"([\\s\\S]*?)"#;`))?.[1]+ if (!original || !patched)+ throw new Error(`Missing ${name} patch anchor`)+ return { original, patched }+}++const css = anchor('CSS')+const bind = anchor('BIND')+const follow = anchor('FOLLOW')+if (fixture.split(bind.original).length !== 2 || fixture.split(follow.original).length !== 2)+ throw new Error('Missing unique production follow-anchor patch')++let directory: string | undefined++afterEach(() => {+ if (directory)+ rmSync(directory, { recursive: true, force: true })+ directory = undefined+})++function runContract(path: string) {+ return spawnSync(+ process.execPath,+ ['--test-reporter=tap', resolve('test/fixtures/chat-follow-anchor-contract.mjs'), path],+ { encoding: 'utf8', timeout: 20000 },+ )+}++describe('chat follow anchor patch', () => {+ it('drops the ancestor :has() and mirrors the same attribute from JavaScript', () => {+ expect(css.original).toContain(':has(.EvIC1a_root[data-chat-following-tail])')+ expect(css.patched).toBe('[data-conversation-scroll][data-chat-following-tail]')+ expect(css.patched).not.toContain(':has(')+ expect(bind.patched).toContain('this.followAnchor();')+ expect(follow.patched).toContain('scrollport.setAttribute("data-chat-following-tail", "")')+ })++ it('satisfies the shared contract with the production replacement', () => {+ directory = mkdtempSync(resolve('test/.chat-follow-anchor-'))+ const target = resolve(directory, 'client.txt')+ const patched = fixture.replace(bind.original, bind.patched).replace(follow.original, follow.patched)+ writeFileSync(target, patched)+ const result = runContract(target)+ expect(result.error).toBeUndefined()+ expect(result.status, result.stdout + result.stderr).toBe(0)+ expect(result.stdout).toMatch(/# fail 0\b/)+ })++ it('rejects the released source that never mirrors the follow intent', () => {+ const result = runContract(fixturePath)+ expect(result.error).toBeUndefined()+ expect(result.status, result.stdout + result.stderr).toBe(1)+ expect(result.stdout).toContain('not ok 1 - following mirrors the intent onto the enclosing scrollport')+ expect(result.stdout).toMatch(/# fail [1-9]\d*\b/)+ })+})diff --git a/test/fixtures/chat-follow-anchor-contract.mjs b/test/fixtures/chat-follow-anchor-contract.mjsnew file mode 100644index 00000000..7f1d89f4--- /dev/null+++ b/test/fixtures/chat-follow-anchor-contract.mjs@@ -0,0 +1,105 @@+import assert from 'node:assert/strict'+import { readFileSync } from 'node:fs'+import process from 'node:process'+import { test } from 'node:test'+import { runInNewContext } from 'node:vm'++const source = readFileSync(process.argv[2], 'utf8')+const ScrollFollow = runInNewContext(`${source}\nScrollFollow`, {}, { timeout: 1000 })+const ATTRIBUTE = 'data-chat-following-tail'++function scrollport() {+ const attributes = new Set()+ const writes = []+ return {+ attributes,+ writes,+ hasAttribute: name => attributes.has(name),+ setAttribute(name, value) {+ writes.push(['set', name, value])+ attributes.add(name)+ },+ removeAttribute(name) {+ writes.push(['remove', name])+ attributes.delete(name)+ },+ }+}++function bind({ nested = true, port = scrollport() } = {}) {+ let attached = nested+ const element = {+ closest: selector => (attached && selector === '[data-conversation-scroll]' ? port : null),+ }+ const follow = new ScrollFollow()+ return {+ follow,+ port,+ detach: () => {+ attached = false+ },+ unbind: follow.bind(element),+ }+}++test('following mirrors the intent onto the enclosing scrollport', () => {+ const { follow, port } = bind()+ assert.equal(port.attributes.has(ATTRIBUTE), false)+ follow.setFollowing(true)+ assert.equal(port.attributes.has(ATTRIBUTE), true)+})++test('unchanged intent does not rewrite the mirror', () => {+ const { follow, port } = bind()+ follow.setFollowing(true)+ follow.setFollowing(true)+ follow.setFollowing(true)+ assert.deepEqual(port.writes, [['set', ATTRIBUTE, '']])+})++test('leaving the tail clears the mirror', () => {+ const { follow, port } = bind()+ follow.setFollowing(true)+ follow.setFollowing(false)+ assert.equal(port.attributes.has(ATTRIBUTE), false)+ assert.deepEqual(port.writes, [+ ['set', ATTRIBUTE, ''],+ ['remove', ATTRIBUTE],+ ])+})++test('releasing the scrollport clears the mirror', () => {+ const { follow, port, unbind } = bind()+ follow.setFollowing(true)+ unbind()+ assert.equal(port.attributes.has(ATTRIBUTE), false)+})++test('clearing works when the element is detached before release', () => {+ const { follow, port, detach, unbind } = bind()+ follow.setFollowing(true)+ assert.equal(port.attributes.has(ATTRIBUTE), true)+ detach()+ unbind()+ assert.equal(port.attributes.has(ATTRIBUTE), false)+})++test('without an enclosing conversation scrollport nothing is written', () => {+ const { follow, port } = bind({ nested: false })+ follow.setFollowing(true)+ assert.deepEqual(port.writes, [])+})++test('one follower leaving the tail keeps the mirror while another follows', () => {+ const shared = scrollport()+ const first = bind({ port: shared })+ first.follow.setFollowing(true)+ const second = bind({ port: shared })+ second.follow.setFollowing(true)+ second.follow.setFollowing(false)+ assert.equal(shared.attributes.has(ATTRIBUTE), true)+ second.unbind()+ assert.equal(shared.attributes.has(ATTRIBUTE), true)+ first.unbind()+ assert.equal(shared.attributes.has(ATTRIBUTE), false)+})diff --git a/test/fixtures/chat-follow-anchor.txt b/test/fixtures/chat-follow-anchor.txtnew file mode 100644index 00000000..7c858b63--- /dev/null+++ b/test/fixtures/chat-follow-anchor.txt@@ -0,0 +1,17 @@+var ScrollFollow = class ScrollFollow {+ constructor() {+ this.following = false;+ this.target = null;+ }+ bind(element) {+ ScrollFollow.owners.set(element, this);+ return () => {+ if (ScrollFollow.owners.get(element) === this) ScrollFollow.owners.delete(element);+ };+ }+ setFollowing(active) {+ this.following = active;+ if (!active) this.target = null;+ }+ };+ScrollFollow.owners = new Map();