Skip to content

Conversation

@wumo1016
Copy link

@wumo1016 wumo1016 commented Aug 1, 2025

Summary by CodeRabbit

  • New Features

    • Bubble list now displays new items at the bottom, reversing the previous order.
    • Added smooth auto-scrolling to the bottom using improved observation logic.
    • Back-to-bottom button repositioned for better usability.
  • Improvements

    • Enhanced scroll behavior for more accurate navigation and better handling when new messages arrive.
    • In the demo, newly added messages dynamically extend their content over several seconds for a more interactive experience.
  • Style

    • Updated visual stacking order so that bubbles grow upward from the bottom.

@coderabbitai
Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

The BubbleList component now renders its list in reverse order and updates all scroll, index, and rendering logic to match. Scrolling and auto-scroll behaviors are reworked using IntersectionObserver and new helper functions. Styles are updated for column-reverse flex direction. A story file adds dynamic message content extension for demonstration.

Changes

Cohort / File(s) Change Summary
BubbleList Component Logic
packages/core/src/components/BubbleList/index.vue
Refactored to render the list in reverse order using a computed property. All scroll and index calculations are updated to match the reversed logic. Introduces helper functions for index mapping and scroll setting. Replaces ResizeObserver with IntersectionObserver for auto-scroll. Updates scroll event handling and back-to-bottom button logic. Template is adjusted to use the reversed list and new observation element.
BubbleList Styles
packages/core/src/components/BubbleList/style.scss
Changes flex direction of the bubble list container from column to column-reverse to visually reverse the stacking of child elements. No other style changes.
Story Demo Update
packages/core/src/stories/BubbleList/CustomSolt.vue
Enhances the addMessage function to append text to the last message at 100ms intervals, repeating 50 times, to demonstrate dynamic content extension in the story. No changes to exports or public API.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant BubbleList
  participant DOM
  participant IntersectionObserver

  User->>BubbleList: Add new message to list
  BubbleList->>BubbleList: wrapList (reverse list)
  BubbleList->>DOM: Render bubbles in reversed order
  BubbleList->>IntersectionObserver: Observe checkViewRef at bottom
  IntersectionObserver-->>BubbleList: checkViewRef not visible
  BubbleList->>DOM: Scroll checkViewRef into view (autoScroll)
  IntersectionObserver-->>BubbleList: checkViewRef visible
  BubbleList->>BubbleList: Stop autoScroll
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

In the garden of code where bubbles align,
The list flips its order—now bottom is fine!
With scrolls that observe and messages that grow,
The rabbits rejoice as new features flow.
Hopping through columns, reversed with delight,
Our chat bubbles sparkle—oh what a sight!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate unit tests to generate unit tests for 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

@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 (1)
packages/core/src/components/BubbleList/index.vue (1)

70-70: Fix ESLint style violations.

Please address the ESLint warnings by adding newlines after if statements and fixing brace styles for better code consistency.

Also applies to: 89-89, 96-96, 100-100, 119-119, 178-178, 133-133, 213-213

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f516932 and 0f8246f.

📒 Files selected for processing (3)
  • packages/core/src/components/BubbleList/index.vue (6 hunks)
  • packages/core/src/components/BubbleList/style.scss (1 hunks)
  • packages/core/src/stories/BubbleList/CustomSolt.vue (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/core/src/components/BubbleList/style.scss (1)
packages/core/src/components/BubbleList/types.d.ts (4)
  • BubbleListInstance (31-35)
  • BubbleListProps (12-25)
  • BubbleListItemProps (5-5)
  • BackButtonPosition (7-10)
packages/core/src/components/BubbleList/index.vue (1)
packages/core/src/components/BubbleList/types.d.ts (5)
  • BubbleListInstance (31-35)
  • BubbleListProps (12-25)
  • BubbleListEmits (27-29)
  • BubbleListItemProps (5-5)
  • BackButtonPosition (7-10)
🪛 ESLint
packages/core/src/components/BubbleList/index.vue

[error] 70-70: Expect newline after if

(antfu/if-newline)


[error] 89-89: Expect newline after if

(antfu/if-newline)


[error] 96-96: Expect newline after if

(antfu/if-newline)


[error] 100-100: Expect newline after if

(antfu/if-newline)


[error] 119-119: Expect newline after if

(antfu/if-newline)


[error] 133-133: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)


