Skip to content

Conversation

@tclxshunquan-wang
Copy link
Contributor

@tclxshunquan-wang tclxshunquan-wang commented Jun 20, 2025

Fix: Resolved style override issues within Shadow DOM environments.
Fix: Addressed compatibility issues when setting the translate property on documentElement.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved style override issues within Shadow DOM contexts, ensuring consistent appearance in encapsulated environments.
    • Improved compatibility for CSS transformations by updating how the translate property is set, enhancing cross-browser support.
  • New Features

    • Added a helper function for reliably copying text to the clipboard, improving clipboard interaction across different environments.
  • Style

    • Refined panel and list item spacing, sizing, and font properties for improved visual consistency and readability.
  • Chores

    • Updated ESLint configuration to remove unnecessary React-specific rules for cleaner code linting.

@coderabbitai
Copy link

coderabbitai bot commented Jun 20, 2025

Walkthrough

This update focuses on improving the @hyperse/inspector-component package. It addresses style encapsulation in Shadow DOM, enhances cross-browser support for CSS transforms, and introduces a shared clipboard copy helper. Several components are refactored for style consistency, and overlay/panel DOM insertion points are adjusted for better compatibility.

Changes

Files/Groups Change Summary
.changeset/dull-geckos-run.md Adds a changeset describing Shadow DOM style fixes and CSS transform compatibility improvements.
packages/inspector-component/eslint.config.js Removes React-specific ESLint config, retaining only base and custom rules.
src/components/Panel.styled.tsx Refines spacing, font sizes, and weights for multiple styled panel components.
src/components/ShadowRoot.tsx Reorders imports and reformats JSX in useEffect; no functional changes.
src/helpers/helper-copy-text.ts Adds a new copyText helper for clipboard copying with fallback support.
src/overlay/Overlay.tsx, src/panel/InspectContextPanel.tsx Changes overlay/panel DOM insertion from body to documentElement (<html>).
src/overlay/OverlayTip.tsx Refactors and simplifies component structure; no logic changes.
src/panel/InspectContextPanelRoot.tsx Switches panel drag positioning from top/left to transform: translate(x, y).
src/panel/InspectListItem.tsx Replaces local clipboard copy function with the shared copyText helper.
src/panel/InspectPanel.tsx Reformats inline color style expressions for clarity; logic unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InspectPanel
    participant HelperCopyText
    User->>InspectPanel: Click "Copy" button
    InspectPanel->>HelperCopyText: copyText(text)
    HelperCopyText->>User: Copies text to clipboard (Clipboard API or fallback)
Loading
sequenceDiagram
    participant User
    participant InspectContextPanel
    participant DocumentElement
    User->>InspectContextPanel: Open panel
    InspectContextPanel->>DocumentElement: Append panel to <html> (documentElement)
Loading

Poem

In the garden of code, a bunny hops by,
With styles in the shadow and panels that fly.
Copying text with a magical touch,
Panels now float, but never too much.
From HTML roots, overlays bloom—
This patch brings tidiness back to the room!
🐇✨


📜 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 b87143e and 8d746d3.

📒 Files selected for processing (3)
  • packages/inspector-component/src/overlay/Overlay.tsx (2 hunks)
  • packages/inspector-component/src/overlay/OverlayTip.tsx (2 hunks)
  • packages/inspector-component/src/panel/InspectContextPanel.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/inspector-component/src/overlay/Overlay.tsx
  • packages/inspector-component/src/panel/InspectContextPanel.tsx
  • packages/inspector-component/src/overlay/OverlayTip.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (18.x)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

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: 4

🧹 Nitpick comments (3)
packages/inspector-component/src/overlay/OverlayTip.tsx (3)

42-69: Optional: Memoize outerBox calculation
outerBox is redefined on every render. Using useCallback with [boundingRect, boxSizing] will stabilize its reference and avoid unnecessary allocations.


86-89: Optional: Add transform fallback for broader browser support
The CSS translate property may not be supported in all target environments. Add a transform fallback for compatibility:

  style={{
    display: hidden ? 'none' : 'flex',
-   translate: position.translate,
+   translate: position.translate,
+   transform: `translate(${position.translate})`,
  }}

104-106: Nitpick: Use conditional rendering for the corner hint
Instead of toggling display, render <Overlay.OverlayCornerHint> only when showCornerHint is true for cleaner markup.

-    <Overlay.OverlayCornerHint style={{ display: showCornerHint ? 'block' : 'none' }}>
+    {showCornerHint && (
+      <Overlay.OverlayCornerHint>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 093c01c and b87143e.

📒 Files selected for processing (11)
  • .changeset/dull-geckos-run.md (1 hunks)
  • packages/inspector-component/eslint.config.js (1 hunks)
  • packages/inspector-component/src/components/Panel.styled.tsx (7 hunks)
  • packages/inspector-component/src/components/ShadowRoot.tsx (2 hunks)
  • packages/inspector-component/src/helpers/helper-copy-text.ts (1 hunks)
  • packages/inspector-component/src/overlay/Overlay.tsx (2 hunks)
  • packages/inspector-component/src/overlay/OverlayTip.tsx (2 hunks)
  • packages/inspector-component/src/panel/InspectContextPanel.tsx (2 hunks)
  • packages/inspector-component/src/panel/InspectContextPanelRoot.tsx (4 hunks)
  • packages/inspector-component/src/panel/InspectListItem.tsx (1 hunks)
  • packages/inspector-component/src/panel/InspectPanel.tsx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/dull-geckos-run.md

[grammar] ~6-~6: The word “translate” is a verb. The noun is spelled “translation”.
Context: ...d compatibility issues when setting the translate property on documentElement.

(PREPOSITION_VERB)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: deploy (20.x)
  • GitHub Check: test (18.x)
🔇 Additional comments (17)
packages/inspector-component/src/components/ShadowRoot.tsx (1)

1-1: LGTM: Code formatting improvements

The import reordering and JSX multi-line formatting enhance code readability without affecting functionality.

Also applies to: 17-19, 27-27

packages/inspector-component/eslint.config.js (1)

1-10: Verify if React-specific ESLint rules are still needed

The React-specific ESLint configuration was removed, leaving only the base configuration. For a React component package, this might result in missing important React-specific linting rules (e.g., missing keys, hooks rules, JSX-specific validations).

Please ensure that React-specific linting is either handled by the base configuration or that this removal is intentional.

packages/inspector-component/src/overlay/Overlay.tsx (2)

3-3: LGTM: Import reordering

The import reordering improves code organization.


26-26: Good change: Moving overlay to documentElement for better Shadow DOM compatibility

Appending the overlay to documentElement instead of body should improve style isolation and z-index stacking in Shadow DOM environments, which aligns with the PR objectives.

Please verify that overlay positioning and styling behavior remain correct after this change, especially for edge cases where body styles might have affected the overlay previously.

packages/inspector-component/src/panel/InspectListItem.tsx (1)

3-3: Excellent refactoring: Centralized clipboard copy functionality

Moving from a local copyText implementation to a shared helper function improves code reuse and maintainability. This ensures consistent clipboard behavior across all components.

.changeset/dull-geckos-run.md (1)

1-6: LGTM: Well-documented changeset

The changeset clearly describes the two main fixes: Shadow DOM style override issues and translate property compatibility on documentElement. The technical terminology is correct - "translate property" is the proper name for the CSS property.

packages/inspector-component/src/panel/InspectPanel.tsx (1)

96-99: LGTM! Improved code readability.

The reformatting of the inline style ternary expressions to multi-line format enhances readability while preserving the original logic and color values.

Also applies to: 107-110

packages/inspector-component/src/panel/InspectContextPanel.tsx (2)

3-3: LGTM! Import organization improvement.

The reordering of imports improves code organization without any functional impact.


28-28: ```shell
#!/bin/bash

Retry searching for DOM insertion points without file-type filters

rg -n "documentElement.appendChild|body.appendChild"


</details>
<details>
<summary>packages/inspector-component/src/panel/InspectContextPanelRoot.tsx (3)</summary>

`86-89`: **LGTM! Improved code formatting.**

The reformatted `panelStartPos` assignment enhances readability without changing functionality.

---

`103-103`: **Excellent improvement: Using transform for positioning.**

Switching from `top`/`left` properties to `transform: translate()` is a modern best practice that:
- Improves performance by leveraging GPU acceleration
- Better supports Shadow DOM style encapsulation
- Aligns with the PR's objective to fix translate property compatibility issues




Also applies to: 138-138

---

`158-159`: **Good baseline positioning setup.**

Setting explicit `top: 0` and `left: 0` provides a clean baseline for the `transform: translate()` positioning system.

</details>
<details>
<summary>packages/inspector-component/src/components/Panel.styled.tsx (3)</summary>

`48-48`: **LGTM! Enhanced button typography.**

Adding `font-weight: 600` improves the visual hierarchy and makes action buttons more prominent.

---

`60-60`: **Good spacing and sizing improvements.**

The changes enhance the panel's usability:
- Fixed height of 400px provides consistent panel sizing
- Increased padding (10px) improves content breathing room
- Font size adjustment (12px) enhances readability




Also applies to: 63-64

---

`80-80`: **Comprehensive visual consistency improvements.**

The spacing, sizing, and typography adjustments create a more cohesive and polished UI:
- Improved gaps and padding throughout components
- Consistent font sizing and weights
- Enhanced border radius for better visual appeal

These changes complement the Shadow DOM fixes by ensuring consistent presentation.



Also applies to: 89-93, 105-106, 123-123, 130-131, 146-146

</details>
<details>
<summary>packages/inspector-component/src/overlay/OverlayTip.tsx (2)</summary>

`1-8`: **Approve: Import consolidation**  
Consolidating React imports and types improves clarity and reduces redundancy.

---

`21-30`: **Approve: Prop destructuring and defaults**  
Destructuring props with a default for `cornerHintText` is concise and clear.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +1 to +27
export const copyText = (text: string) => {
if (navigator.clipboard) {
try {
void navigator.clipboard.writeText(text);
} catch (err) {
console.log(err);
}
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof document.execCommand === 'function') {
try {
const input = document.createElement('textarea');
input.setAttribute('readonly', 'readonly');
input.value = text;
document.body.appendChild(input);
input.select();
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (document.execCommand('copy')) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
document.execCommand('copy');
}
document.body.removeChild(input);
} catch (error) {
console.log(error);
}
}
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the redundant execCommand call and improve error handling.

The helper function has good structure with proper fallback, but contains a logic error and could be improved:

  1. Critical Issue: Lines 18-20 call execCommand('copy') twice redundantly
  2. Improvement: Consider returning success/failure status and providing more informative error messages

Apply this diff to fix the logic error:

-      if (document.execCommand('copy')) {
-        // eslint-disable-next-line @typescript-eslint/no-deprecated
-        document.execCommand('copy');
-      }
+      // eslint-disable-next-line @typescript-eslint/no-deprecated
+      document.execCommand('copy');

Consider enhancing the function to return success status:

-export const copyText = (text: string) => {
+export const copyText = (text: string): Promise<boolean> | boolean => {
   if (navigator.clipboard) {
     try {
-      void navigator.clipboard.writeText(text);
+      return navigator.clipboard.writeText(text).then(() => true).catch((err) => {
+        console.error('Clipboard API failed:', err);
+        return false;
+      });
     } catch (err) {
-      console.log(err);
+      console.error('Clipboard API failed:', err);
     }
   }
   // ... rest of fallback logic with similar improvements
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const copyText = (text: string) => {
if (navigator.clipboard) {
try {
void navigator.clipboard.writeText(text);
} catch (err) {
console.log(err);
}
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof document.execCommand === 'function') {
try {
const input = document.createElement('textarea');
input.setAttribute('readonly', 'readonly');
input.value = text;
document.body.appendChild(input);
input.select();
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (document.execCommand('copy')) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
document.execCommand('copy');
}
document.body.removeChild(input);
} catch (error) {
console.log(error);
}
}
};
export const copyText = (text: string) => {
if (navigator.clipboard) {
try {
void navigator.clipboard.writeText(text);
} catch (err) {
console.log(err);
}
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof document.execCommand === 'function') {
try {
const input = document.createElement('textarea');
input.setAttribute('readonly', 'readonly');
input.value = text;
document.body.appendChild(input);
input.select();
// eslint-disable-next-line @typescript-eslint/no-deprecated
document.execCommand('copy');
document.body.removeChild(input);
} catch (error) {
console.log(error);
}
}
};
🤖 Prompt for AI Agents
In packages/inspector-component/src/helpers/helper-copy-text.ts lines 1 to 27,
remove the redundant second call to document.execCommand('copy') inside the
fallback block to fix the logic error. Additionally, enhance the function by
returning a boolean indicating success or failure of the copy operation and
improve error handling by logging more informative error messages that specify
which method failed.

@tianyingchun tianyingchun merged commit e5e7cb8 into hyperse-io:main Jun 20, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants