Skip to content

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

Keep the composer's "+" hooks unconditional

Fei24113259beaaafdf
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 9b175630..2755331b 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -10569,6 +10569,11 @@ function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
window.removeEventListener("keydown", onKey, true);
};
}, [open]);
+ const place = (0, import_react20.useMemo)(() => {
+ if (!shown || !button.current) return null;
+ const rect = button.current.getBoundingClientRect();
+ return { left: rect.left, bottom: viewBottom() - rect.top + 8 };
+ }, [shown, open, tick]);
const target = roster.byId?.[sessionId]?.id ?? roster.roomsById?.[sessionId]?.id;
if (sessionId === void 0 || target === void 0) return null;
const fileInput = () => button.current?.closest("[data-composer-card]")?.querySelector("input[type=file]");
@@ -10592,11 +10597,6 @@ function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
actions.referenceChat(sessionId, inputActions?.captureInsertion?.());
};
const canReference = typeof inputActions?.captureInsertion === "function" && actions.canReferenceChat();
- const place = (0, import_react20.useMemo)(() => {
- if (!shown || !button.current) return null;
- const rect = button.current.getBoundingClientRect();
- return { left: rect.left, bottom: viewBottom() - rect.top + 8 };
- }, [shown, open, tick]);
return (0, import_react20.createElement)(
import_react20.Fragment,
null,
diff --git a/ds-bot/src/client/composer.js b/ds-bot/src/client/composer.js
index 08d3b669..1ea7632d 100644
--- a/ds-bot/src/client/composer.js
+++ b/ds-bot/src/client/composer.js
@@ -121,6 +121,15 @@ export function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
window.addEventListener('keydown', onKey, true)
return () => { window.removeEventListener('mousedown', onDown, true); window.removeEventListener('keydown', onKey, true) }
}, [open])
+ // Hooks stay above the early return below: the roster may not know the Bot yet, and a
+ // render that skips a hook breaks the composer's slot when the roster arrives.
+ // Anchored to the "+" each render: the visible viewport can move (on-screen
+ // keyboard) while the menu is open.
+ const place = useMemo(() => {
+ if (!shown || !button.current) return null
+ const rect = button.current.getBoundingClientRect()
+ return { left: rect.left, bottom: viewBottom() - rect.top + 8 }
+ }, [shown, open, tick])
const target = roster.byId?.[sessionId]?.id ?? roster.roomsById?.[sessionId]?.id
if (sessionId === undefined || target === undefined) return null
const fileInput = () => button.current?.closest('[data-composer-card]')?.querySelector('input[type=file]')
@@ -144,13 +153,6 @@ export function ComposerPlus({ sessionId, inputActions, useRoster, actions }) {
actions.referenceChat(sessionId, inputActions?.captureInsertion?.())
}
const canReference = typeof inputActions?.captureInsertion === 'function' && actions.canReferenceChat()
- // Anchored to the "+" each render: the visible viewport can move (on-screen
- // keyboard) while the menu is open.
- const place = useMemo(() => {
- if (!shown || !button.current) return null
- const rect = button.current.getBoundingClientRect()
- return { left: rect.left, bottom: viewBottom() - rect.top + 8 }
- }, [shown, open, tick])
return h(Fragment, null,
h('button', {
ref: button, type: 'button', className: 'bt-plus', 'aria-label': t('Add'), title: t('Add'),
diff --git a/ds-bot/test/composer-plus.test.js b/ds-bot/test/composer-plus.test.js
new file mode 100644
index 00000000..d01e49b8
--- /dev/null
+++ b/ds-bot/test/composer-plus.test.js
@@ -0,0 +1,54 @@
+import assert from 'node:assert/strict'
+import { test } from 'node:test'
+import { fileURLToPath } from 'node:url'
+import { runInNewContext } from 'node:vm'
+import { build } from 'esbuild'
+
+// The composer's "+" bundled with a React stand-in that counts hook calls. React needs a
+// component to call the same hooks on every render: one render that calls a hook the
+// previous render did not is an error, and the composer's slot drops the "+" for good.
+const { outputFiles } = await build({
+ entryPoints: [fileURLToPath(new URL('../src/client/composer.js', import.meta.url))],
+ bundle: true, format: 'cjs', platform: 'browser', write: false, logLevel: 'silent',
+ external: ['react', 'react-dom'],
+})
+let hooks = 0
+const react = {
+ Fragment: 'fragment',
+ createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }),
+ useState: initial => { hooks += 1; return [initial, () => {}] },
+ useRef: current => { hooks += 1; return { current } },
+ useEffect: () => { hooks += 1 },
+ useLayoutEffect: () => { hooks += 1 },
+ useMemo: make => { hooks += 1; return make() },
+}
+const module = { exports: {} }
+runInNewContext(outputFiles[0].text, {
+ module, exports: module.exports,
+ require: name => (name === 'react' ? react : name === 'react-dom' ? { createPortal: node => node } : {}),
+})
+const { ComposerPlus } = module.exports
+
+// Renders the "+" for a chat whose Bot is in the roster as `roster` says, and counts its hook calls.
+function render(roster) {
+ hooks = 0
+ const tree = ComposerPlus({
+ sessionId: 'chief', useRoster: select => select(roster),
+ actions: { canReferenceChat: () => false },
+ })
+ return { tree, hooks }
+}
+
+test('the "+" calls the same hooks whether or not its roster knows the Bot yet', () => {
+ const roster = { ready: false }
+ const unknown = render(roster)
+ roster.byId = { chief: { id: 'chief' } }
+ const known = render(roster)
+ roster.byId = {}
+ const forgotten = render(roster)
+ assert.equal(unknown.tree, null)
+ assert.equal(known.tree.type, 'fragment')
+ assert.equal(forgotten.tree, null)
+ assert.equal(known.hooks, unknown.hooks)
+ assert.equal(forgotten.hooks, unknown.hooks)
+})