Skip to content

fix(popper): [tooltip,popover] fix popper doms in custom element, cant get zindex #3125

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Mar 14, 2025

PR

PR Checklist

修复popper用在自定义元素内部时,向上找父节点报错的问题。 ---- 同步代码
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
    • Enhanced UI element positioning and stacking by improving support for shadow DOM scenarios, ensuring consistent display and behavior.
  • Chores
    • Updated the package version and adjusted dependency ordering for improved package management.

Copy link

coderabbitai bot commented Mar 14, 2025

Walkthrough

This pull request modifies functions across several modules to improve support for shadow DOM elements. In particular, it adds conditional checks to detect if an element is encapsulated within a shadow DOM by verifying the existence of a host property. When such a property is found, the functions update their reference to the host element before proceeding with further logic. Additionally, the package version is updated and the dependency order in package.json is adjusted.

Changes

File(s) Change Summary
packages/renderless/src/.../popper.ts
packages/renderless/src/.../vue-popper.ts
packages/renderless/src/.../dom.ts
Added conditional checks for shadow DOM handling by verifying a host property and assigning the host element, ensuring proper DOM traversal in functions isFixed, getReferMaxZIndex, and hasDataTag.
packages/renderless/package.json Updated version from 3.21.1 to 3.21.2 and reordered dependencies (moved "color": "4.2.3" below "@opentiny/utils": "workspace:~").

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant isFixed
    participant Element
    Caller->>isFixed: Call isFixed(el)
    isFixed->>Element: Check if 'host' property exists
    alt Element has host (shadow DOM)
      isFixed->>Element: Set el = el.host
    end
    isFixed->>Element: Continue fixed positioning check recursively
Loading
sequenceDiagram
    participant Caller
    participant getReferMaxZIndex
    participant Reference
    Caller->>getReferMaxZIndex: Call getReferMaxZIndex(reference)
    getReferMaxZIndex->>Reference: Check if reference is ShadowRoot with a host
    alt Reference has host (shadow DOM)
      getReferMaxZIndex->>Reference: Set reference = reference.host
    end
    getReferMaxZIndex->>Reference: Calculate maximum z-index value
Loading
sequenceDiagram
    participant Caller
    participant hasDataTag
    participant Element
    Caller->>hasDataTag: Call hasDataTag(el, data-tag)
    hasDataTag->>Element: Check for host property (shadow DOM)
    alt Element has host
      hasDataTag->>Element: Set el = el.host
    end
    hasDataTag->>Element: Verify matching data attribute
Loading

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

I'm a bunny on a code spree,
Hopping through DOMs so tirelessly.
If an element hides within a shadow,
I find its host and let it go.
With each hop, the logic rings true,
Celebrating changes with a joyful "woo!"
🐇✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0be30ad and 83b710b.

📒 Files selected for processing (1)
  • packages/renderless/package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/renderless/package.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
  • GitHub Check: PR Unit Test

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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 Mar 14, 2025
Copy link

Walkthrough

此PR修复了在自定义元素内部使用popper时,无法正确获取父节点z-index的问题。通过处理shadowRoot的情况,确保popper在自定义元素中能够正常工作。

Changes

文件 概要
packages/renderless/src/common/deps/popper.ts 处理遇到shadowRoot的情况,确保正确获取父节点。
packages/renderless/src/common/deps/vue-popper.ts 处理shadowRoot的情况,确保正确获取z-index。
packages/renderless/src/grid/utils/dom.ts 修复shadowRoot没有getAttribute方法的问题,确保正确获取data-tag。

@@ -180,11 +180,15 @@ export const colToVisible = ($table, column, move) => {
}

export const hasDataTag = (el, value) => {
// el可能为shadow-root,shadow-root没有getAttribute方法
if (!el || !value || !el.getAttribute) {
if (!el || !value) {

Choose a reason for hiding this comment

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

The removal of the check for el.getAttribute could lead to runtime errors if el is not a valid DOM element or does not have the getAttribute method. Consider adding a check to ensure el is a valid DOM element before calling getAttribute. This will prevent potential runtime errors.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Walkthrough

This PR fixes the issue where the parent node z-index cannot be properly obtained when using popper inside a custom element. By handling shadowRoot situations, make sure that popper works properly in custom elements.

Changes

Documents Summary
packages/renderless/src/common/deps/popper.ts Handle shadowRoot to ensure that the parent node is properly obtained.
packages/renderless/src/common/deps/vue-popper.ts Handle shadowRoot situation and make sure to get z-index correctly.
packages/renderless/src/grid/utils/dom.ts Fixed the issue where shadowRoot has no getAttribute method to make sure the data-tag is correctly obtained.

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 (2)
packages/vue-hooks/package.json (2)

5-5: New "author" Field Added
An empty "author" field is now included. Consider filling this with the appropriate author information (e.g., name and/or email) to improve package metadata clarity.


7-7: "Keywords" Field Introduced
A "keywords" field (currently empty) has been added. To enhance package discoverability, consider adding relevant keywords in future updates.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 16d50e5 and 0be30ad.

📒 Files selected for processing (3)
  • packages/renderless/package.json (2 hunks)
  • packages/utils/package.json (2 hunks)
  • packages/vue-hooks/package.json (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/utils/package.json
  • packages/renderless/package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (3)
packages/vue-hooks/package.json (3)

3-3: Version Bump Confirmation
The version update from "3.21.0" to "3.21.1" is correctly reflected and indicates a minor release.


6-6: Explicit License Declaration
Adding the "license" field with the value "ISC" improves clarity regarding the terms under which the package is distributed.


17-19: Workspace Dependency Version Specifier Verification
The dependency declaration for "@opentiny/vue-common" uses the "workspace:~" specifier. Please verify that this specifier works as intended in the monorepo build environment and aligns with the versioning policies across packages.

@shenjunjian shenjunjian force-pushed the shen/sync-popper-relaease3.21 branch from 0be30ad to 83b710b Compare March 17, 2025 02:08
@zzcr zzcr merged commit dad6a97 into release-3.21.0 Mar 17, 2025
9 of 10 checks passed
@kagol kagol deleted the shen/sync-popper-relaease3.21 branch April 14, 2025 12:27
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants