Skip to content

Auto adjust table content width#1

Open
topfunplusnew wants to merge 1 commit intofront-devfrom
cursor/auto-adjust-table-content-width-e794
Open

Auto adjust table content width#1
topfunplusnew wants to merge 1 commit intofront-devfrom
cursor/auto-adjust-table-content-width-e794

Conversation

@topfunplusnew
Copy link
Owner

@topfunplusnew topfunplusnew commented Nov 15, 2025

Add v-auto-table-width directive to automatically adjust el-table column widths based on content for improved readability.


Open in Cursor Open in Web


Note

Adds a Vue directive v-auto-table-width to auto-adjust Element UI el-table column widths based on content, with options, registration, example, and docs.

  • Directive:
    • Adds src/directive/module/autoTableWidth.js providing v-auto-table-width to auto-size el-table columns using content measurement with options: minWidth, maxWidth, padding, excludeColumns, delay.
    • Handles updates via MutationObserver, window resize, and cleans up on unbind.
  • Registration:
    • Registers directive in src/directive/index.js as autoTableWidth.
  • Examples/Docs:
    • Adds usage example in src/directive/module/autoTableWidth.example.vue.
    • Adds documentation src/directive/module/autoTableWidth.md with features, usage, and notes.

Written by Cursor Bugbot for commit 3612970. This will update automatically on new commits. Configure here.

Co-authored-by: ming10655 <ming10655@gmail.com>
@cursor
Copy link

cursor bot commented Nov 15, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@topfunplusnew topfunplusnew marked this pull request as ready for review November 15, 2025 14:25
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.


// 保存observer到元素上,以便在unbind时清理
el._autoTableWidthObserver = observer;
el._autoTableWidthTimer = adjustTimer;
Copy link

Choose a reason for hiding this comment

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

Bug: Stale Timer Reference Causes Leaks

The timer reference saved to el._autoTableWidthTimer on line 55 becomes stale immediately. The local adjustTimer variable gets updated inside the adjustWidth closure on each call, but el._autoTableWidthTimer is only set once during initialization. This prevents proper cleanup of active timers in the update and unbind hooks, causing timer leaks when the directive updates or unbinds while a delayed adjustment is pending.

Fix in Cursor Fix in Web

subtree: true,
attributes: true,
attributeFilter: ['style', 'class']
});
Copy link

Choose a reason for hiding this comment

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

Bug: Infinite Style Loop Crushes Performance

The MutationObserver watches for style attribute changes with attributeFilter: ['style', 'class'], but the directive itself modifies element styles in adjustTableWidth (lines 225-226, 240-241). This creates an infinite observation loop where each width adjustment triggers the observer, which triggers another adjustment, causing excessive recalculations and severe performance degradation.

Fix in Cursor Fix in Web

adjustWidth();
};
}
}
Copy link

Choose a reason for hiding this comment

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

Bug: Persistent Override Causes Leaks and Conflicts

The code permanently overwrites vueInstance.$forceUpdate without storing the original method or cleaning it up in unbind. This causes the override to persist after the directive is removed, and prevents multiple directives on the same component from working correctly. The overridden method also lacks proper cleanup, leading to memory leaks as the closure retains references to adjustWidth.

Fix in Cursor Fix in Web

el._autoTableWidthTimer = setTimeout(() => {
adjustTableWidth(el, { minWidth, maxWidth, padding, excludeColumns });
}, delay);
},
Copy link

Choose a reason for hiding this comment

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

Bug: Dynamic Widths Stuck on Old Settings

The update hook cannot update the configuration used by the MutationObserver and resize handler because they reference the adjustWidth closure from inserted which captures the original options. When binding values change (like minWidth, maxWidth, padding, or excludeColumns), the observer and resize handler continue using stale configuration values, causing inconsistent width calculations between manual updates and automatic recalculations.

Fix in Cursor Fix in Web

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.

2 participants