[error] 178-178: Expect newline after if

(antfu/if-newline)


[error] 213-213: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)

🔇 Additional comments (5)
packages/core/src/components/BubbleList/style.scss (1)

3-3: LGTM!

The flex-direction: column-reverse change correctly implements the reversed layout for the bubble list, ensuring new items appear at the bottom of the container.

packages/core/src/components/BubbleList/index.vue (4)

27-44: Well-implemented list reversal logic.

The wrapList computed property correctly creates a reversed copy without mutating the original prop, and getTrueIndex properly maps indices between the reversed and original lists.


75-84: Correct implementation for reversed container.

Setting scrollTop to a negative value is the correct approach for scrolling to the top in a column-reverse flex container.


176-226: Well-implemented scroll handling for reversed container.

The scroll calculations correctly account for the reversed layout, and the threshold-based user interaction detection provides good UX.


243-243: Smart implementation of scroll detection.

The 1px invisible element for intersection observation is an elegant solution, and the template correctly uses the reversed list.

Also applies to: 274-274

Comment on lines +115 to 145
let intersectionObserver!: IntersectionObserver;
// 组件内部触发方法,跟随打字器滚动,滚动底部
function autoScroll() {
if (scrollContainer.value) {
const listBubbles = scrollContainer.value!.querySelectorAll(
'.el-bubble-content-wrapper'
);
// 如果页面上有监听节点,先移除
if (resizeObserver.value) {
resizeObserver.value.disconnect();
}
const lastItem = listBubbles[listBubbles.length - 1];
if (lastItem) {
resizeObserver.value = new ResizeObserver(() => {
if (!stopAutoScrollToBottom.value) {
scrollToBottom();
const container = checkViewRef.value;
if (!container) return;
if (intersectionObserver) {
intersectionObserver.unobserve(container);
}
container.scrollIntoView({
behavior: 'smooth'
});
intersectionObserver = new IntersectionObserver(
entries => {
if (stopAutoScrollToBottom.value)
return intersectionObserver.unobserve(container);
entries.forEach(entry => {
if (entry.isIntersecting) {
intersectionObserver.unobserve(container);
} else {
intersectionObserver.unobserve(container);
intersectionObserver.disconnect();
autoScroll();
}
});
resizeObserver.value.observe(lastItem);
},
{
threshold: 1
}
}
);
intersectionObserver.observe(container);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential memory leak with IntersectionObserver.

The global intersectionObserver variable could lead to memory leaks if multiple observers are created without proper cleanup.

Consider this improvement:

-let intersectionObserver!: IntersectionObserver;
 // 组件内部触发方法,跟随打字器滚动,滚动底部
 function autoScroll() {
   const container = checkViewRef.value;
   if (!container) return;
-  if (intersectionObserver) {
-    intersectionObserver.unobserve(container);
-  }
   container.scrollIntoView({
     behavior: 'smooth'
   });
-  intersectionObserver = new IntersectionObserver(
+  const observer = new IntersectionObserver(
     entries => {
       if (stopAutoScrollToBottom.value)
-        return intersectionObserver.unobserve(container);
+        return observer.disconnect();
       entries.forEach(entry => {
         if (entry.isIntersecting) {
-          intersectionObserver.unobserve(container);
+          observer.disconnect();
         } else {
-          intersectionObserver.unobserve(container);
-          intersectionObserver.disconnect();
+          observer.disconnect();
           autoScroll();
         }
       });
     },
     {
       threshold: 1
     }
   );
-  intersectionObserver.observe(container);
+  observer.observe(container);
 }

Also consider adding a cleanup in onBeforeUnmount to ensure any active observer is disconnected.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let intersectionObserver!: IntersectionObserver;
// 组件内部触发方法,跟随打字器滚动,滚动底部
function autoScroll() {
if (scrollContainer.value) {
const listBubbles = scrollContainer.value!.querySelectorAll(
'.el-bubble-content-wrapper'
);
// 如果页面上有监听节点,先移除
if (resizeObserver.value) {
resizeObserver.value.disconnect();
}
const lastItem = listBubbles[listBubbles.length - 1];
if (lastItem) {
resizeObserver.value = new ResizeObserver(() => {
if (!stopAutoScrollToBottom.value) {
scrollToBottom();
const container = checkViewRef.value;
if (!container) return;
if (intersectionObserver) {
intersectionObserver.unobserve(container);
}
container.scrollIntoView({
behavior: 'smooth'
});
intersectionObserver = new IntersectionObserver(
entries => {
if (stopAutoScrollToBottom.value)
return intersectionObserver.unobserve(container);
entries.forEach(entry => {
if (entry.isIntersecting) {
intersectionObserver.unobserve(container);
} else {
intersectionObserver.unobserve(container);
intersectionObserver.disconnect();
autoScroll();
}
});
resizeObserver.value.observe(lastItem);
},
{
threshold: 1
}
}
);
intersectionObserver.observe(container);
}
// 组件内部触发方法,跟随打字器滚动,滚动底部
function autoScroll() {
const container = checkViewRef.value;
if (!container) return;
container.scrollIntoView({
behavior: 'smooth'
});
const observer = new IntersectionObserver(
entries => {
if (stopAutoScrollToBottom.value)
return observer.disconnect();
entries.forEach(entry => {
if (entry.isIntersecting) {
observer.disconnect();
} else {
observer.disconnect();
autoScroll();
}
});
},
{
threshold: 1
}
);
observer.observe(container);
}
🧰 Tools
🪛 ESLint

[error] 119-119: Expect newline after if

(antfu/if-newline)


[error] 133-133: Closing curly brace appears on the same line as the subsequent block.

(style/brace-style)

🤖 Prompt for AI Agents
In packages/core/src/components/BubbleList/index.vue around lines 115 to 145,
the global intersectionObserver variable may cause memory leaks by creating
multiple observers without proper cleanup. To fix this, ensure that before
assigning a new IntersectionObserver to the variable, any existing observer is
disconnected and unobserved. Additionally, add a cleanup step in the component's
onBeforeUnmount lifecycle hook to disconnect the observer if it exists,
preventing lingering observers after the component is destroyed.

Comment on lines +46 to +54
let num = 50;
const T = setInterval(() => {
if (num < 1) {
clearInterval(T);
}
bubbleItems.value[bubbleItems.value.length - 1].content +=
'欢迎使用 Element Plus X .';
num--;
}, 100);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Variable shadowing and potential performance issues.

The local variable num shadows the ref declared at line 17. Additionally, updating the message content 50 times in 5 seconds could cause performance issues.

Consider these improvements:

-  let num = 50;
-  const T = setInterval(() => {
-    if (num < 1) {
-      clearInterval(T);
+  let counter = 50;
+  const intervalId = setInterval(() => {
+    if (counter < 1 || bubbleItems.value.length === 0) {
+      clearInterval(intervalId);
+      return;
     }
     bubbleItems.value[bubbleItems.value.length - 1].content +=
       '欢迎使用 Element Plus X .';
-    num--;
+    counter--;
   }, 100);

This addresses variable shadowing, follows naming conventions, and adds a safety check for empty arrays.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let num = 50;
const T = setInterval(() => {
if (num < 1) {
clearInterval(T);
}
bubbleItems.value[bubbleItems.value.length - 1].content +=
'欢迎使用 Element Plus X .';
num--;
}, 100);
let counter = 50;
const intervalId = setInterval(() => {
if (counter < 1 || bubbleItems.value.length === 0) {
clearInterval(intervalId);
return;
}
bubbleItems.value[bubbleItems.value.length - 1].content +=
'欢迎使用 Element Plus X .';
counter--;
}, 100);
🤖 Prompt for AI Agents
In packages/core/src/stories/BubbleList/CustomSolt.vue around lines 46 to 54,
the local variable 'num' shadows a ref declared earlier, which can cause
confusion and bugs. Rename the local variable to avoid shadowing, follow
consistent naming conventions, and add a check to ensure 'bubbleItems.value' is
not empty before updating its last item's content to prevent runtime errors.
Also, consider reducing the update frequency or batching updates to mitigate
potential performance issues from frequent DOM updates.

@HeJiaYue520 HeJiaYue520 changed the base branch from main to sender-test August 11, 2025 09:40
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