Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 10, 2026

Selective migration of select-dom imports to select-dom/strict.js for better type safety, while preserving non-strict utilities based on codebase conventions.

Changes

  • Selective import migration (~20 files):

    • $$$$ from strict (when elements are guaranteed to exist and should throw if not found)
    • $$optional from strict (when elements may not exist, e.g., reactions, optional UI elements)
    • lastElement(selector)lastElementOptional(selector) (when null-checked)
    • Used strict $ where non-null assertions (!) were already used
  • Preserved non-strict utilities:

    • Kept elementExists from non-strict 'select-dom' (42+ files unchanged)
    • Kept countElements from non-strict 'select-dom' where used
    • Kept $$ from non-strict in files where iteration over potentially empty arrays is the expected behavior (deep-reblame only)
  • Code quality fixes:

    • Removed all aliasing patterns (never use $$optional as $$)
    • Maintained original import order with external imports near the top
    • Consolidated duplicate imports across files

Example

# Use strict $$ where elements must exist (throws if not found)
- import {$$} from 'select-dom';
+ import {$$} from 'select-dom/strict.js';

# Use $$optional where elements may not exist (returns empty array)
- import {$$} from 'select-dom';
+ import {$$optional} from 'select-dom/strict.js';
- for (const reaction of $$(selector)) { ... }
+ for (const reaction of $$optional(selector)) { ... }

# Keep non-strict utilities unchanged
import {elementExists, countElements} from 'select-dom';
if (elementExists('.some-selector')) { ... }
const count = countElements('.items');

Files retain non-strict imports for elementExists, countElements, and ElementNotFoundError (not exported by strict version). Migration uses:

  • Strict $$ where elements are guaranteed to exist (closing-remarks, token-validation, and 11 other files)
  • $$optional where elements may not exist (highest-rated-comment for reactions, etc.)

Test URLs

Affects all pages where features use DOM selection. Tested on:

Screenshot

N/A - Internal refactoring with no UI changes

Original prompt

Replace all select-dom imports with select-dom/strict. If ! is used, then just use the strict version ($, $$); if there's an extistence check, use $optional, etc


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 10, 2026 07:35
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Fix duplicate imports and TypeScript errors

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
All select-dom imports now use select-dom/strict.js with proper mappings:
- $$ → $$optional (aliased as $$ for minimal changes)
- elementExists → $optional
- countElements → $$optional().length
- lastElement → lastElementOptional (when checking for null)

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace select-dom imports with select-dom/strict Migrate all select-dom imports to select-dom/strict Jan 10, 2026
Copilot AI requested a review from fregante January 10, 2026 07:52
Copilot AI and others added 2 commits January 10, 2026 08:47
…order

- Reverted actionable-pr-view-file.tsx to use elementExists
- Changed batch-mark-files-as-viewed.tsx to use $$ (strict) without aliasing
- Restored import order in deep-reblame.tsx

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
- Reverted 42 files to use elementExists from 'select-dom'
- Removed all '$$optional as $$' aliasing, using actual function names
- Fixed import order in multiple files
- Updated all usage to match new import patterns

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI changed the title Migrate all select-dom imports to select-dom/strict Migrate select-dom imports to select-dom/strict (partial) Jan 10, 2026
Copilot AI requested a review from fregante January 10, 2026 08:53
@fregante fregante changed the title Migrate select-dom imports to select-dom/strict (partial) Meta: Turn silent errors loud Jan 10, 2026
@fregante fregante changed the title Meta: Turn silent errors loud Meta: Fail loudly Jan 10, 2026
- Reverted clean-repo-tabs.tsx to use countElements (non-strict)
- Reverted deep-reblame.tsx to use $$ from non-strict select-dom
- Reverted token-validation.tsx to use $$ from non-strict select-dom
- Reverted closing-remarks.tsx completely (imports and usage)
- Changed $$optional to $$ (strict) in files where elements always exist:
  - close-out-of-view-modals.tsx
  - cross-deleted-pr-branches.tsx
  - hidden-review-comments-indicator.tsx
  - highest-rated-comment.tsx
  - no-duplicate-list-update-time.tsx
  - open-issue-to-latest-comment.tsx
  - quick-comment-hiding.tsx
  - release-download-count.tsx
  - click-all.ts
  - feature-list.tsx (3 instances)
  - options.tsx

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
- Changed from non-strict $$ to strict $$ (as intended)
- Moved import to correct position with other external imports (line 3)
- Consolidated imports: {$, $$} from 'select-dom/strict.js'

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
- closing-remarks.tsx: Changed from non-strict to strict $$ import
- token-validation.tsx: Changed from non-strict to strict $$ import
- Both files now use: import {$, $$} from 'select-dom/strict.js'

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI requested a review from fregante January 10, 2026 15:53
@fregante fregante marked this pull request as ready for review January 10, 2026 17:21
@fregante fregante changed the title Meta: Fail loudly Meta: Avoid failing silently for DOM searches Jan 10, 2026
@fregante fregante added the meta Related to Refined GitHub itself label Jan 10, 2026
@fregante fregante changed the title Meta: Avoid failing silently for DOM searches Avoid failing silently for DOM searches Jan 10, 2026
…exist

- Changed line 43 from $$ to $$optional for positiveReactionsSelector
- Changed line 95 from $$ to $$optional in selectSum function
- Added $$optional to imports
- Reactions may not exist on the page, so $$optional is appropriate

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI changed the title Avoid failing silently for DOM searches Meta: Fail loudly Jan 10, 2026
@fregante fregante changed the title Meta: Fail loudly Meta: Avoid failing silently for DOM searches Jan 10, 2026
@fregante
Copy link
Member

(placeholder for issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

2 participants