-
Notifications
You must be signed in to change notification settings - Fork 314
fix(grid): optimize render count #3613
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
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughThe changes refactor internal logic in three grid-related Vue source files. They optimize array reuse in a header utility, adjust the timing of a recalculation callback in a table method, and consolidate column width assignments in an auto-width utility to minimize unnecessary re-renders. No public APIs or function signatures are modified. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/vue/src/grid/src/table/src/utils/autoCellWidth.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-vue". (The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. packages/vue/src/grid/src/table/src/methods.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-vue". (The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. packages/vue/src/grid/src/composable/useHeader.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-vue". (The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. 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
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/vue/src/grid/src/composable/useHeader.ts
(1 hunks)packages/vue/src/grid/src/table/src/methods.ts
(1 hunks)packages/vue/src/grid/src/table/src/utils/autoCellWidth.ts
(4 hunks)
🔇 Additional comments (7)
packages/vue/src/grid/src/composable/useHeader.ts (1)
56-56
: Efficient array clearing implementation.Good use of
length = 0
for clearing the reused array - this preserves the reference while removing all elements, which is exactly what's needed for the performance optimization.packages/vue/src/grid/src/table/src/methods.ts (1)
829-829
: No timing dependencies found forrecalculate()
– manual verification recommendedWe’ve replaced:
- From:
this.$nextTick(() => { setTimeout(() => { this.recalculate() }) })- To:
this.$nextTick(this.recalculate)Since
$nextTick
already waits for the DOM to update, the extrasetTimeout
appears redundant. A repository-wide search yielded no comments or code relying on a delayedrecalculate()
call.Please manually verify that no timing-sensitive behavior breaks, for example:
- Table rendering after data changes (filters, sorts, pagination)
- Resizing or dynamic column updates
- Any custom callbacks that assumed the extra tick
packages/vue/src/grid/src/table/src/utils/autoCellWidth.ts (5)
49-50
: Excellent optimization to reduce re-renders.The introduction of
minArr
to batch width assignments is a smart approach to prevent multiplecolumn.renderWidth
modifications that could trigger unnecessary re-renders during width calculations.
53-58
: Correct indexing for batched width storage.The indexing logic
minArr[index + scaleMinArr.length]
correctly places pxMinArr widths after scaleMinArr entries in the temporary array.
63-68
: Consistent batching strategy for scale minimum widths.Storing scaleMinArr widths at the beginning of
minArr
is consistent with the overall batching strategy and indexing logic.
109-125
: Deferred assignment optimization for auto columns.Using a local
renderWidth
variable and deferring the assignment tocolumn.renderWidth
until after all calculations are complete follows the same optimization pattern and prevents intermediate re-renders.
139-142
: Correct final batch assignment of calculated widths.The final assignment loop correctly applies all calculated widths from
minArr
back to the columns using consistent indexing, completing the render optimization effectively.
PR
减少column.renderWidth的多次赋值导致的表格render重新执行
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Refactor
Chores