Skip to content

feat(polyfill): Move querySelector polyfill from jitsi-meet and migrate to TypeScript#77

Merged
hristoterezov merged 1 commit intomasterfrom
query-selector-polyfill
Oct 17, 2025
Merged

feat(polyfill): Move querySelector polyfill from jitsi-meet and migrate to TypeScript#77
hristoterezov merged 1 commit intomasterfrom
query-selector-polyfill

Conversation

@hristoterezov
Copy link
Member

@hristoterezov hristoterezov commented Oct 17, 2025

Summary

Moves the querySelector/querySelectorAll polyfill from jitsi-meet repository to @jitsi/js-utils for better reusability across Jitsi projects. Converts the implementation to TypeScript and adds robust support for Document, DocumentFragment, and Element node types.

Changes

  • Moved polyfill from jitsi-meet to @jitsi/js-utils for shared usage
  • Migrated to TypeScript with full type safety and proper interfaces
  • Removed all unsafe type assertions using function overload pattern with boolean parameters
  • Added proper Node type support:
    • _getSearchElements() helper handles Document/DocumentFragment/Element nodes
    • querySelector/querySelectorAll check root elements before searching descendants
    • Internal functions simplified to only accept Element type
  • Added try-catch for complex selectors when checking root element matches
  • Updated tsconfig.json to include the new TypeScript polyfill
  • Clean overload pattern for all internal functions (no as any assertions)

Benefits

  • ✅ Shared polyfill reduces code duplication across Jitsi projects
  • ✅ TypeScript provides better type safety and IDE support
  • document.querySelector('html') correctly finds the root element
  • documentFragment.querySelector() works properly
  • ✅ XML documents with any root element name are supported
  • ✅ Complex selectors like 'body > div' work correctly with Document nodes
  • ✅ Zero unsafe type assertions in the codebase

Test Plan

  • Run npm run build - TypeScript compilation passes
  • Run npm run lint - ESLint passes with no errors
  • Test with jitsi-meet integration
  • Verify polyfill works with Document, DocumentFragment, and Element nodes
  • Test with simple selectors ('html', 'body', 'div')
  • Test with complex selectors ('body > div', :scope > span')

…te to TypeScript

Moves the querySelector/querySelectorAll polyfill from jitsi-meet repository to
js-utils for better reusability across Jitsi projects. Converts the implementation
to TypeScript and adds robust support for Document, DocumentFragment, and Element
node types to ensure the polyfill works correctly across all supported DOM API surfaces.

Changes:
- Moved polyfill from jitsi-meet to @jitsi/js-utils
- Migrated to TypeScript with full type safety
- Added proper function overloads with boolean parameter pattern to avoid 'as any' assertions
- Implemented _getSearchElements() helper to handle Document/DocumentFragment/Element nodes
- Updated querySelector/querySelectorAll to check root elements before searching descendants
- Simplified internal functions to only accept Element type
- Added try-catch blocks for complex selectors when checking root element matches
- Updated tsconfig.json to include the TypeScript polyfill
- All internal functions use clean overload pattern for type-safe boolean parameters

Benefits:
- Shared polyfill reduces code duplication across Jitsi projects
- TypeScript provides better type safety and IDE support
- document.querySelector('html') correctly finds the root element
- documentFragment.querySelector() works properly
- XML documents with any root element name are supported
- Complex selectors like 'body > div' work correctly with Document nodes
@hristoterezov hristoterezov force-pushed the query-selector-polyfill branch from ec8663a to 575964b Compare October 17, 2025 22:47
@hristoterezov hristoterezov merged commit 2eb9376 into master Oct 17, 2025
1 check passed
@hristoterezov hristoterezov deleted the query-selector-polyfill branch October 17, 2025 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants