Skip to content

Conversation

@arvinxx
Copy link
Member

@arvinxx arvinxx commented Dec 17, 2025

Summary

  • Fix DragOverlay position calculation issues after drag operations in SortableList component
  • Add MeasuringStrategy.Always to ensure accurate position measurement on every drag
  • Add closestCenter collision detection for better drag experience
  • Add renderOverlay prop to allow custom drag overlay rendering

Changes

Core Fix

  • Added measuring config with MeasuringStrategy.Always to force re-measurement of element positions
  • Added closestCenter collision detection algorithm

New Feature

  • Added renderOverlay prop to SortableListProps interface
  • Users can now customize the drag overlay appearance independently from renderItem

Test Plan

  • Type check passes
  • All existing tests pass
  • Demo updated with useCustomOverlay toggle to showcase new feature
  • Manual testing: verify drag overlay position is correct after multiple drag operations

Related Issues

Closes LOBE-1959, LOBE-1960, LOBE-1961

🤖 Generated with Claude Code

Summary by Sourcery

Improve SortableList drag-and-drop behavior and support customizable drag overlays.

New Features:

  • Add an optional renderOverlay prop to SortableList to allow custom drag overlay rendering independent of renderItem.

Enhancements:

  • Use closestCenter collision detection to provide more intuitive drag interactions in SortableList.
  • Enable continuous droppable measuring with MeasuringStrategy.Always to keep drag overlay positioning in sync after drag operations.
  • Extend the SortableList demo with a useCustomOverlay toggle showcasing the custom overlay capability.

…ations

- Add MeasuringStrategy.Always to ensure accurate position measurement
- Add closestCenter collision detection for better drag experience
- Add renderOverlay prop for custom drag overlay rendering

Closes LOBE-1959, LOBE-1960, LOBE-1961

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@vercel
Copy link

vercel bot commented Dec 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
lobe-ui Ready Ready Preview, Comment Dec 17, 2025 2:32am

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 17, 2025

Reviewer's Guide

Updates the SortableList drag-and-drop behavior to always re-measure droppable positions, use closest-center collision detection, and support a customizable drag overlay, with a demo toggle to showcase the new overlay behavior.

Sequence diagram for SortableList drag overlay rendering with closestCenter and measuring

sequenceDiagram
  actor User
  participant PointerSensor
  participant DndContext
  participant SortableListParent
  participant overlayRenderer
  participant SortableOverlay

  User->>PointerSensor: start drag on item
  PointerSensor->>DndContext: onDragStart(event)
  DndContext->>SortableListParent: onDragStart callback
  SortableListParent->>SortableListParent: setActive(active)
  Note over DndContext,SortableListParent: During drag
  DndContext->>DndContext: measuringConfig.droppable.strategy = MeasuringStrategy.Always
  DndContext->>DndContext: collisionDetection = closestCenter

  loop while dragging
    DndContext->>DndContext: measure droppables on every update
    DndContext->>DndContext: compute collisions via closestCenter
  end

  SortableListParent->>overlayRenderer: renderOverlay(item) or renderItem(item)
  overlayRenderer-->>SortableListParent: ReactNode overlay
  SortableListParent->>SortableOverlay: children = overlay
  SortableOverlay-->>User: shows drag overlay at correct position

  User->>PointerSensor: end drag
  PointerSensor->>DndContext: onDragEnd(event)
  DndContext->>SortableListParent: onDragEnd callback
  SortableListParent->>SortableListParent: setActive(null)
Loading

Class diagram for updated SortableListProps and SortableListParent

classDiagram
  class SortableListItem {
    +string id
    +string name
  }

  class SortableListProps {
    +SortableListItem[] items
    +function onChange(items: SortableListItem[]): void
    +Ref ref
    +function renderItem(item: SortableListItem): ReactNode
    +function renderOverlay(item: SortableListItem) ReactNode
    +number gap
  }

  class SortableListParent {
    +SortableListProps props
    +Active active
    +function setActive(active: Active): void
    +function overlayRenderer(item: SortableListItem): ReactNode
  }

  class DndContextConfig {
    +function collisionDetection(): void
    +object measuring
    +modifier[] modifiers
  }

  class measuringConfig {
    +object droppable
    +MeasuringStrategy strategy
  }

  class SortableOverlay {
    +ReactNode children
  }

  SortableListParent --> SortableListProps : accepts
  SortableListParent --> SortableOverlay : renders
  SortableListParent --> DndContextConfig : configures
  DndContextConfig --> measuringConfig : uses
  SortableListProps --> SortableListItem : contains
  SortableListParent --> SortableListItem : activeItem
  SortableListParent --> SortableListItem : overlayRenderer
Loading

File-Level Changes

Change Details Files
Ensure more accurate drag positioning by re-measuring droppables and switching to closest-center collision detection.
  • Introduce a shared measuring configuration that forces droppable measurements on every drag using MeasuringStrategy.Always.
  • Pass the measuring configuration into DndContext to affect drag calculations.
  • Switch DndContext collisionDetection to closestCenter to improve which item is considered the current drop target.
src/SortableList/SortableList.tsx
Allow consumers to customize the drag overlay independently of the list item renderer.
  • Extend SortableListProps with an optional renderOverlay callback that takes a SortableListItem and returns a ReactNode.
  • Add overlayRenderer in SortableList that prefers renderOverlay and falls back to renderItem.
  • Use overlayRenderer when rendering SortableOverlay while leaving list item rendering unchanged.
  • Add a demo control flag to toggle between default and custom overlay rendering and wire it to the SortableList renderOverlay prop.
src/SortableList/type.ts
src/SortableList/SortableList.tsx
src/SortableList/demos/index.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gru-agent
Copy link
Contributor

gru-agent bot commented Dec 17, 2025

TestGru Assignment

Summary

Link CommitId Status Reason
Detail 7372973 ✅ Finished

History Assignment

Files

File Pull Request
src/SortableList/SortableList.tsx ❌ Failed (The test job failed due to an environment/configuration issue, not a source code bug. The error message indicates that Vitest is unable to load its config because it is trying to require() an ES module (vite), which is not supported. This is a Node.js ESM/CJS interop problem, not a bug in the SortableList source code. Additionally, there is a minor TypeScript lint error (unused @ts-expect-error), but this does not cause the test run to fail. The actual test suite did not run due to the Vitest startup error.)

Tip

You can @gru-agent and leave your feedback. TestGru will make adjustments based on your input

@lobehubbot
Copy link
Member

👍 @arvinxx


Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

@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 there - I've reviewed your changes - here's some feedback:

  • Consider making collisionDetection and the measuring config configurable via SortableListProps (with sensible defaults of closestCenter and MeasuringStrategy.Always) so consumers can tune drag behavior without modifying the component internals.
  • The new renderOverlay and fallback to renderItem is nice, but you may want to clarify in the typings or JSDoc that the overlay renderer should be visually independent from list layout (e.g., not relying on flex props) since it’s rendered inside SortableOverlay rather than the list.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making `collisionDetection` and the `measuring` config configurable via `SortableListProps` (with sensible defaults of `closestCenter` and `MeasuringStrategy.Always`) so consumers can tune drag behavior without modifying the component internals.
- The new `renderOverlay` and fallback to `renderItem` is nice, but you may want to clarify in the typings or JSDoc that the overlay renderer should be visually independent from list layout (e.g., not relying on flex props) since it’s rendered inside `SortableOverlay` rather than the list.

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/lobehub/lobe-ui/@lobehub/ui@420

commit: 7372973

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.

3 participants