refactor: stop routing Composer internal state through 12 DOM CustomEvents #463
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman#463
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Code-quality audit (P2).
frontend/src/components/assistant/Composer.tsx— two effects inside the same component communicate by dispatching and listening for DOMCustomEvents oninputRef.current.Dispatch side (
:571-574,:605-625,:652-654,:688,:710-714,:724-733,:752):Listen side (
:826-852):12 distinct event names:
oc-agent-picker-open,oc-bash-mode,oc-clear-files,oc-clear-images,oc-help-open,oc-model-picker-open,oc-paste-images,oc-skill-picker-open,oc-slash-close,oc-slash-nav,oc-slash-select,oc-slash-update.Why it matters
Internal state transitions are routed through the DOM.
detailisany, so none of it is type-checked; a renamed event or a changed payload shape fails silently at runtime. It is also a major contributor toComposerImpl's complexity score of 82 (ESLint limit 20), and shares a root cause with the ~25 hand-rolled prop-to-ref mirrors in the same file and thecomposerPropsEqualstaleness bug (composerMemo.ts:56, complexity 58).The reason these were introduced — stale closures in long-lived listener effects — no longer applies. React Compiler is enabled (
vite.config.ts:100) anduseEffectEventis already used in the codebase (frontend/src/lib/useClickOutside.ts:8). One cleanup fixes three problems.Suggested fix
useReducertransitions in the component, wrapping listener callbacks inuseEffectEventwhere a stable identity is needed.composerPropsEqualonce the mirrors are gone — it may become unnecessary under React Compiler.Acceptance criteria
oc-*CustomEvents dispatched or listened to withinComposer.tsx.ComposerImplcomplexity below 40.Effort: L.