-
Notifications
You must be signed in to change notification settings - Fork 326
fix(grid): fix scroll bar error after load data #3644
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -30,7 +30,8 @@ import { | |||||||||||||||||||||||
resolveTheme, | ||||||||||||||||||||||||
defineComponent, | ||||||||||||||||||||||||
useInstanceSlots, | ||||||||||||||||||||||||
useRelation | ||||||||||||||||||||||||
useRelation, | ||||||||||||||||||||||||
isVue2 | ||||||||||||||||||||||||
} from '@opentiny/vue-common' | ||||||||||||||||||||||||
import Tooltip from '@opentiny/vue-tooltip' | ||||||||||||||||||||||||
import { extend } from '@opentiny/utils' | ||||||||||||||||||||||||
|
@@ -539,7 +540,15 @@ export default defineComponent({ | |||||||||||||||||||||||
this.handleSelectionHeader() | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
parentHeight() { | ||||||||||||||||||||||||
this.$nextTick(this.recalculate) | ||||||||||||||||||||||||
this.recalculate() | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
// 选项式监控在vue2可以检测到顶层数组splice项替换/$set项替换 | ||||||||||||||||||||||||
// array.splice(index, 1, newItem) | ||||||||||||||||||||||||
// this.$set(array, index, newItem) | ||||||||||||||||||||||||
data(array1, array2) { | ||||||||||||||||||||||||
if (isVue2 && array1 === array2 && array1.length === array2.length) { | ||||||||||||||||||||||||
this.handleDataChange() | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
Comment on lines
+548
to
552
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainGood Vue 2 array-mutation watcher; add an Array guard to avoid unnecessary calls The watcher correctly handles Vue 2’s same-reference array mutations (splice/$set). Add a guard to skip non-array Apply this diff: - data(array1, array2) {
- if (isVue2 && array1 === array2 && array1.length === array2.length) {
+ data(array1, array2) {
+ // Guard non-array props and avoid unnecessary calls when data is an object
+ if (isVue2 && Array.isArray(array1) && array1 === array2 && array1.length === array2.length) {
this.handleDataChange()
}
} To ensure the watcher captures Vue 2 in-place mutations across the codebase, you can grep for other places mutating 🏁 Script executed: #!/bin/bash
# Look for common in-place mutations on `data` props
rg -n -A 2 -B 2 $'\\.data\\.(push|splice|pop|shift|unshift)\\('
rg -n -A 2 -B 2 $'\\$set\\(\\s*[^,]+\\.data' Length of output: 3166 Add Array guard to Vue 2 data watcher in table.ts The watcher should only trigger for arrays — otherwise objects (with undefined length) can cause unnecessary handleDataChange() calls. Verified the repo contains in-place mutations of Files to update / check:
Apply this diff: - data(array1, array2) {
- if (isVue2 && array1 === array2 && array1.length === array2.length) {
- this.handleDataChange()
- }
- }
+ data(array1, array2) {
+ // Guard non-array props and avoid unnecessary calls when data is an object
+ if (isVue2 && Array.isArray(array1) && array1 === array2 && array1.length === array2.length) {
+ this.handleDataChange()
+ }
+ } 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
created() { | ||||||||||||||||||||||||
|
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.
💡 Verification agent
🧩 Analysis chain
Make data-change refresh reset scroll and reflow — aligns with the bugfix objective
Switching
loadTableData(this.data, true)
toloadTableData(this.data)
will clear scroll and triggerrecalculate()
. This is consistent with fixing the abnormal scrollbar after data mutations. Note thatclearScroll()
already respectsfetchOption.isReloadScroll
, so consumers can still opt out of scroll reset.Two things to verify:
attemptRestoreScroll
with large-to-small data changes.isReloadScroll
).You can quickly scan for other internal callers that intend to preserve scroll by passing
true
toloadTableData
:🏁 Script executed:
Length of output: 3190
🏁 Script executed:
Length of output: 16901
🏁 Script executed:
Length of output: 8073
Make data-change refresh reset scroll and reflow — one remaining init caller to update
handleDataChange already calls loadTableData(this.data) (no notRefresh), so data-change will clear scroll and trigger recalc. However loadStatic still calls loadTableData(..., true) during initial prop load and should be updated if you want the same behavior on initial load.
Files to update / note:
Recommended change (table.ts):
Notes to verify:
🤖 Prompt for AI Agents