Repository navigation
Reuse hint: "<Card> appears 3 times on this page" — this one, or the component? - #28
Closed
gowtham012 wants to merge 1 commit into
Closed
gowtham012 wants to merge 1 commit into
gowtham012 wants to merge 1 commit into
Conversation
When the picked element belongs to a component rendered more than once,
the comment box says "<Card> appears 3 times on this page" and offers
"Just this one" / "Everywhere (the component)" (nothing chosen by
default). The note carries element.reuse = {component, count, estimate,
scope?}; the agent's markdown gets a "Reused:" line, and when no scope
was chosen it is told to ask with reply_annotation before editing the
shared component. The MCP instructions say the same.
Detection (inspector.js, MAIN world, one new function + one call):
React counts fibers of the nearest component's type in the committed
tree from the HostRoot; Vue 3 walks the app root's vnode/instance tree;
plain HTML estimates from tag + classes + parent tag/classes. Capped at
500 matches / 50k nodes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Included in #30 (merged), together with fixes found by testing on real Vite/React/Next/webpack/Vue production builds. |
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 the picked element belongs to a component rendered more than once, the comment box shows a one-line hint (
<ProductCard> appears 6 times on this page) with two toggle buttons: Just this one / Everywhere (the component). Neither is chosen by default, and clicking the chosen one again clears it. Both are plain<button aria-pressed>elements inside a labelled group, so they work with Tab, Space and Enter.element.reuse = { component, count, estimate, scope? }, wherescopeis"instance"or"component"and is only set when the developer picks one.toMarkdown, soget_pending_annotationsandget_annotationboth show it):- Reused: <Card> is rendered 3 times on this page. Scope: the component | just this instance | not specified — … ask with reply_annotation before editing if unclear.The component name is flattened like other page data. The scope text always comes from a fixed table, so it can't carry page text (Object.hasOwn, so"constructor"doesn't sneak through).Detection (inspector.js, MAIN world: one new
reuseHint()plus one call ininspect())typein the committed tree (HostRoot.stateNode.current), going depth-first by child and sibling.__vueParentComponent, go up to the app's root instance, then walksubTreevnodes (component subtrees, children arrays, the active Suspense branch) and count instances with the sametype.estimate: trueand shown asdiv.card > h3 … (estimate). Skipped when neither the element nor its parent has a class.Tests
test/e2e-reuse.test.mjs(browser, ports P+12/S+12): React Card ×3 (hint, keyboard choice of "Everywhere", stored scope, markdown via MCPget_annotation); React Hero ×1 (no hint, noreuse); Vue PriceCard ×2 ("Just this one"); plain HTML 4 cards (estimate, choice cleared → "not specified"); plain single button (no hint).test/reuse-bridge.test.mjs: markdown for each scope, the estimate and 500+ wording, no line for bad counts, flattening of an injection attempt, and the MCP instruction sentence.🤖 Generated with Claude Code