Skip to content

Option to disable auto scroll functionality #6465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gq97a6
Copy link

@gq97a6 gq97a6 commented Apr 25, 2025

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

Refactored auto scroll.
Added auto scroll configuration to settings.
Added locales for auto scroll configuration.

📝 补充信息 | Additional Information

Chat is ALWYAS automatically scrolled to the bottom when:

  • user opens chat window
  • user user clicks the "Scroll to Bottom" button
  • chat is already scrolled to the bottom and its size changes (sticky bottom)

Chat is automatically scrolled to the bottom when AUTO SCROLL ENABLED IN CONFIG and when:

  • input field gains focus
  • input field is clicked
  • user submits input
  • after finishing making request (finished loading)

Summary by CodeRabbit

  • New Features
    • Introduced an "Auto Scroll" setting, allowing users to enable or disable automatic scrolling to the bottom of the chat when focusing the text area or sending a message.
    • Added localization for the new "Auto Scroll" setting across multiple languages.
  • Improvements
    • Simplified and improved chat auto-scroll behavior for a smoother user experience.
  • Settings
    • Added a configurable option for auto-scroll in the settings menu, enabled by default.
  • Localization
    • Updated translations to include the new auto-scroll setting in all supported languages.
  • Minor Changes
    • Small textual update in the English settings description for artifacts.

Copy link

vercel bot commented Apr 25, 2025

@gq97a6 is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

Walkthrough

This change introduces a user-configurable "Auto Scroll" feature for the chat interface. The scroll-to-bottom logic in the chat component is refactored for simplicity, removing the custom useScrollToBottom hook and associated state in favor of direct imperative scrolling based on a new enableAutoScroll configuration flag. A new setting is added to the Settings UI, allowing users to enable or disable auto-scroll. This feature and its description are localized across multiple languages, and a new enableAutoScroll property is included in the default app configuration.

Changes

File(s) Change Summary
app/components/chat.tsx Refactored chat scroll-to-bottom logic: removed useScrollToBottom hook, added direct scroll functions, updated event handlers, and replaced auto-scroll state with config-based control. Renamed prop in ChatActions from scrollToBottom to scrollChatToBottom.
app/components/settings.tsx Added an "AutoScroll" checkbox to the Settings UI, bound to the new config property.
app/store/config.ts Added enableAutoScroll boolean property (default: true) to DEFAULT_CONFIG.
app/locales/ar.ts, app/locales/bn.ts, app/locales/cn.ts, ...
app/locales/cs.ts, app/locales/da.ts, app/locales/de.ts, app/locales/en.ts,
app/locales/es.ts, app/locales/fr.ts, app/locales/id.ts, app/locales/it.ts,
app/locales/jp.ts, app/locales/ko.ts, app/locales/no.ts, app/locales/pt.ts,
app/locales/ru.ts, app/locales/sk.ts, app/locales/tr.ts, app/locales/tw.ts,
app/locales/vi.ts
Added localized entries for the new "AutoScroll" setting with appropriate titles and subtitles in each language.
app/locales/en.ts Additionally, removed a trailing period from Mask.Config.Artifacts.SubTitle.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Settings
    participant Config
    participant Chat

    User->>Settings: Toggles AutoScroll checkbox
    Settings->>Config: Updates enableAutoScroll property

    User->>Chat: Focuses input / submits message
    Chat->>Config: Checks enableAutoScroll
    alt enableAutoScroll is true
        Chat->>Chat: Scrolls to bottom
    else enableAutoScroll is false
        Chat->>Chat: No auto-scroll
    end
Loading

Possibly related PRs

  • ChatGPTNextWeb/NextChat#5821: Both PRs modify the scrolling behavior in the app/components/chat.tsx file, specifically updating the useScrollToBottom hook and the doSubmit function to improve auto-scroll logic, indicating a direct relation in how chat scrolling is managed.

Suggested labels

enhancement

Suggested reviewers

  • Dogtiti

Poem

A rabbit hops and scrolls with glee,
Now chats can auto-scroll, you see!
Flip a switch in settings land,
And let the messages glide as planned.
In every tongue, this feature's found—
So bunnies scroll the world around!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
app/components/chat.tsx (3)

1049-1061: Duplicate scroll trigger after doSubmit

autoScrollChatToBottom() is called twice:

  1. in the then callback after chatStore.onUserInput(...)
  2. again immediately after resetting local state.

Because both calls run unconditionally and internally check the same config.enableAutoScroll flag, the second invocation does not add value but still schedules an extra requestAnimationFrame, resulting in redundant work (and two layout thrashes).

-    chatStore.onUserInput(userInput, attachImages).then(() => {
-      setIsLoading(false);
-      autoScrollChatToBottom();
-    });
-
-    ...
-    autoScrollChatToBottom();
+    chatStore.onUserInput(userInput, attachImages).then(() => {
+      setIsLoading(false);
+      autoScrollChatToBottom(); // keep a single, well-timed scroll
+    });

1362-1376: Minor: avoid passing negative index explicitly

scrollChatToBottom sets

setMsgRenderIndex(renderMessages.length - CHAT_PAGE_SIZE);

and relies on the clamping logic inside setMsgRenderIndex to normalise negative values.
For clarity (and to avoid any future refactor accident) compute the clamped index before the setter:

-      setMsgRenderIndex(renderMessages.length - CHAT_PAGE_SIZE);
+      const start = Math.max(0, renderMessages.length - CHAT_PAGE_SIZE);
+      setMsgRenderIndex(start);

2038-2041: Respect “auto scroll disabled” for click/focus

