Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

fix(client): land the sidebar drag on the state React renders

Fei24110c62c5f87081
diff --git a/ds-bot/client.js b/ds-bot/client.js
index eb083f15..0dcc0f40 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -9559,12 +9559,15 @@ function TeamSidebar(props) {
if (typeof document !== "undefined") chatRoom.setLeft(null);
}, []);
const settleTimer = (0, import_react18.useRef)(0);
+ const springTimer = (0, import_react18.useRef)(0);
const startDrag = (event) => {
if (event.button !== 0) return;
event.preventDefault();
clearTimeout(settleTimer.current);
+ clearTimeout(springTimer.current);
const grip = event.currentTarget;
const column = grip.parentElement;
+ delete column.dataset.folding;
grip.setPointerCapture?.(event.pointerId);
chatRoom.hold(true);
const columns2 = chatRoom.columns();
@@ -9572,7 +9575,6 @@ function TeamSidebar(props) {
const offLeft = frameSnap.collapsedWidth ?? 0;
let last = null;
let liveLeft = mode;
- let folded = false;
let done = false;
const write = (at) => {
const width = at.left === "rail" ? RAIL_WIDTH : at.width;
@@ -9581,27 +9583,36 @@ function TeamSidebar(props) {
const push = Math.max(0, (at.left === "open" ? width : RAIL_WIDTH) - offLeft);
for (const col of columns2) col.style.setProperty("margin-left", `${push}px`, "important");
};
+ let springUntil = 0;
+ const springOff = () => {
+ springUntil = 0;
+ delete column.dataset.folding;
+ for (const col of columns2) col.style.setProperty("transition", "none", "important");
+ };
+ const springOn = () => {
+ column.dataset.folding = "";
+ for (const col of columns2) col.style.setProperty("transition", `margin-left ${SPRING_SHAPE.duration}ms ${SPRING_SHAPE.easing}`, "important");
+ springUntil = performance.now() + SPRING_SHAPE.duration;
+ clearTimeout(springTimer.current);
+ springTimer.current = setTimeout(springOff, SPRING_SHAPE.duration);
+ };
const track = (x) => {
last = dragColumn(x, window.innerWidth);
if (last.left !== liveLeft) {
- if (!folded && !reducedMotion()) {
- folded = true;
- column.dataset.folding = "";
- for (const col of columns2) col.style.setProperty("transition", `margin-left ${SPRING_SHAPE.duration}ms ${SPRING_SHAPE.easing}`, "important");
- }
liveLeft = last.left;
+ if (!reducedMotion()) springOn();
setDrag(last);
}
write(last);
};
const onMove = (move) => track(move.clientX);
const finish = () => {
+ clearTimeout(springTimer.current);
if (column.isConnected && last !== null) chatRoom.setLeft(Math.max(0, (last.left === "open" ? last.width : RAIL_WIDTH) - offLeft));
for (const col of columns2) {
col.style.removeProperty("margin-left");
col.style.removeProperty("transition");
}
- column.style.removeProperty("width");
column.style.removeProperty("--bt-lc-w");
delete column.dataset.folding;
chatRoom.hold(false);
@@ -9627,8 +9638,8 @@ function TeamSidebar(props) {
actions.setSidebarPref?.("open");
actions.setLeftDrawer?.(last.left === "drawer");
}
- if (!folded) finish();
- else settleTimer.current = setTimeout(finish, SPRING_SHAPE.duration + 60);
+ if (springUntil === 0) finish();
+ else settleTimer.current = setTimeout(finish, Math.max(0, springUntil - performance.now()) + 60);
};
grip.addEventListener("pointermove", onMove);
for (const name of ends) grip.addEventListener(name, onEnd);
diff --git a/ds-bot/src/client/sidebar.js b/ds-bot/src/client/sidebar.js
index c870a510..2fbb8f36 100644
--- a/ds-bot/src/client/sidebar.js
+++ b/ds-bot/src/client/sidebar.js
@@ -339,15 +339,21 @@ export function TeamSidebar(props) {
// Per frame the drag writes the column's own inline style and each conversation
// column's inline margin — the same path the panel's resize takes — so nothing
// re-renders or restyles the chat while the pointer moves. A render only happens
- // when the drag crosses the rail's snap line, and the first crossing arms the
- // spring (`data-folding`) so the fold glides instead of jumping.
+ // when the drag crosses the rail's snap line, and the spring (`data-folding`)
+ // rides that switch alone: it comes off when the switch settles, so a drag that
+ // keeps going afterwards follows the cursor frame by frame again.
const settleTimer = useRef(0)
+ const springTimer = useRef(0)
const startDrag = (event) => {
if (event.button !== 0) return
event.preventDefault()
clearTimeout(settleTimer.current)
+ clearTimeout(springTimer.current)
const grip = event.currentTarget
const column = grip.parentElement
+ // A re-grab can land while a previous spring still stands: the new drag owns
+ // the column from here, so its fold state starts clean.
+ delete column.dataset.folding
grip.setPointerCapture?.(event.pointerId)
chatRoom.hold(true)
const columns = chatRoom.columns()
@@ -355,7 +361,6 @@ export function TeamSidebar(props) {
const offLeft = frameSnap.collapsedWidth ?? 0
let last = null
let liveLeft = mode
- let folded = false
let done = false
const write = (at) => {
const width = at.left === 'rail' ? RAIL_WIDTH : at.width
@@ -364,26 +369,40 @@ export function TeamSidebar(props) {
const push = Math.max(0, (at.left === 'open' ? width : RAIL_WIDTH) - offLeft)
for (const col of columns) col.style.setProperty('margin-left', `${push}px`, 'important')
}
+ // A snap crossing arms the spring for the switch's glide; the timer takes it
+ // back off once the switch has had its duration.
+ let springUntil = 0
+ const springOff = () => {
+ springUntil = 0
+ delete column.dataset.folding
+ for (const col of columns) col.style.setProperty('transition', 'none', 'important')
+ }
+ const springOn = () => {
+ column.dataset.folding = ''
+ for (const col of columns) col.style.setProperty('transition', `margin-left ${SPRING_SHAPE.duration}ms ${SPRING_SHAPE.easing}`, 'important')
+ springUntil = performance.now() + SPRING_SHAPE.duration
+ clearTimeout(springTimer.current)
+ springTimer.current = setTimeout(springOff, SPRING_SHAPE.duration)
+ }
const track = (x) => {
last = dragColumn(x, window.innerWidth)
if (last.left !== liveLeft) {
- if (!folded && !reducedMotion()) {
- folded = true
- column.dataset.folding = ''
- for (const col of columns) col.style.setProperty('transition', `margin-left ${SPRING_SHAPE.duration}ms ${SPRING_SHAPE.easing}`, 'important')
- }
liveLeft = last.left
+ if (!reducedMotion()) springOn()
setDrag(last)
}
write(last)
}
const onMove = (move) => track(move.clientX)
// The rules and props take the landed geometry back over; while the fold's
- // spring still runs this waits it out so the landing does not snap.
+ // spring still runs this waits it out so the landing does not snap. The
+ // inline `width` stays: it is the landed geometry, and React writes its width
+ // prop only when the value changes, so removing it would leave the edge at
+ // its CSS fallback (57px on the rail).
const finish = () => {
+ clearTimeout(springTimer.current)
if (column.isConnected && last !== null) chatRoom.setLeft(Math.max(0, (last.left === 'open' ? last.width : RAIL_WIDTH) - offLeft))
for (const col of columns) { col.style.removeProperty('margin-left'); col.style.removeProperty('transition') }
- column.style.removeProperty('width')
column.style.removeProperty('--bt-lc-w')
delete column.dataset.folding
chatRoom.hold(false)
@@ -405,8 +424,8 @@ export function TeamSidebar(props) {
actions.setSidebarPref?.('open')
actions.setLeftDrawer?.(last.left === 'drawer')
}
- if (!folded) finish()
- else settleTimer.current = setTimeout(finish, SPRING_SHAPE.duration + 60)
+ if (springUntil === 0) finish()
+ else settleTimer.current = setTimeout(finish, Math.max(0, springUntil - performance.now()) + 60)
}
grip.addEventListener('pointermove', onMove)
for (const name of ends) grip.addEventListener(name, onEnd)
diff --git a/ds-bot/test/sidebar-switch.test.js b/ds-bot/test/sidebar-switch.test.js
index 59109a99..0c05300a 100644
--- a/ds-bot/test/sidebar-switch.test.js
+++ b/ds-bot/test/sidebar-switch.test.js
@@ -36,11 +36,12 @@ const react = {
}
const module = { exports: {} }
const viewport = { innerWidth: 1280 }
-runInNewContext(outputFiles[0].text, {
+const sandbox = {
module, exports: module.exports,
require: name => (name === 'react' ? react : {}),
window: viewport,
-})
+}
+runInNewContext(outputFiles[0].text, sandbox)
const { SHELL_CSS, SIDEBAR_CSS, TeamSidebar } = module.exports
function navigationSidebar(wide, { leftDrawer = false } = {}) {
@@ -435,3 +436,101 @@ test('the Bot footer holds the account and the return button only', () => {
const ids = [...source.matchAll(/shadow\('sidebar\.footer\.action',\s*\{[^}]*?id:\s*['"]([^'"]+)['"]/g)].map(match => match[1])
assert.deepEqual(ids.sort(), ['bot-account', 'bot-return'])
})
+
+// The edge drag writes the column and the chat's margins straight into the page, so these
+// run it on a jsdom page with real timers. The sandbox gets the page and the timers only
+// while a drag runs; the release then re-renders the sidebar at the state it stored.
+async function edgeDrag({ start, reduced = false }, run) {
+ const dom = new JSDOM('<!doctype html><body><div class="x_centerCol"></div><div class="bt-leftcol"><div class="bt-leftcol-grip"></div></div></body>')
+ const { document } = dom.window
+ const column = document.querySelector('.bt-leftcol')
+ const grip = column.querySelector('.bt-leftcol-grip')
+ const center = document.querySelector('.x_centerCol')
+ const frame = { viewport: 1280, sidebarWidth: start.width, collapsedWidth: 0, collapsed: false }
+ const stored = { pref: start.pref }
+ const roster = { bots: [], rooms: [], agents: [], byId: {}, ready: true }
+ const actions = {
+ setPanelYield() {}, setLeftDrawer() {}, toggleSidebar() {}, toggleLeftHidden() {},
+ setSidebarWidth: (width) => { frame.sidebarWidth = width },
+ setSidebarPref: (pref) => { stored.pref = pref },
+ }
+ const render = () => TeamSidebar({
+ wide: false, actions,
+ useRoster: pick => pick(roster), useUi: pick => pick({ unread: {} }), useRegistry: pick => pick({}),
+ useSessions: pick => pick({ ids: [], byId: {} }), useUpdate: () => ({}),
+ useFrame: pick => pick(frame), useSidebarPref: pick => pick(stored.pref),
+ })
+ const leftColumn = () => {
+ const find = (node) => {
+ if (Array.isArray(node)) return node.map(find).find(Boolean)
+ if (!node || typeof node !== 'object') return undefined
+ return node.type?.name === 'LeftColumn' ? node : find(node.props?.children)
+ }
+ return find(render()).props
+ }
+ const globals = { document, performance, setTimeout, clearTimeout, requestAnimationFrame: next => setTimeout(next, 0), cancelAnimationFrame: clearTimeout, CSS: { escape: value => value } }
+ Object.assign(sandbox, globals)
+ viewport.innerWidth = 1280
+ if (reduced) viewport.matchMedia = () => ({ matches: true })
+ const pointer = (type, clientX) => grip.dispatchEvent(new dom.window.MouseEvent(type, { clientX }))
+ try {
+ return await run({
+ column, center, leftColumn,
+ press: () => leftColumn().onGrip({ button: 0, pointerId: 1, currentTarget: grip, preventDefault() {} }),
+ move: clientX => pointer('pointermove', clientX),
+ release: clientX => pointer('pointerup', clientX),
+ settle: ms => new Promise(resolve => setTimeout(resolve, ms)),
+ })
+ } finally {
+ for (const name of Object.keys(globals)) delete sandbox[name]
+ delete viewport.matchMedia
+ }
+}
+
+// After the drag ends the column's own width must be the one the sidebar renders for the
+// state it stored, or the edge sits at the CSS fallback (57px on the rail).
+test('a drag that ends on the rail leaves the column at the rail width', async () => {
+ await edgeDrag({ start: { pref: 'open', width: 350 } }, async ({ column, leftColumn, press, move, release, settle }) => {
+ press()
+ for (const x of [300, 250, 200, 150, 100]) move(x)
+ release(100)
+ await settle(800)
+ assert.equal(leftColumn().mode, 'rail')
+ assert.equal(leftColumn().width, 88)
+ assert.equal(column.style.width, '88px')
+ assert.equal(column.hasAttribute('data-folding'), false)
+ })
+})
+
+test('a reduced-motion drag that unfolds the rail lands at the dragged width', async () => {
+ await edgeDrag({ start: { pref: 'rail', width: 280 }, reduced: true }, async ({ column, leftColumn, press, move, release }) => {
+ press()
+ for (const x of [120, 160, 200, 260, 330]) move(x)
+ release(330)
+ assert.equal(leftColumn().mode, 'open')
+ assert.equal(leftColumn().width, 330)
+ assert.equal(column.style.width, '330px')
+ assert.equal(column.hasAttribute('data-folding'), false)
+ })
+})
+
+// The spring rides the snap switch only: after it settles the same drag follows the cursor
+// frame by frame, and the chat's margin takes no transition of its own.
+test('after a snap the spring stops and the drag follows the cursor', async () => {
+ await edgeDrag({ start: { pref: 'rail', width: 280 } }, async ({ column, center, leftColumn, press, move, release, settle }) => {
+ press()
+ move(200)
+ assert.equal(column.dataset.folding, '')
+ await settle(800)
+ assert.equal(column.hasAttribute('data-folding'), false)
+ assert.equal(center.style.getPropertyValue('transition'), 'none')
+ for (const x of [280, 300, 330]) {
+ move(x)
+ assert.equal(column.style.width, `${x}px`)
+ }
+ release(330)
+ await settle(800)
+ assert.equal(leftColumn().width, 330)
+ assert.equal(column.style.width, '330px')
+ })
+})