Skip to content

fix(grid): fix user passed scrollY value is null #3658

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Aug 21, 2025

PR

修复用户主动将scrollY 传值为Null时的报错

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
    • Prevents rare runtime errors when calculating row height in tables without a vertical scroll configuration.
    • Maintains existing fallback behavior for row heights, ensuring consistent display.
    • No impact on header row height; overall stability improved without altering visible behavior.

Copy link

coderabbitai bot commented Aug 21, 2025

Walkthrough

Adds a null-safe access when computing rowHeight in the table component, changing scrollY.rHeight to scrollY?.rHeight to avoid runtime errors when scrollY is undefined. No API/signature changes.

Changes

Cohort / File(s) Summary of Changes
Row height null-guard
packages/vue/src/grid/src/table/src/table.ts
Use optional chaining on scrollY (scrollY?.rHeight) in rowHeight calculation; preserves existing fallbacks and leaves header computation unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

I nudge a nib with gentle might,
A question mark to guard the night—
If scrollY sleeps, we tiptoe by,
And still the rows are standing high.
Thump-thump, my paws approve this tweak;
Less crash, more carrots every week. 🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cgm/fix-grid-rHeight

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the bug Something isn't working label Aug 21, 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: 1

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

713-715: Prefer nullish coalescing (??) over logical OR (||) for numeric fallbacks

Using || will treat 0 as falsy and fall back to defaults. If 0 is ever a valid (even if unlikely) value for rHeight, it would be unintentionally overridden. ?? expresses the intent of “use default only when null/undefined.”

-        optimizeOpts.value?.scrollY?.rHeight ||
-        GlobalConfig.rowHeight[tinyTheme.value]?.[vSize.value || 'default'] ||
-        40
+        optimizeOpts.value?.scrollY?.rHeight ??
+        GlobalConfig.rowHeight[tinyTheme.value]?.[vSize.value || 'default'] ??
+        40
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4366672 and 5d6c709.

📒 Files selected for processing (1)
  • packages/vue/src/grid/src/table/src/table.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/vue/src/grid/src/table/src/table.ts (2)
packages/vue/src/grid-toolbar/src/index.ts (1)
  • vSize (313-315)
packages/vue/src/grid/src/grid/grid.ts (1)
  • vSize (181-183)
🔇 Additional comments (1)
packages/vue/src/grid/src/table/src/table.ts (1)

713-715: Null-safe access to scrollY prevents TypeError — LGTM

Changing scrollY.rHeight to scrollY?.rHeight correctly handles the case when users pass scrollY: null, avoiding runtime crashes during row height computation. Fallback order remains intact.

Comment on lines 711 to 716
const rowHeight = hooks.computed(
() =>
optimizeOpts.value?.scrollY.rHeight || GlobalConfig.rowHeight[tinyTheme.value]?.[vSize.value || 'default'] || 40
optimizeOpts.value?.scrollY?.rHeight ||
GlobalConfig.rowHeight[tinyTheme.value]?.[vSize.value || 'default'] ||
40
)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Add a regression test and scan for other unguarded scrollY dereferences

Given this bug class, add a test that mounts the grid with optimization: { scrollY: null } and asserts no error and that rowHeight resolves to theme/default values. Also, scan the repo for scrollY. accesses lacking optional chaining to prevent similar crashes elsewhere.

I can draft the unit test and open a follow-up PR to harden other call sites. To quickly scan the codebase, run:


🏁 Script executed:

#!/bin/bash
# Find potentially unsafe scrollY dereferences
rg -nP -C2 --type=ts '\bscrollY\.[A-Za-z_]\w*' -g '!**/dist/**' -g '!**/node_modules/**'

# Also check optimizeOpts-based paths
rg -nP -C2 --type=ts 'optimizeOpts(?:\.value)?\.scrollY\.[A-Za-z_]\w*' -g '!**/dist/**' -g '!**/node_modules/**'

Length of output: 2551


Guard all scrollY accesses and add a regression test

I’ve confirmed several unguarded scrollY dereferences beyond the original snippet. To prevent crashes when optimization.scrollY is null or undefined, please:

  • In packages/vue/src/grid/src/table/src/utils/computeScrollLoad.ts
    • Line 37: replace scrollY.vSize with scrollY?.vSize
    • Line 41: guard !scrollY.oSize as !scrollY?.oSize
    • Line 46: guard if (!scrollY.rSize) as if (!scrollY?.rSize)
    • (And similarly for any other direct scrollY.* usages)
  • In packages/vue/src/grid/src/table/src/methods.ts line 293
    • Change scrollY && scrollY.gt > 0 to scrollY?.gt > 0

After adding these guards (and providing sensible defaults where needed), please write a regression test that mounts the grid with:

optimization: { scrollY: null }

and asserts:

  1. No runtime error is thrown.
  2. rowHeight falls back to the theme’s default (e.g. GlobalConfig.rowHeight[tinyTheme.value]['default'] or 40).

This will catch any remaining unguarded access and prevent similar crashes in the future.

🤖 Prompt for AI Agents
In packages/vue/src/grid/src/table/src/table.ts around lines 711-716 and in
packages/vue/src/grid/src/table/src/utils/computeScrollLoad.ts (line ~37, 41, 46
and any other direct scrollY.* usages) and
packages/vue/src/grid/src/table/src/methods.ts line 293, guard all dereferences
of optimization.scrollY with optional chaining (e.g. replace scrollY.vSize with
scrollY?.vSize, !scrollY.oSize with !scrollY?.oSize, if (!scrollY.rSize) with if
(!scrollY?.rSize), and change scrollY && scrollY.gt > 0 to scrollY?.gt > 0), and
provide sensible defaults where needed so code still falls back to GlobalConfig
rowHeight or 40; then add a regression test that mounts the grid with
optimization: { scrollY: null } and asserts no runtime error and rowHeight falls
back to the theme default.

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.

1 participant