onFocus and onClick always invoke autoScrollChatToBottom, but that helper internally checks config.enableAutoScroll.
This is fine logically, yet it still mounts two listeners that will be no-ops when the feature is off.
For cleanliness you could attach these handlers conditionally:

- onFocus={autoScrollChatToBottom}
- onClick={autoScrollChatToBottom}
+ onFocus={config.enableAutoScroll ? autoScrollChatToBottom : undefined}
+ onClick={config.enableAutoScroll ? autoScrollChatToBottom : undefined}

Not critical, but it avoids needless function calls when auto-scroll is disabled.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3809375 and 520c285.

📒 Files selected for processing (23)
  • app/components/chat.tsx (8 hunks)
  • app/components/settings.tsx (1 hunks)
  • app/locales/ar.ts (1 hunks)
  • app/locales/bn.ts (1 hunks)
  • app/locales/cn.ts (1 hunks)
  • app/locales/cs.ts (1 hunks)
  • app/locales/da.ts (1 hunks)
  • app/locales/de.ts (1 hunks)
  • app/locales/en.ts (2 hunks)
  • app/locales/es.ts (1 hunks)
  • app/locales/fr.ts (1 hunks)
  • app/locales/id.ts (1 hunks)
  • app/locales/it.ts (1 hunks)
  • app/locales/jp.ts (1 hunks)
  • app/locales/ko.ts (1 hunks)
  • app/locales/no.ts (1 hunks)
  • app/locales/pt.ts (1 hunks)
  • app/locales/ru.ts (1 hunks)
  • app/locales/sk.ts (1 hunks)
  • app/locales/tr.ts (1 hunks)
  • app/locales/tw.ts (1 hunks)
  • app/locales/vi.ts (1 hunks)
  • app/store/config.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/components/chat.tsx (2)
app/constant.ts (1)
  • CHAT_PAGE_SIZE (832-832)
app/client/api.ts (1)
  • config (181-181)
🔇 Additional comments (21)
app/locales/tw.ts (1)

210-213: Localization entry looks correct.

The Traditional Chinese translations for AutoScroll Title and SubTitle align with other locales and follow existing formatting.

app/locales/tr.ts (1)

203-207: Turkish localization validated.

The new AutoScroll entry matches the English key semantics and indentation.

app/locales/ko.ts (1)

202-206: Korean translation is accurate.

The AutoScroll Title and SubTitle convey the feature correctly and match other locale patterns.

app/locales/jp.ts (1)

203-207: Japanese localization approved.

The AutoScroll strings are consistent with the existing style and correctly describe the feature.

app/locales/cs.ts (1)

203-207: Add AutoScroll localization entry
The new AutoScroll key and its Title/SubTitle values align with the existing pattern under Settings and are consistent with other locales.

app/locales/vi.ts (1)

203-207: Add AutoScroll localization entry
The AutoScroll entry follows the same structure as other settings, ensuring consistent UI text for Vietnamese users.

app/locales/it.ts (1)

212-216: Add AutoScroll localization entry
The Italian translation for AutoScroll is correctly added with matching keys and formatting.

app/locales/sk.ts (1)

203-207: Add AutoScroll localization entry
The Slovak AutoScroll section is properly inserted, mirroring the pattern used in other locales.

app/locales/no.ts (1)

209-213: Add AutoScroll localization entry
The Norwegian AutoScroll block is added with correct indentation and consistent naming.

app/locales/id.ts (1)

204-208: New AutoScroll locale entry looks correct and consistent.

The AutoScroll key and its Title/SubTitle values are properly added under Settings, matching the structure of other locale entries.

app/locales/es.ts (1)

211-215: New AutoScroll localization is accurate and consistent.

The Spanish translations for Title and SubTitle align with other locales and follow existing formatting conventions.

app/locales/fr.ts (1)

210-214: French AutoScroll entry is well-formed.

The new AutoScroll block matches the style of neighboring settings and the translation is clear.

app/locales/pt.ts (1)

202-206: Portuguese AutoScroll entry is correctly inserted.

The key, title, and subtitle follow the project’s locale structure and the translation reads naturally.

app/locales/cn.ts (1)

223-226: Chinese AutoScroll entry is properly added.

This new localization aligns with other languages and fits the existing indentation and format.

app/locales/ar.ts (1)

202-206: New AutoScroll localization entry looks correct.
The Arabic translation for the AutoScroll setting is well-formulated, aligns with the feature description, and matches the formatting/style of adjacent entries.

app/locales/de.ts (1)

208-212: New AutoScroll localization entry looks correct.
The German strings for AutoScroll are consistent with other locales and follow existing translation conventions.

app/locales/bn.ts (1)

203-207: New AutoScroll localization entry looks correct.
The Bengali translation for the AutoScroll setting is accurate, clear, and matches the formatting of surrounding entries.

app/locales/ru.ts (1)

205-209: New AutoScroll localization entry looks correct.
The Russian strings for AutoScroll are properly added and consistent with the rest of the locale.

app/locales/da.ts (1)

222-226: New AutoScroll localization entry looks correct.
The Danish translation for the AutoScroll setting is accurately inserted and maintains consistency with other locale entries.

app/components/settings.tsx (1)

1702-1718: UI control looks good – remember to localise

The checkbox correctly binds to config.enableAutoScroll, mirrors the surrounding pattern, and includes a data-testid.

Just double-check that every non-English locale gets the new Settings.AutoScroll entries; otherwise users running other languages will see blank labels.

app/locales/en.ts (1)

225-229: Entry added correctly

The AutoScroll title and subtitle are well phrased and match the behaviour implemented in the component. No issues spotted.

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.

1 participant