feat(polyfill): Move querySelector polyfill from jitsi-meet and migrate to TypeScript#77
Merged
hristoterezov merged 1 commit intomasterfrom Oct 17, 2025
Merged
Conversation
damencho
approved these changes
Oct 17, 2025
…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
ec8663a to
575964b
Compare
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
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
_getSearchElements()helper handles Document/DocumentFragment/Element nodesas anyassertions)Benefits
document.querySelector('html')correctly finds the root elementdocumentFragment.querySelector()works properly'body > div'work correctly with Document nodesTest Plan
npm run build- TypeScript compilation passesnpm run lint- ESLint passes with no errors'html','body','div')'body > div',:scope > span')