Skip to content

Merge query helpers into one scopedQuery module - #2

Open
myabc wants to merge 1 commit into
mainfrom
refactor/scoped-query
Open

Merge query helpers into one scopedQuery module#2
myabc wants to merge 1 commit into
mainfrom
refactor/scoped-query

Conversation

@myabc

@myabc myabc commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Ticket

N/A — internal architecture review of this library.

What are you trying to accomplish?

Collapse two shallow query helpers into one deep module. queryOne/queryAll duplicated 16 lines each (guard, selector check, try/catch, warn-once) differing by two tokens, and the warn-once registry was a process-global Set whose only reset was a test-only export hidden from the barrel.

What approach did you choose and why?

  • One interface: scopedQuery(root, selector){ first, all, exists }. Guard, error policy, and warn-once live behind one seam; blessing.ts call sites collapse onto it.
  • Warn registry keyed per root element via WeakMap — lifetime becomes an implementation detail, dies with the element, tests need no reset hook. resetSelectorWarnings deleted (keeping the global Set + reset export would keep a test-only seam in production surface).
  • CONTEXT.md records the term + decision.

No public API change; patch changeset for the observable warn-scoping change.

Stacked on #1 (rewrote the blessing.ts call sites this touches). Chain: #6#1 ← this ← #4.

Verification: bun test 42 pass, bun run typecheck clean, bun run build clean.

Merge checklist

  • Added/updated tests
  • Lookbook docs n/a — npm library; CONTEXT.md updated
  • Tested major browsers n/a — internal refactor, behavior unchanged

Copilot AI lite review requested due to automatic review settings August 10, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR consolidates the internal DOM query helpers into a single scopedQuery(root, selector) module with a unified guard + invalid-selector warn-once policy, and updates call sites/tests accordingly. It also changes the warn-once registry to be scoped per root element (via WeakMap) and removes the prior test-only reset hook.

Changes:

  • Replace duplicated queryOne/queryAll with scopedQuery() returning { first, all, exists }.
  • Scope invalid-selector warnings per root element using WeakMap<Element, Set<string>>, removing resetSelectorWarnings.
  • Update tests and blessing call sites to use the new API and document the decision in CONTEXT.md (+ changeset).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/query.test.ts Migrates unit tests to scopedQuery() and adds per-root warn-once expectations.
test/integration.test.ts Removes now-unneeded resetSelectorWarnings() usage.
test/blessing.test.ts Removes now-unneeded resetSelectorWarnings() usage/import.
src/query.ts Introduces scopedQuery() and per-root warning registry via WeakMap.
src/blessing.ts Refactors element accessors to use scopedQuery().first/all/exists.
CONTEXT.md Documents “scoped query” and the per-root warn-once policy.
.changeset/quick-moles-search.md Adds patch changeset describing the internal refactor + observable warn scoping change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/query.ts
@myabc myabc added the bug Something isn't working label Aug 10, 2026
@myabc
myabc force-pushed the refactor/scoped-query branch from ee0a57a to 2439513 Compare August 10, 2026 18:50
@myabc
myabc force-pushed the refactor/scoped-query branch from 2439513 to 364367d Compare August 10, 2026 19:40
@myabc
myabc force-pushed the refactor/scoped-query branch from 364367d to 5e3e085 Compare August 10, 2026 20:48
Base automatically changed from fix/element-naming-rule to main August 10, 2026 20:49
queryOne and queryAll duplicated 16 lines each (falsy-root guard,
empty-selector check, try/catch, warn-once) differing by two tokens,
and the warn-once registry was a process-global Set whose only reset
was a test-only export hidden from the barrel — a seam cut for the
test harness, not for callers.

- replace both with scopedQuery(root, selector) returning
  { first, all, exists }; guard, error policy, and warn-once live
  behind one interface
- key the warn registry per root element via WeakMap: warning
  lifetime becomes an implementation detail, dies with the element,
  and tests need no reset hook
- delete resetSelectorWarnings and its imports from blessing and
  integration tests
- record the scoped-query term and warn-once decision in CONTEXT.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Development

Successfully merging this pull request may close these issues.

2 participants