Skip to content

fix(Table): make sure dispose drag columns#7297

Merged
ArgoZhang merged 2 commits intomainfrom
fix-table
Dec 11, 2025
Merged

fix(Table): make sure dispose drag columns#7297
ArgoZhang merged 2 commits intomainfrom
fix-table

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 11, 2025

Link issues

fixes #7295

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Bug Fixes:

  • Fix improper disposal of drag column resources by calling the drag dispose helper on the full draggable column set instead of individual headers.

Copilot AI review requested due to automatic review settings December 11, 2025 10:33
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Dec 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures table column drag-and-drop event handlers are properly disposed by calling the disposal helper on the full dragColumns collection instead of each individual column before event wiring.

Sequence diagram for updated table drag column initialization

sequenceDiagram
    participant TableComponent as TableComponent
    participant setDraggable as setDraggable
    participant disposeDragColumns as disposeDragColumns
    participant DragColumns as dragColumns

    TableComponent->>setDraggable: initializeDrag(table)
    setDraggable->>setDraggable: dragColumns = querySelectorAll(draggable th)
    setDraggable->>disposeDragColumns: disposeDragColumns(dragColumns)
    disposeDragColumns->>DragColumns: remove existing drag event handlers
    disposeDragColumns-->>setDraggable: disposal complete
    loop for each col in dragColumns
        setDraggable->>DragColumns: EventHandler.on(col, dragstart, handler)
        setDraggable->>DragColumns: EventHandler.on(col, dragover, handler)
        setDraggable->>DragColumns: EventHandler.on(col, drop, handler)
    end
Loading

File-Level Changes

Change Details Files
Fix disposal of drag-and-drop handlers for table header columns.
  • Build the dragColumns array from draggable header cells before attaching events.
  • Invoke disposeDragColumns once with the entire dragColumns collection instead of per-column calls inside the forEach loop.
  • Preserve existing dragstart/dragover/drop event wiring logic for each column.
src/BootstrapBlazor/Components/Table/Table.razor.js

Possibly linked issues


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

@bb-auto bb-auto Bot added the enhancement New feature or request label Dec 11, 2025
@bb-auto bb-auto Bot added this to the v10.1.0 milestone Dec 11, 2025
@bb-auto bb-auto Bot added bug Something isn't working and removed enhancement New feature or request labels Dec 11, 2025
@ArgoZhang ArgoZhang merged commit 19c6e27 into main Dec 11, 2025
7 of 8 checks passed
@ArgoZhang ArgoZhang deleted the fix-table branch December 11, 2025 10:34
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 there - I've reviewed your changes - here's some feedback:

  • Consider guarding table.tables[0] and the querySelectorAll result before calling disposeDragColumns(table.dragColumns) to avoid potential null/undefined access when the table has no header or tables[0] is not present.
  • If disposeDragColumns mutates the passed array (e.g., by clearing or replacing it), it may be safer to call it with a shallow copy (e.g., disposeDragColumns([...table.dragColumns])) to ensure the subsequent forEach still iterates the intended columns.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider guarding `table.tables[0]` and the `querySelectorAll` result before calling `disposeDragColumns(table.dragColumns)` to avoid potential null/undefined access when the table has no header or `tables[0]` is not present.
- If `disposeDragColumns` mutates the passed array (e.g., by clearing or replacing it), it may be safer to call it with a shallow copy (e.g., `disposeDragColumns([...table.dragColumns])`) to ensure the subsequent `forEach` still iterates the intended columns.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Table/Table.razor.js:933` </location>
<code_context>
     let dragItem = null;
     let index = 0
     table.dragColumns = [...table.tables[0].querySelectorAll('thead > tr > th')].filter(i => i.draggable)
+    disposeDragColumns(table.dragColumns);
     table.dragColumns.forEach(col => {
-        disposeDragColumns(col);
</code_context>

<issue_to_address>
**issue (bug_risk):** Disposing the newly computed dragColumns likely leaves handlers on the previous set and no-ops on the current one.

Because `setDraggable` can be called repeatedly, disposing *after* reassigning `table.dragColumns` disposes the new set instead of the previous one. That leaves old columns with active drag listeners, and clears the new ones before their listeners are attached.

You likely want to dispose the previous `table.dragColumns` before recomputing it:

```js
const setDraggable = table => {
    let dragItem = null;
    let index = 0;

    // dispose old handlers, if any
    if (table.dragColumns) {
        disposeDragColumns(table.dragColumns);
    }

    // compute new draggable columns
    table.dragColumns = [...table.tables[0].querySelectorAll('thead > tr > th')]
        .filter(i => i.draggable);

    table.dragColumns.forEach(col => {
        EventHandler.on(col, 'dragstart', ...);
        // ...
    });
};
```
</issue_to_address>

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the Table component's drag column functionality. The disposeDragColumns function was being called incorrectly with individual column elements instead of the entire array of columns, which would cause improper event handler cleanup.

  • Moved disposeDragColumns call outside the forEach loop to pass the full array of columns
  • Bumped version from 10.1.4-beta01 to 10.1.4-beta02

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/BootstrapBlazor/Components/Table/Table.razor.js Fixed disposeDragColumns to be called with the full column array before attaching new event handlers, rather than being called for each individual column
src/BootstrapBlazor/BootstrapBlazor.csproj Version bump to 10.1.4-beta02 for the bug fix release

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (604e468) to head (e3742e6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7297   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          745       745           
  Lines        32629     32629           
  Branches      4520      4520           
=========================================
  Hits         32629     32629           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Table):Table显示高度超出父容器

2 participants