Skip to content

Commit b85f2c0

Browse files
committed
fix(client): 侧栏记忆入口锚定新会话行,防生态插件挤位 (#130)
任务看板/技能中心等生态插件(linxin666 sidebar-entry-core 系)把入口 插在新会话行后且后插入者在上;我们固定在 regionArea 之前,被打成入口 组末尾的孤立位(issue #130 截图:记忆按钮被顶到任务看板/技能中心下)。 - 占位锚点改为紧跟新会话行(logoRow/直接子按钮判定与生态 core 一致, 锚点不可靠时回退 regionArea 之前的旧位置) - MutationObserver 里幂等重排:已在锚点位不写 DOM;生态插件后插入时 搬回,对方只在自身节点被移除时才重插,不会来回争抢 - 关键边界:created 已紧跟锚点时 target 即 created 自身,必须短路返回 ——insertBefore(x, x) 在 Chromium 里不是 no-op,会触发 childList mutation 造成观察器自激风暴冻死 SPA(本地实测踩中并已验证修复) web 8788 junction 直载实测:新建会话 → 记忆 → 任务看板 → SSH → 技能中心 → 工作区,顺序稳定无漂移,入口点击正常打开记忆面板。
1 parent df61f13 commit b85f2c0

2 files changed

Lines changed: 65 additions & 9 deletions

File tree

‎dsh-mneme/lib/client.js‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,8 +3741,10 @@ window.__ModuleLoader__.load({
37413741

37423742
// --- Sidebar entry: 工作区上方的记忆按钮 ---
37433743
// 注册仍在 sidebar.footer.action(list 插槽)——它既是 React 树的挂载
3744-
// 锚点,也是 portal 失效时的原位回退。真实按钮 portal 插到 regionArea
3745-
// (工作区列表容器)之前,即「新会话」按钮下方、工作区上方。
3744+
// 锚点,也是 portal 失效时的原位回退。真实按钮 portal 插到「新会话」行
3745+
// 之后、插件入口组的最前:任务看板/技能中心等生态插件也把入口插在新会话
3746+
// 行后(它们的后插入者在上),若我们固定在 regionArea 之前就会被打成
3747+
// 入口组末尾的孤立位(issue #130),所以观察器发现错位就搬回锚点位。
37463748
// 几何对齐方案:读取宿主「新会话」按钮的实时 className 原样套用,再用
37473749
// 我们的修饰类覆盖配色(次级观感)。这样展开态与收起态(rail)都直接
37483750
// 继承宿主自己的盒模型与间距——宿主改版/缩进动画零位移,无需硬编码。
@@ -3769,6 +3771,32 @@ window.__ModuleLoader__.load({
37693771
const findNative = (region) =>
37703772
region.parentElement.querySelector('[class*="newSession"]')
37713773
|| region.previousElementSibling;
3774+
// 占位锚点:新会话行(现役外壳里 newSession 按钮嵌在 logoRow 内,
3775+
// 旧外壳是根的直接子按钮)。判定与生态插件的 sidebar-entry-core
3776+
// 一致;锚点不可靠时回退到 regionArea 之前的旧位置。
3777+
const findAnchor = (region) => {
3778+
const parent = region.parentElement;
3779+
const btn = parent.querySelector('[class*="newSession"]');
3780+
if (!btn) return null;
3781+
const row = btn.closest('[class*="logoRow"]');
3782+
if (row && row.parentElement === parent) return row;
3783+
return btn.parentElement === parent ? btn : null;
3784+
};
3785+
// 占位规则:紧跟新会话行(插件入口组的顶部),幂等——已在锚点位就
3786+
// 不动 DOM。生态插件后插入时会把我们压下去一位,观察器里重排搬回;
3787+
// 它们只在自身节点被移除时才重插,不会与我们来回争抢。
3788+
// 注意 created 已紧跟锚点时 target 即 created 自身,必须直接返回:
3789+
// insertBefore(x, x) 在 Chromium 里不是 no-op,会触发 mutation 造成
3790+
// 观察器自激风暴、冻死整个 SPA。
3791+
const place = (region) => {
3792+
const parent = region.parentElement;
3793+
if (!parent) return;
3794+
const anchor = findAnchor(region);
3795+
const target = anchor ? anchor.nextSibling : region;
3796+
if (target === created) return;
3797+
if (created.parentElement === parent && created.nextSibling === target) return;
3798+
parent.insertBefore(created, target);
3799+
};
37723800
const attempt = () => {
37733801
const region = document.querySelector('[class*="regionArea"]');
37743802
if (region && region.parentElement) {
@@ -3778,12 +3806,13 @@ window.__ModuleLoader__.load({
37783806
// 否则 portal 按钮会停留在捕获时刻的旧类上(宽度/对齐失配)。
37793807
created = document.createElement("div");
37803808
created.dataset.pluginEntry = "@modusensus/dsh-mneme";
3781-
region.parentElement.insertBefore(created, region);
3809+
place(region);
37823810
setHost(created);
37833811
setNativeCls(findNative(region)?.className || "");
37843812
mo = new MutationObserver(() => {
37853813
const cur = document.querySelector('[class*="regionArea"]');
37863814
if (!cur || !cur.parentElement) return;
3815+
place(cur);
37873816
const cls = findNative(cur)?.className || "";
37883817
setNativeCls((prev) => (prev === cls ? prev : cls));
37893818
});

‎dsh-mneme/test/client.test.js‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ test("trigger renders a wide row or a rail icon from the wide flag", () => {
121121
);
122122
});
123123

124-
// The entry lives ABOVE the workspaces region: the real button is portalled
125-
// just before the host's regionArea container (below New Session, above the
126-
// workspace list), while the sidebar.footer.action registration remains as
127-
// the React anchor and the in-place fallback when the host markup changes.
124+
// The entry lives at the top of the plugin-entry group: the real button is
125+
// portalled right after the host's New-Session row (above the entries other
126+
// plugins inject there), while the sidebar.footer.action registration remains
127+
// as the React anchor and the in-place fallback when the host markup changes.
128128
test("sidebar entry portals above the workspaces region with footer fallback", () => {
129129
assert.ok(
130130
clientSource.includes('ctx.slots.inject("sidebar.footer.action"'),
@@ -139,8 +139,8 @@ test("sidebar entry portals above the workspaces region with footer fallback", (
139139
"the portal must anchor at the host's regionArea container"
140140
);
141141
assert.ok(
142-
clientSource.includes("insertBefore(created, region)"),
143-
"the entry must sit immediately above the workspaces region"
142+
clientSource.includes("insertBefore(created, target)"),
143+
"the entry must be placed through the idempotent place() helper"
144144
);
145145
assert.ok(
146146
clientSource.includes("if (!host) return fallback;"),
@@ -160,6 +160,33 @@ test("sidebar entry portals above the workspaces region with footer fallback", (
160160
);
161161
});
162162

163+
// Issue #130: ecosystem plugins (task board, skill explorer, …) inject their
164+
// own entries right after the New-Session row, and late inserters land above
165+
// earlier ones — a fixed "before regionArea" slot degrades into the tail of
166+
// that group, detaching the memory button from its familiar top spot. The
167+
// entry therefore (a) resolves the same anchor as the ecosystem's shared
168+
// sidebar-entry-core (logoRow row, legacy direct-child button), (b) re-asserts
169+
// its slot from the existing observer, and (c) stays idempotent — the anchor
170+
// check short-circuits before any DOM write, so observers never ping-pong.
171+
test("entry re-asserts the New-Session-adjacent slot against ecosystem entries", () => {
172+
assert.ok(
173+
clientSource.includes(`btn.closest('[class*="logoRow"]')`),
174+
"the anchor must resolve the New-Session logo row like the ecosystem core"
175+
);
176+
assert.ok(
177+
clientSource.includes("const target = anchor ? anchor.nextSibling : region;"),
178+
"the entry must sit right after the New-Session row, falling back before regionArea"
179+
);
180+
assert.ok(
181+
clientSource.includes("if (created.parentElement === parent && created.nextSibling === target) return;"),
182+
"placement must be idempotent so the observer never writes on steady state"
183+
);
184+
assert.ok(
185+
/place\(cur\);\s*\n\s*const cls = findNative\(cur\)/.test(clientSource),
186+
"the observer must re-place the entry on childList churn, not just re-sync the class"
187+
);
188+
});
189+
163190
// Three alignment/softness guarantees born from field feedback: (a) the
164191
// portalled entry keeps tracking the live New-Session class (host and skin
165192
// rewrite it asynchronously, so a mount-time snapshot goes stale), (b) it

0 commit comments

Comments
 (0)