LocalAI/core/http/react-ui/src/hooks
LocalAI [bot] 11d5bd0cc3
fix(react-ui/chat): stop wiping selection on every /api/operations poll (#9904) (#9917)
useOperations() was calling setOperations() with a fresh array on every
1s poll, even when the payload was identical. In React 19 the DOM diff
no longer short-circuits dangerouslySetInnerHTML on equal __html, so the
forced Chat re-render re-assigned innerHTML on every assistant message
once per second — wiping any text the user had selected.

Skip the state update when the serialised operations payload is
unchanged, and switch loading/error to functional setters so they also
short-circuit at the source.

Also fixes the chat copy button on plain HTTP: navigator.clipboard is
undefined in non-secure contexts (a common LXC+Docker deployment), but
the previous code called it unconditionally and showed a success toast
regardless. Routed Chat, AgentChat and CanvasPanel through a new
copyToClipboard() helper that uses navigator.clipboard when available
and falls back to a hidden-textarea + execCommand('copy') trick that
browsers still honour outside secure contexts. The fallback preserves
the user's existing selection.

Regression coverage in e2e/chat-polling-selection.spec.js: a
MutationObserver counts mutations on the assistant content node across
3s of polling (must be 0); the copy test stubs out navigator.clipboard
and asserts that execCommand('copy') is invoked.


Assisted-by: claude-opus-4-7-1m

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-05-21 12:17:51 +02:00
..
useAgentChat.js feat(ui): Interactive model config editor with autocomplete (#9149) 2026-04-07 14:42:23 +02:00
useAudioPeaks.js feat: add LocalVQE backend and audio transformations UI (#9640) 2026-05-04 22:07:11 +02:00
useAutocomplete.js feat(ui): Interactive model config editor with autocomplete (#9149) 2026-04-07 14:42:23 +02:00
useChat.js fix: inject text-file content into chat completions messages (#9896) 2026-05-20 01:00:32 +02:00
useCodeMirror.js feat(ui): Interactive model config editor with autocomplete (#9149) 2026-04-07 14:42:23 +02:00
useConfigMetadata.js feat(ui): Interactive model config editor with autocomplete (#9149) 2026-04-07 14:42:23 +02:00
useDebounce.js feat(ui): Interactive model config editor with autocomplete (#9149) 2026-04-07 14:42:23 +02:00
useDistributedMode.js feat(distributed): per-node backend installation from the gallery 2026-04-26 22:05:18 +00:00
useGalleryEnrichment.js feat(react-ui): polish Manage page with kebab menus and gallery rows 2026-04-26 20:33:49 +00:00
useMCPClient.js fix(ui): Move routes to /app to avoid conflict with API endpoints (#8978) 2026-03-13 21:38:18 +01:00
useMediaCapture.js feat: add biometrics UI (#9524) 2026-04-24 08:50:34 +02:00
useMediaHistory.js feat: add LocalVQE backend and audio transformations UI (#9640) 2026-05-04 22:07:11 +02:00
useModels.js fix(react-ui): stop Manage page from blanking on auto-refresh; show real model use cases 2026-04-26 19:35:39 +00:00
useObjectUrl.js feat: add LocalVQE backend and audio transformations UI (#9640) 2026-05-04 22:07:11 +02:00
useOperations.js fix(react-ui/chat): stop wiping selection on every /api/operations poll (#9904) (#9917) 2026-05-21 12:17:51 +02:00
useResources.js feat(ui): move to React for frontend (#8772) 2026-03-05 21:47:12 +01:00
useUserMap.js feat: add users and authentication support (#9061) 2026-03-19 21:40:51 +01:00
useVramEstimate.js feat(ui): Interactive model config editor with autocomplete (#9149) 2026-04-07 14:42:23 +02:00