Skip to content

Commit 0ff8c7f

Browse files
committed
refactor(chat): remove a needless alias and correct an eslint-disable reason
Self-audit for shortcuts, prompted by 'nothing hacky': - handlePaste kept `const prepared = preparedSelection`, an alias added only to avoid renaming two downstream lines. Uses the real name now. - The home.tsx drain's eslint-disable claimed handleContextAdd is 'a stable body function'. It is a body function, so it is a NEW value every render — the justification was false. Replaced with the actual reason: it is omitted to keep the drain one-shot, and doing so is harmless because consume() clears atomically, so a re-run would find nothing. Audited the rest of the diff for suppressions, casts and swallowed errors. The three catch blocks are documented graceful degradations with explicit fallbacks (row-drain failure, browsers rejecting a custom clipboard MIME mid-gesture, malformed clipboard JSON); the one double cast is a DataTransfer stub in a test.
1 parent 14b9ba6 commit 0ff8c7f

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/prompt-editor/use-prompt-editor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,14 +940,13 @@ export function usePromptEditor({
940940
: null
941941
if (preparedSelection) {
942942
e.preventDefault()
943-
const prepared = preparedSelection
944943
const selStart = textarea.selectionStart ?? valueRef.current.length
945944
const selEnd = textarea.selectionEnd ?? selStart
946945
const needsSpaceBefore = selStart > 0 && !/\s/.test(valueRef.current.charAt(selStart - 1))
947-
const insert = `${needsSpaceBefore ? ' ' : ''}@${prepared.label} `
946+
const insert = `${needsSpaceBefore ? ' ' : ''}@${preparedSelection.label} `
948947
textarea.setRangeText(insert, selStart, selEnd, 'end')
949948
const caret = selStart + insert.length
950-
contextManagementRef.current.addContext(prepared)
949+
contextManagementRef.current.addContext(preparedSelection)
951950
valueRef.current = textarea.value
952951
setValueState(textarea.value)
953952
requestAnimationFrame(() => textarea.setSelectionRange(caret, caret))

apps/sim/app/workspace/[workspaceId]/home/home.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ export function Home({ chatId, userName, userId, tableViewsEnabled }: HomeProps)
358358
const contexts = handoff.contexts ?? []
359359
for (const context of contexts) handleContextAdd(context)
360360
addMothershipContexts(contexts)
361-
// eslint-disable-next-line react-hooks/exhaustive-deps -- one-shot drain; handleContextAdd is a stable body function
361+
// `handleContextAdd` is a body function, so it is a new value every render;
362+
// listing it would re-run this drain on every render. Omitted deliberately to
363+
// keep it one-shot — and harmless either way, since `consume` clears the entry
364+
// atomically and any re-run would find nothing.
365+
// eslint-disable-next-line react-hooks/exhaustive-deps -- see above
362366
}, [chatId, workspaceId, sendMessage])
363367

364368
function resolveResourceFromContext(

0 commit comments

Comments
 (0)