Skip to content

Conversation

gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Aug 18, 2025

PR

修复在shadow dom下,表格部分target指向错误问题

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

    • Improved event handling across Grid/Table components for more reliable interactions, especially with complex/Shadow DOM structures.
    • More accurate “click outside” detection to clear selections and active states as expected.
    • More consistent blur behavior and scroll calculations, reducing intermittent glitches during navigation and scrolling.
  • Chores

    • Bumped Grid package version to 3.25.1.
    • Tidy dependency ordering with no user-facing impact.

Copy link

coderabbitai bot commented Aug 18, 2025

Walkthrough

Introduces a safer event target utility via optional chaining in utils and adopts it across Grid keyboard, table, and global mousedown handlers. Replaces direct event.target usage with getActualTarget(event). Also bumps the Grid package version to 3.25.1 and reorders a dependency entry.

Changes

Cohort / File(s) Summary
Utils: event target resolution
packages/utils/src/event/index.ts
Use optional chaining when accessing e.target.shadowRoot in getActualTarget; no API changes.
Vue Grid: keyboard handlers
packages/vue/src/grid/src/keyboard/src/methods.ts
Import getActualTarget and replace event.target checks with actualTarget for outside-click logic.
Vue Grid: table methods
packages/vue/src/grid/src/table/src/methods.ts
Import getActualTarget; replace event.target with getActualTarget(event) in blur and scroll logic.
Vue Grid: global mousedown handling
packages/vue/src/grid/src/table/src/utils/handleGlobalMousedownEvent.ts
Import getActualTarget; use actualTarget for header/content containment checks.
Package metadata
packages/vue/src/grid/package.json
Bump version 3.25.0 → 3.25.1; reorder dependencies to place @opentiny/utils at top (no net dependency change).

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant DOM Event
  participant getActualTarget
  participant Grid Components

  User->>DOM Event: Click/Scroll/MouseDown
  DOM Event->>getActualTarget: Resolve actual target (shadow DOM aware)
  getActualTarget-->>Grid Components: actualTarget
  Grid Components->>Grid Components: Containment checks, blur/clear/scroll logic
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A twitch of whiskers, a click in the night,
I trace the true target by softer light.
Through shadows I hop, past roots I peek,
The grid stays calm, the scrolls don’t squeak.
Patch hops to .1—carrot-sized delight!

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-target-error

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 18, 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

🧹 Nitpick comments (4)
packages/utils/src/event/index.ts (1)

61-61: Guard composedPath presence to avoid rare runtime errors

Optional chaining on target is good. For extra safety, also guard that composedPath exists before calling it, since some environments may not implement it even if composed is truthy.

Apply this diff:

-return e.target?.shadowRoot && e.composed ? e.composedPath()[0] || e.target : e.target
+return e.target?.shadowRoot && e.composed && typeof e.composedPath === 'function'
+  ? e.composedPath()[0] || e.target
+  : e.target
packages/vue/src/grid/src/table/src/methods.ts (3)

1216-1216: Avoid potential TypeError when args.cell is undefined

If args exists but args.cell is undefined, args?.cell.contains(...) can throw. Chain the cell as well.

Apply this diff:

-        if (args?.cell.contains(getActualTarget(event))) {
+        if (args?.cell?.contains(getActualTarget(event))) {
           return true
         }

1628-1632: Defensive access for scrollTop to handle unexpected targets

In rare cases, getActualTarget(event) might not be a scrollable element. Use optional chaining with a sane default to avoid runtime errors and keep pagination math stable.

Apply this diff:

-        let scrollTop = getActualTarget(event).scrollTop
+        const target = getActualTarget(event)
+        let scrollTop = (target && 'scrollTop' in (target as any)) ? (target as any).scrollTop : 0

1652-1654: Same here: guard scrollTop destructuring

Avoid destructuring from a possibly nullish or non-scrollable target.

Apply this diff:

-    let { scrollTop } = getActualTarget(event)
+    const target = getActualTarget(event)
+    const scrollTop = (target && 'scrollTop' in (target as any)) ? (target as any).scrollTop : 0
📜 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 3e3786d and 1eda66b.

📒 Files selected for processing (5)
  • packages/utils/src/event/index.ts (1 hunks)
  • packages/vue/src/grid/package.json (3 hunks)
  • packages/vue/src/grid/src/keyboard/src/methods.ts (2 hunks)
  • packages/vue/src/grid/src/table/src/methods.ts (5 hunks)
  • packages/vue/src/grid/src/table/src/utils/handleGlobalMousedownEvent.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/vue/src/grid/src/table/src/methods.ts (1)
packages/utils/src/event/index.ts (1)
  • getActualTarget (57-62)
packages/vue/src/grid/src/table/src/utils/handleGlobalMousedownEvent.ts (1)
packages/utils/src/event/index.ts (1)
  • getActualTarget (57-62)
packages/vue/src/grid/src/keyboard/src/methods.ts (1)
packages/utils/src/event/index.ts (1)
  • getActualTarget (57-62)
🔇 Additional comments (8)
packages/vue/src/grid/src/keyboard/src/methods.ts (2)

25-25: LGTM: centralizing target resolution

Importing getActualTarget here aligns target handling with Shadow DOM cases across the Grid.


670-677: Robust outside-click detection with Shadow DOM-aware target

Using actualTarget = getActualTarget(event) and the unified equalOrContain checks addresses retargeting issues under Shadow DOM while remaining null-safe (Node.contains accepts null).

packages/vue/src/grid/src/table/src/utils/handleGlobalMousedownEvent.ts (2)

25-25: LGTM: shared utility import

Pulling getActualTarget from utils is consistent with other modules.


82-89: Containment checks now honor Shadow DOM internals

Switching to actualTarget = getActualTarget(event) and using it for header/table containment removes false negatives when events originate inside shadow roots. Logic remains equivalent otherwise.

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

26-26: LGTM: import addition for Shadow DOM-aware targeting

This keeps target handling consistent across Grid internals.


1751-1751: LGTM: wheel containment uses actual target

Checking $el.contains(getActualTarget(event)) correctly treats wheel events originating inside shadow descendants as “inside”.

packages/vue/src/grid/package.json (2)

4-4: Version bump looks correct

3.25.1 aligns with a bugfix-level change.


15-16: Dependency reorder is fine

Relocating @opentiny/utils to the top keeps the dependency set unchanged.

Also applies to: 30-31

@zzcr zzcr merged commit 4366672 into dev Aug 18, 2025
10 of 11 checks passed
@zzcr zzcr deleted the cgm/fix-grid-target-error branch August 18, 2025 12:22
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.

2 participants