Skip to content

Meta: Avoid failing silently for DOM searches - #8863

Closed
fregante with Copilot wants to merge 22 commits into
mainfrom
copilot/replace-select-dom-imports
Closed

fregante with Copilot wants to merge 22 commits into
mainfrom
copilot/replace-select-dom-imports

Conversation

Copilot AI commented Jan 10, 2026 •

Copy link
Copy Markdown
Contributor

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
Fix duplicate imports and TypeScript errors

Co-authored-by: fregante <[email protected]>
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 <[email protected]>
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
Comment thread source/features/deep-reblame.tsx Resolved
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 <[email protected]>
- 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 <[email protected]>
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
Comment thread source/features/clean-repo-tabs.tsx Resolved
Comment thread source/features/closing-remarks.tsx Resolved
Comment thread source/features/closing-remarks.tsx Resolved
Comment thread source/options/feature-list.tsx Resolved
Comment thread source/options/feature-list.tsx Resolved
Comment thread source/options/feature-list.tsx Resolved
Comment thread source/options/token-validation.tsx Resolved
Comment thread source/options.tsx Resolved
- 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 <[email protected]>
- 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 <[email protected]>
Comment thread source/features/closing-remarks.tsx Resolved
Comment thread source/options/token-validation.tsx Resolved
@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 <[email protected]>
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
Copy Markdown
Member

(placeholder for issue)

@fregante

Copy link
Copy Markdown
Member

@copilot list the top 10 longest files (LOC) in source/features.

Copilot AI commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot list the top 10 longest files (LOC) in source/features.

Top 10 longest files in source/features by lines of code:

  1. conversation-activity-filter.tsx - 286 LOC
  2. useful-not-found-page.tsx - 252 LOC
  3. unreleased-commits.tsx - 220 LOC
  4. comments-time-machine-links.tsx - 208 LOC
  5. update-pr-from-base-branch.tsx - 196 LOC
  6. netiquette.tsx - 193 LOC
  7. bugs-tab.tsx - 193 LOC
  8. select-notifications.tsx - 186 LOC
  9. quick-mention.tsx - 177 LOC
  10. github-actions-indicators.tsx - 175 LOC

@fregante

Copy link
Copy Markdown
Member

PITA, I still had to verify most of these, and some were unnecessary changes. Closing and it's best to just gradually fix it as necessary. Eventually we'll implement a lint rule and/or use strict exports as the main entry point of select-dom

@fregante fregante closed this Mar 10, 2026
@fregante
fregante deleted the copilot/replace-select-dom-imports branch March 10, 2026 11:56
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