Skip to content

feat(console): persist auto-scroll toggle state in localStorage#8024

Merged
RC-CHN merged 1 commit intoAstrBotDevs:masterfrom
RC-CHN:store-auto-scroll
May 6, 2026
Merged

feat(console): persist auto-scroll toggle state in localStorage#8024
RC-CHN merged 1 commit intoAstrBotDevs:masterfrom
RC-CHN:store-auto-scroll

Conversation

@RC-CHN
Copy link
Copy Markdown
Member

@RC-CHN RC-CHN commented May 6, 2026

The auto-scroll toggle on the console page resets to its default (true) on every page refresh, which can be annoying for users who prefer to keep it disabled.

Modifications / 改动点

dashboard/src/views/ConsolePage.vue

  • Initialize autoScrollEnabled from localStorage on mount, falling back to true when no stored value exists.

  • Watch autoScrollEnabled and persist changes to localStorage so the preference survives page reloads.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

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

image ---

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

New Features:

  • Remember the console auto-scroll toggle state per user by storing it in local storage and restoring it on page load.

@auto-assign auto-assign Bot requested review from Fridemn and LIghtJUNction May 6, 2026 02:53
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels May 6, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider initializing autoScrollEnabled from localStorage in a mounted hook instead of in data() so the component doesn’t touch window.localStorage during server-side rendering or non-browser usage.
  • It may be safer to normalize the stored value explicitly (e.g., const stored = localStorage.getItem('console_auto_scroll'); this.autoScrollEnabled = stored === null ? true : stored === 'true';) to avoid unexpected behavior if the key is ever set to an unexpected string.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider initializing `autoScrollEnabled` from `localStorage` in a `mounted` hook instead of in `data()` so the component doesn’t touch `window.localStorage` during server-side rendering or non-browser usage.
- It may be safer to normalize the stored value explicitly (e.g., `const stored = localStorage.getItem('console_auto_scroll'); this.autoScrollEnabled = stored === null ? true : stored === 'true';`) to avoid unexpected behavior if the key is ever set to an unexpected string.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@RC-CHN RC-CHN merged commit b32cc8d into AstrBotDevs:master May 6, 2026
21 checks passed
@RC-CHN RC-CHN deleted the store-auto-scroll branch May 6, 2026 02:58
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements persistence for the console's auto-scroll setting by storing the state in localStorage. The review feedback identifies potential runtime errors if localStorage is restricted and suggests wrapping storage operations in try-catch blocks. Additionally, it notes a synchronization issue where the initial persisted state is not correctly propagated to the child component upon mounting.

data() {
return {
autoScrollEnabled: true,
autoScrollEnabled: localStorage.getItem('console_auto_scroll') !== 'false',
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.

high

Accessing localStorage can throw an error if it is disabled or restricted in the user's browser. It is safer to wrap this call in a try-catch block to prevent the component from failing to mount.

autoScrollEnabled: (() => {
  try {
    return localStorage.getItem('console_auto_scroll') !== 'false';
  } catch (e) {
    return true;
  }
})(),

Comment on lines 77 to 81
autoScrollEnabled(val) {
localStorage.setItem('console_auto_scroll', val);
if (this.$refs.consoleDisplayer) {
this.$refs.consoleDisplayer.autoScroll = val;
}
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.

high

The autoScrollEnabled state is not synchronized with the ConsoleDisplayer component on initial load. ConsoleDisplayer defaults to true, so it will ignore the persisted false state until the user toggles the switch. Consider adding a mounted hook to ConsolePage.vue to set this.$refs.consoleDisplayer.autoScroll = this.autoScrollEnabled;.

},
watch: {
autoScrollEnabled(val) {
localStorage.setItem('console_auto_scroll', val);
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.

medium

Accessing localStorage can throw an error if it is disabled or restricted. Wrap the setItem call in a try-catch block to handle potential errors gracefully.

try {
  localStorage.setItem('console_auto_scroll', val);
} catch (e) {
  console.error('Failed to save auto-scroll state:', e);
}

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

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant