feat(react-grab): ghost-highlight similar component instances on shift-hover#455
Open
aidenybai wants to merge 2 commits into
Open
feat(react-grab): ghost-highlight similar component instances on shift-hover#455aidenybai wants to merge 2 commits into
aidenybai wants to merge 2 commits into
Conversation
…t-hover Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
…ewport updates Co-authored-by: Aiden Bai <aidenybai@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
2 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/react-grab/src/components/overlay-canvas.tsx">
<violation number="1" location="packages/react-grab/src/components/overlay-canvas.tsx:573">
P2: Key ghost animations by stable component identity, not array index. Reusing `ghost-${index}` can attach the previous animation state to a different matched instance when the ghost list changes order or size, causing ghosts to jump or morph incorrectly.</violation>
</file>
<file name="packages/react-grab/src/core/context.ts">
<violation number="1" location="packages/react-grab/src/core/context.ts:407">
P2: Shift-hover ghosting now scans the whole fiber tree on the interaction path, which can make pointer movement janky on large apps.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| } | ||
|
|
||
| ghostAnimations = bounds.map((ghostBounds, index) => { | ||
| const animationId = `ghost-${index}`; |
Contributor
There was a problem hiding this comment.
P2: Key ghost animations by stable component identity, not array index. Reusing ghost-${index} can attach the previous animation state to a different matched instance when the ghost list changes order or size, causing ghosts to jump or morph incorrectly.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/react-grab/src/components/overlay-canvas.tsx, line 573:
<comment>Key ghost animations by stable component identity, not array index. Reusing `ghost-${index}` can attach the previous animation state to a different matched instance when the ghost list changes order or size, causing ghosts to jump or morph incorrectly.</comment>
<file context>
@@ -501,6 +554,41 @@ export const OverlayCanvas: Component<OverlayCanvasProps> = (props) => {
+ }
+
+ ghostAnimations = bounds.map((ghostBounds, index) => {
+ const animationId = `ghost-${index}`;
+ const existingAnimation = existingGhostById.get(animationId);
+
</file context>
| const seenElements = new Set<Element>(); | ||
| const similarElements: Element[] = []; | ||
|
|
||
| traverseFiber(rootFiber, (currentFiber) => { |
Contributor
There was a problem hiding this comment.
P2: Shift-hover ghosting now scans the whole fiber tree on the interaction path, which can make pointer movement janky on large apps.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/react-grab/src/core/context.ts, line 407:
<comment>Shift-hover ghosting now scans the whole fiber tree on the interaction path, which can make pointer movement janky on large apps.</comment>
<file context>
@@ -362,6 +364,65 @@ export const getComponentDisplayName = (element: Element): string | null => {
+ const seenElements = new Set<Element>();
+ const similarElements: Element[] = [];
+
+ traverseFiber(rootFiber, (currentFiber) => {
+ if (currentFiber === targetFiber) return;
+ if (!isCompositeFiber(currentFiber)) return;
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When you hold Shift while hovering over an element (in active grab mode), React Grab now finds the nearest React component for the hovered element, traverses the fiber tree from its root with bippy to locate every other instance of the same component, and renders dashed "ghost" highlights over each instance's nearest DOM node.
This makes it easy to see, at a glance, everywhere a given component is rendered on the page.
How
core/context.ts— newfindSimilarComponentElements(element):getType.fiber.returnto the tree root, thentraverseFibers the whole tree collecting composite fibers whosegetTypematches.getNearestHostFiber(...).stateNode, skipping the originally hovered node, disconnected nodes, and duplicates.components/overlay-canvas.tsx— new compositorghostlayer drawn beneath the live selection box, using a dashed stroke and reduced opacity so it reads as a secondary, "ghosted" highlight. Ghosts fade in via opacity and follow scroll/viewport changes like the selection layer.core/index.tsx— tracks whether Shift is held (pointermove / keydown / keyup, reset on deactivate and window blur), derivessimilarComponentElementsreactively (only while hovering — not during multi-select, drag, prompt, frozen, or context-menu phases), and feedsghostBounds/ghostVisibleto the renderer.constants.ts— ghost overlay colors, dash length, and opacity.types.ts/renderer.tsx— thread the newghostVisible/ghostBoundsprops through.The feature is purely additive and visual; it does not change selection/copy behavior or the existing Shift-click multi-select.
Verification
pnpm build,pnpm typecheck,pnpm lint,pnpm formatall pass.Summary by cubic
Add Shift-hover ghost highlighting in
react-grabto show all other instances of the same React component. Also decouples similar-component detection from scroll/viewport updates to avoid extra fiber traversals.New Features
bippyto resolve the component type, traverse the fiber tree, and collect nearest host nodes (skips the hovered one, duplicates, and disconnected nodes).overlay-canvaswith dashed stroke, low opacity, and fade-in; rendered beneath selection and synced with scroll.ghostVisible/ghostBoundsand ghost style constants throughtypes,renderer, and canvas.Refactors
Written for commit d044551. Summary will update on new commits.