Fix/settings edit hook issues#2860
Merged
dokterbob merged 2 commits intoChainlit:mainfrom Apr 1, 2026
Merged
Conversation
added 2 commits
March 26, 2026 17:25
…ger edit event when the edit comes from the user
hayescode
approved these changes
Apr 1, 2026
Contributor
hayescode
left a comment
There was a problem hiding this comment.
Reviewed via Codex
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR was implemented in collaboration with @tonca, many thanks to him !
Summary
Improves chat settings behavior around live edits (
on_settings_edit), session vs UI state, and Reset / Cancel after dynamic schema updates from the server.Problems
ChatSettings.send()and committed sessionsend()always calledset_chat_settings, so using it from@cl.on_settings_editto refresh widgets also overwrotesession.chat_settings. Committed settings should only change on submit (chat_settings_change/on_settings_update), not on every in-form edit.Spurious
chat_settings_editeventsThe modal used
watch()+useEffectto emit edits. Any form update—includingreset()after a serverchat_settingspush—could emit again, so the backend could see duplicate or misleading edit events.Reset / Cancel vs “when I opened”
Reset used
chat_settingsDefaultValue(current schemainitials), not the state when the panel opened. After a server-driven refresh, Reset and Cancel could leave the new widget list while trying to revert values.What we changed
Backend
ChatSettings.refresh()— Pushes the samechat_settingspayload assend(), but does not callset_chat_settings, so sessionchat_settingsstays unchanged until the user confirms.send()— Unchanged behavior: still updates session and emits; shared_inputs_as_dicts()keeps payload building in one place.test_chat_settings_refreshassertsset_chat_settingsis not called andchat_settingsis emitted.Frontend
watch+useEffectfor edits.setFieldValuenow callssetValuetheneditChatSettings(getValues()), soreset()/ Recoil sync do not emit edits. Applied in modal and sidebar.useChatSettingsSnapshotAtOpencaptureschatSettingsValueandchatSettingsInputswhen the panel opens (not on every prop change while open).restoreSnapshot()writescloneDeepsnapshots back intochatSettingsInputsStateandchatSettingsValueState, so schema and values both match pre-open state; existinguseEffect→reset(chatSettingsValue)keeps react-hook-form aligned.Result
await cl.ChatSettings([...]).refresh()insideon_settings_editto refresh the form without mutating committed session settings.chat_settings_editis tied to real control changes, not programmatic resets.Follow-ups (optional)
editChatSettingsfor sliders if event volume is an issue.refresh()instead ofsend()where session should not be updated on edit.Summary by cubic
Fixes chat settings live edits so the UI can refresh without overwriting session settings, prevents spurious edit events, and makes Reset/Cancel restore the state from when the panel opened.
New Features
ChatSettings.refresh()to emitchat_settingsUI updates without updating session settings. Use it inon_settings_edit(e.g.,await cl.ChatSettings([...]).refresh()).useChatSettingsSnapshotAtOpento snapshot inputs and values at open; used in modal and sidebar.Bug Fixes
session.chat_settings; settings are committed only on Confirm/Submit.chat_settings_editnow fires only on user changes; programmaticreset()or server-driven updates no longer emit.Written for commit 325cd1c. Summary will update on new commits.