chore(element-selector): scaffold element selector types#1779
Open
jxiwang wants to merge 8 commits into
Open
Conversation
size-limit report 📦
|
b6a7080 to
b5fb5b7
Compare
Base automatically changed from
jessewang/sr-4560-eng-001-set-up-amplitudeelement-selector-package
to
main
May 28, 2026 22:34
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64876df to
f941f96
Compare
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
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.
Summary
Second PR in the v1 element-selector groundwork chain. Lands the static + primitive pieces of
@amplitude/element-selector: type definitions, both regex pattern packs, helper functions, and the two v1 strategies. Each piece is independently unit-tested — nothing drives them together yet. The orchestrator, fallback, config resolver, and engine factory land in the follow-up PR (SR-4609).Closes SR-4608.
What's in this PR
Types (
src/types.ts)Strategy,StrategyContext— pluggable-strategy interfaceResolvedSelectorConfig— runtime config consumed by strategies / orchestrator / fallbackElementSelectorRemoteConfig— remote-config payload shape (every field optional)SelectorEngine— public engine interface (implementation lands in the orchestration PR)Pattern packs
patterns/autogenerated-ids.ts—DEFAULT_AUTOGENERATED_ID_PATTERNS(ReactuseId, Radix, Headless UI, MUI, hex hashes, trailing-digit timestamps, 4+ consecutive digits) +compile()+isStableId()patterns/unstable-classes.ts—DEFAULT_UNSTABLE_CLASS_PATTERNS(Tailwind utilities + variants, CSS-in-JS / build hashes, Swiper / MUI / Radix runtime state classes) +compile()+filterClasses()Helpers
helpers/get-stable-id.ts— single source of truth for "is this element's id usable?" (honors the explicit-tracking-attribute suppression signal + the autogen filter)helpers/describe-relative.ts— positional descent builder, emitstag:nth-of-type(n)Strategies
strategies/explicit-tracking-attribute.ts— anchor ondata-amp-track-id(or the customer-configured attribute name)strategies/stable-id.ts— anchor ontag#idwhen the id survivesgetStableIdTests — one file per source file, all running on jsdom; pattern packs are table-driven with positive and negative cases drawn from real React / Radix / Headless UI / MUI / Swiper / Tailwind / CSS-modules / Emotion / styled-components samples.
What's NOT in this PR
fallbackCssPath→ SR-4609resolveSelectorConfig→ SR-4609createSelectorEnginefactory + the runtimeSelectorEngineinstance → SR-4609@amplitude/analytics-core→ SR-4641 (verification PR)Why a separate package
The selector algorithm needs to be consumed by three surfaces — the autocapture SDK plugin, the app.amplitude.com tagging UI, and the Chrome extension visual tagger. Standing it up as a shared package now avoids the "copy the algorithm into each consumer" pattern currently in place with the legacy
cssPath. Design doc atpackages/plugin-autocapture-browser/element-selector-strategy-v1-no-classes.md.Stack
Branches off SR-4560 (scaffolding, already merged). The next PR (SR-4609, orchestration) branches off this one.
Test plan
pnpm --filter @amplitude/element-selector testpassespnpm --filter @amplitude/element-selector lintpassespnpm --filter @amplitude/element-selector buildproduces both ESM + CJS outputtslib(logger integration arrives in SR-4641)src/index.tsthat aren't documented in the design docChecklist
Note
Low Risk
New library code and exports only; no runtime wiring to autocapture yet, and behavior is covered by unit tests.
Overview
This PR expands
@amplitude/element-selectorfrom a placeholder entry point into the v1 foundation: public types (Strategy,ResolvedSelectorConfig,ElementSelectorRemoteConfig,SelectorEngine), default autogenerated-id and unstable-class regex packs withcompile/isStableId/filterClasses, helpers (getStableId,describeRelative, internalescapeCssIdentifier), and the first two strategies (explicit tracking attribute, stabletag#id).index.tsnow re-exports that surface for SDK, dashboard, and extension consumers.Orchestrator, fallback walker, config resolver, and
SelectorEngineimplementation are intentionally out of scope (follow-up PR). Each new module ships with jsdom unit tests, including table-driven pattern coverage.Reviewed by Cursor Bugbot for commit 9758d21. Bugbot is set up for automated code reviews on this repo. Configure here.