Skip to content

fix: persist WebChat chat preferences - #10324

Open
C10H14N2O5 wants to merge 4 commits into
AstrBotDevs:masterfrom
C10H14N2O5:fix/10316-chat-preferences
Open

C10H14N2O5 wants to merge 4 commits into
AstrBotDevs:masterfrom
C10H14N2O5:fix/10316-chat-preferences

Conversation

@C10H14N2O5

@C10H14N2O5 C10H14N2O5 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

  • Persist streaming output, reasoning visibility, and the send shortcut across page reloads.
  • Follow the existing SSE / WebSocket transport preference's localStorage initialization and watcher pattern in both chat entry points.
  • Add focused regression tests and verify the fix on a running local AstrBot instance.

Background

Fixes #10316.

In WebChat's Settings → Chat menu, disabling streaming output or reasoning visibility, or selecting Shift+Enter as the send shortcut, only applied to the current page. Reloading restored both toggles to enabled and the send shortcut to Enter. The neighboring SSE / WebSocket transport preference already survived reloads.

These options reflect personal chat preferences. This fix retains the user's choices using the same browser-local persistence approach as the transport preference.

Modifications / 改动点

Chat preferences

Update dashboard/src/components/chat/Chat.vue and dashboard/src/components/chat/StandaloneChat.vue to read saved preferences when initializing their reactive state and write changes through Vue watchers.

Preference Storage key Default when no preference is saved
Streaming output chat.enableStreaming Enabled
Show reasoning content chat.enableReasoning Enabled
Send shortcut chat.sendShortcut Enter

Both the main WebChat and the configuration page's test chat use these keys, so newly opened chat entry points read the same preferences on the same browser origin.

The main WebChat remains mounted while other pages are open. When it becomes active again, it reloads the three saved preferences so changes made in the configuration page's test chat are reflected when returning to WebChat.

Regression tests

Add dashboard/tests/chatPreferencesPersistence.test.mjs, following the existing lightweight Node / TypeScript / Vue test style. The five tests execute the components' initialization and watcher code to cover:

  • Existing defaults when no preferences have been saved.
  • Saving disabled toggles and Shift+Enter, then restoring them when either chat component is initialized again.
  • Saving and restoring the defaults after switching back.
  • Preserving the existing chat.transportMode value.
  • Refreshing the retained main WebChat instance after preferences are changed in the configuration page's test chat, including switching back to the defaults.

No documentation update is needed because this fix preserves the existing navigation, page structure, and labels. No new dependencies are introduced.

  • This is NOT a breaking change.

Screenshots or Test Results / 运行截图或测试结果

Verification steps

  1. Open WebChat and go to Settings → Chat.
  2. Disable streaming output and reasoning visibility, and select Shift+Enter as the send shortcut.
  3. Reload the page and reopen the settings. Confirm all three choices are retained.
  4. Open the configuration page's test chat and confirm it reads the same saved preferences.
  5. Switch the three preferences back to their defaults, reload, and confirm those choices are retained as well.
  6. Change the SSE / WebSocket transport preference and confirm it continues to survive reloads.

Manual acceptance testing on the isolated local AstrBot instance passed. The instance serves the frontend built from this working tree and uses a separate runtime data directory. This validation covers settings persistence; no external LLM provider was configured.

Streaming output preference

流式传输

Reasoning visibility preference

思考内容

Send shortcut preference

发送快捷键

Automated validation

From dashboard/:

node --test tests/chatPreferencesPersistence.test.mjs tests/imeInput.test.mjs

Result: 9 passed — five persistence tests and four existing IME input tests.

pnpm --config.verifyDepsBeforeRun=false build

Result: passed, including TypeScript checks and the production build. The command-line override used the installed dependencies without triggering a reinstall by the local pnpm runtime.

From the repository root:

ruff format .
ruff check .
git diff --check

Results: 514 files left unchanged, All checks passed, and no whitespace errors.

Runtime smoke checks also passed: login, chat session/configuration endpoints, and serving assets matching the freshly built frontend.

After merging the latest upstream master in commit 81c637165, all GitHub Actions checks passed: Unit Tests on Linux, macOS, and Windows; Dashboard CI; Code Format Check; Smoke Test; and CodeQL.


Checklist / 检查清单

  • If new features are added, they have been discussed with the authors through issues/emails. The persistence omission was confirmed before implementing this fix.
  • My changes have been well-tested, and verification steps and screenshots have been provided above.
  • The affected WebUI navigation, page structure, and labels were checked; no documentation update is needed, as explained above.
  • No new dependencies are introduced.
  • My changes do not introduce malicious code.

Summary by Sourcery

Persist WebChat chat preferences locally so user settings survive reloads and remain synchronized across chat entry points.

Bug Fixes:

  • Persist WebChat streaming, reasoning visibility, and send shortcut preferences across reloads and between chat entry points.

Enhancements:

  • Refresh the mounted main chat with preferences changed in the configuration test chat while preserving transport settings.

Tests:

  • Add regression coverage for preference defaults, persistence, cross-entry-point restoration, active-chat refresh, and transport preference preservation.

@C10H14N2O5
C10H14N2O5 marked this pull request as ready for review October 2, 2026 09:58
@C10H14N2O5

Copy link
Copy Markdown
Contributor Author

The unit test failures on Linux, macOS, and Windows are pre-existing upstream failures, rather than regressions introduced by this PR.

I compared this PR’s CI run with the upstream master CI run following #10307. Each platform reports the same five failing tests and identical pass counts:

  • Linux and macOS: 3628 passed, 5 failed
  • Windows: 3556 passed, 5 failed

The failures concern the plugin Pages → Views rename: outdated bridge and metadata assertions, plus OpenAPI artifacts that have not been regenerated.

This PR changes only two Vue components and one Node test file; it does not modify the affected Python tests, backend implementation, or OpenAPI artifacts. The Dashboard CI run passed.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="dashboard/src/components/chat/StandaloneChat.vue" line_range="331-341" />
<code_context>
     : "sse",
 );

+watch(enableStreaming, (enabled) => {
+  localStorage.setItem("chat.enableStreaming", String(enabled));
+});
+
+watch(enableReasoning, (enabled) => {
</code_context>
<issue_to_address>
**issue (broader_impact):** The two chat entry points only read `localStorage` during component setup, so their reactive preference state becomes stale when the other entry point changes a preference. `FullLayout` keeps `Chat` mounted with `v-show`; after a user changes settings in `StandaloneChat`, navigating back to WebChat displays the still-mounted `Chat` instance with the old values and sends requests using those old preferences.

**Triggers:** When WebChat has already been mounted and the user changes preferences in the configuration page's test chat before returning to WebChat.

**Suggested fix:** Synchronize the reactive state on activation or use a shared preference store/storage-event listener so both mounted entry points update when the persisted values change.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: dashboard/src/components/chat/StandaloneChat.vue:341


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread dashboard/src/components/chat/StandaloneChat.vue
@C10H14N2O5

Copy link
Copy Markdown
Contributor Author

Following up on the earlier CI failures: the upstream issues were fixed in #10319, and I have merged the latest upstream master into this branch in commit 81c6371.
All checks now pass, including the unit tests on Linux, macOS, and Windows. The previously reported upstream test failures are resolved. Latest unit test run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] WebChat 聊天偏好在刷新后重置:流式输出、显示思考内容及发送快捷键

1 participant