Skip to content

Conversation

@gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Dec 18, 2025

PR

修复插入的数据rowIndex不正确问题

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Bug Fixes

    • Cache now updates immediately after row inserts/deletes so the table view stays in sync and avoids stale displays.
  • Improvements

    • Internal caching and full-data backing redesigned for more reliable behavior with large tables and virtual scrolling.
    • Virtual-scroll detection and data preparation refined to reduce unexpected rendering glitches.
  • Style

    • Slight sticky-header color adjustment for improved visual consistency.
  • Tests

    • Adjusted date-filter test input targeting to stabilize the behavior under multiple date fields.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the bug Something isn't working label Dec 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Walkthrough

Cache handling moved from a backupInfos structure to a per-rowid Map and tableFullData is now the canonical source; updateCache() is invoked after record insertions/removals; scrollYLoad and tableFullData are initialized on rawDataVersion changes; a sticky-header CSS variable was adjusted.

Changes

Cohort / File(s) Summary
Edit operations — ensure cache refresh
packages/vue/src/grid/src/edit/src/methods.ts
Added calls to updateCache() after inserting and after removing records so the cache is refreshed before subsequent UI/state updates.
Table cache & origin-row refactor
packages/vue/src/grid/src/table/src/methods.ts, packages/vue/src/grid/src/table/src/table.ts
Replaced backupInfos with a rowidCacheMap (Map) exposed on the table instance; updateCache() and backup creation now iterate tableFullData and populate rowidCacheMap keyed by computed rowid; getOriginRow/setOriginRow read/write from rowidCacheMap; backupInfos removed. rowidCacheMap initialized and cleared on unmount.
Raw data → full-data setup for virtual scroll
packages/vue/src/grid/src/composable/useNormalData.ts
On rawDataVersion change compute tableFullData, derive optimizeOpts/scrollY, set $table.tableFullData and $table.scrollYLoad (based on scrollY.gt and data length), then call $table.updateCache() and $table.handleDataChange().
Edit methods: cache call placement
packages/vue/src/grid/src/edit/src/methods.ts
Ensured updateCache() calls are placed immediately after mutations (insert/remove) while preserving existing downstream calls (handleTableData, checkSelectionStatus, updateFooter, etc.).
Theme minor style tweak
packages/theme-saas/src/grid/table.less
Changed sticky header background variable from --tiny-color-fill-8-solid to --tiny-color-fill-8 (fallback #f4f6fb unchanged).
Test adjustment
examples/sites/demos/pc/app/grid/filter/simple-date-filter.spec.ts
Modified which date input is targeted for the second date selection (changed from nth(1) to the first matching textbox).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Verify rowid computation is correct and produces unique stable keys.
  • Confirm rowidCacheMap is properly initialized, populated in updateCache, and cleared on unmount.
  • Ensure all references to backupInfos were removed/updated.
  • Check virtual-scroll edge cases: tableFullData population and scrollYLoad decisions.
  • Review timing: updateCache() placement in edit flows doesn’t conflict with selection/footer updates or introduce race conditions.
  • Spot-check visual effect of CSS variable change in sticky headers.

Poem

🐇 I hopped through rows both old and new,

I cached each id in morning dew,
Insert, remove — I nudge and hum,
Full-data sings where bytes become,
A rabbit's cheer for caches true.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(grid): fix insert rowIndex error' is partially related to the changeset. While it mentions fixing a rowIndex error in the grid, the actual changes go beyond this—they implement a significant refactoring from backupInfos to rowidCacheMap architecture and related data flow changes. The title captures only one aspect of the broader changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cgm/fix-insert-rowindex

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 604e55b and 099ff16.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/grid/filter/simple-date-filter.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (1)
examples/sites/demos/pc/app/grid/filter/simple-date-filter.spec.ts (1)

16-16: Selector change is correct for sequential date picker interaction.

Line 16 correctly fills the first matching textbox because line 13's confirm action closes the first date picker modal. When line 15 opens the second date picker, it becomes the only active picker, making the textbox selector accurate without .nth(1). The sequential interaction pattern (confirm→close→open→fill) validates this change.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/vue/src/grid/src/table/src/methods.ts (1)

410-480: Consider performance optimization for bulk operations.

The current implementation rebuilds the entire cache on every updateCache() call. For typical single insert/remove operations this is fine, but if your grid supports bulk operations (inserting/removing many rows at once), you might want to consider:

  1. Batching: Only call updateCache() once after bulk operations complete
  2. Incremental updates: Update only affected row indexes instead of rebuilding the entire cache

The current implementation is correct and maintainable. This optimization would only be necessary if profiling shows performance issues with bulk operations.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 851cab3 and 733f72a.

📒 Files selected for processing (2)
  • packages/vue/src/grid/src/edit/src/methods.ts (2 hunks)
  • packages/vue/src/grid/src/table/src/methods.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
  • GitHub Check: verify-main-build
🔇 Additional comments (3)
packages/vue/src/grid/src/edit/src/methods.ts (2)

142-142: Correctly updates cache after inserting records.

This ensures fullDataRowIdData and fullDataRowMap are rebuilt to include the newly inserted rows with correct indexes, fixing the rowIndex error described in the PR.


216-216: Correctly updates cache after removing records.

This maintains cache consistency by recalculating row indexes for all remaining rows after removal, ensuring symmetry with the insert operation.

packages/vue/src/grid/src/table/src/methods.ts (1)

411-412: Critical fix: Cache now reflects current data state including insertions.

Changing the data source from rawData to tableFullData is essential for this fix:

  • rawData: Original data source (doesn't include inserted rows)
  • tableFullData: Current table data (includes inserted rows)

This ensures that when updateCache() is called after insert operations, the cache includes the newly inserted rows with correct indexes.

@gimmyhehe gimmyhehe changed the title fix(grid): fix insert rowIndex error fix(grid): fix insert rowIndex error Dec 19, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/vue/src/grid/src/table/src/methods.ts (1)

404-461: rowidCacheMap state loss due to requestIdleCallback overwrite

The updateCache method schedules a requestIdleCallback that creates a new local rowidCacheMap and overwrites this.rowidCacheMap on line 461. This destroys any state changes made via setOriginRow() between updateCache calls.

For example, in reloadRow() (lines 369-372):

  1. setOriginRow(row, backupRow) modifies rowidCacheMap directly
  2. updateCache() schedules a callback
  3. When the callback executes, it creates a fresh rowidCacheMap and overwrites the instance, losing the changes from setOriginRow

This pattern occurs in edit operations where setOriginRow() and updateCache() are called in sequence. The asynchronous requestIdleCallback callback can execute after subsequent synchronous edits, causing state loss.

Consider deferring the rowidCacheMap assignment until the callback completes, or ensuring setOriginRow changes persist across updateCache invocations.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 733f72a and 604e55b.

📒 Files selected for processing (4)
  • packages/theme-saas/src/grid/table.less
  • packages/vue/src/grid/src/composable/useNormalData.ts
  • packages/vue/src/grid/src/table/src/methods.ts
  • packages/vue/src/grid/src/table/src/table.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-04T09:35:13.159Z
Learnt from: zzcr
Repo: opentiny/tiny-vue PR: 2481
File: packages/theme/src/time-range/vars.less:27-28
Timestamp: 2024-11-04T09:35:13.159Z
Learning: 在 `packages/theme/src/time-range/vars.less` 文件中,应使用 `var(--tv-TimeRange-header-height)` 作为 `--tv-TimeRange-header-line-height` 的值,以保持一致性。

Applied to files:

  • packages/theme-saas/src/grid/table.less
🧬 Code graph analysis (1)
packages/vue/src/grid/src/table/src/methods.ts (1)
packages/renderless/src/grid/utils/common.ts (1)
  • getRowid (39-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (6)
packages/theme-saas/src/grid/table.less (1)

1449-1449: PR scope mismatch: CSS styling change in rowIndex fix PR.

This PR is titled "fix(grid): fix insert rowIndex error," yet the modification at line 1449 is a CSS variable styling change. CSS styling adjustments cannot address rowIndex logic issues.

The change itself appears safe—using var(--tiny-color-fill-8, #f4f6fb) is consistent with lines 196, 201, and 231 elsewhere in the file. However, clarify whether:

  1. Other files in this PR contain the actual rowIndex logic fix
  2. This CSS change is incidental or directly related to the stated issue
packages/vue/src/grid/src/table/src/table.ts (2)

788-788: LGTM!

Proper cleanup of the rowidCacheMap on unmount to prevent memory leaks.


811-811: LGTM!

Introduction of rowidCacheMap provides a cleaner per-rowid caching mechanism, replacing the previous backupInfos approach. The Map is properly initialized and exposed via the setup return.

Also applies to: 847-848

packages/vue/src/grid/src/table/src/methods.ts (2)

291-291: LGTM!

Removal of destructuring is appropriate since tableFullData is now set upstream in useNormalData.ts and accessed via this when needed.


328-336: LGTM!

The refactored origin row management using rowidCacheMap is cleaner and more direct. The null checks are appropriate and handle the case where getRowid returns an empty string.

packages/vue/src/grid/src/composable/useNormalData.ts (1)

67-75: The review comment flags a non-issue. Code is safe by design.

The concern about accessing scrollY.gt without checking if scrollY exists is unfounded. scrollY is always defined in the default GlobalConfig.optimization with gt: 500. The optimizeOpts computed property uses extend() to merge defaults with user props, ensuring scrollY and scrollY.gt always exist. The scrollY && check on line 74, while redundant, does not cause harm. The suggested additional check (scrollY.gt &&) is unnecessary and based on incorrect assumptions about the code's safety.

@zzcr zzcr merged commit d708e25 into dev Dec 23, 2025
9 of 10 checks passed
@zzcr zzcr deleted the cgm/fix-insert-rowindex branch December 23, 2025 11:41
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.

3 participants