Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(container-breakdown-observer): Fixes an issue where query parsing…
Browse files Browse the repository at this point in the history
… is not working in Edge.

Microsoft Edge will prepend `all and` to a query in window.matchMedia(). This will now be handled more gracefully and filtered out accordingly.

Closes #1346
  • Loading branch information
samuelfahrngruber authored and ffriedl89 committed Jul 27, 2020
1 parent 4552a95 commit d8e5453
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,16 @@ describe('Query', () => {
value: '300px',
});
});

it('should return an element query if its a valid query string but polluted with `all and`', () => {
window.matchMedia = () =>
({ media: 'all and (min-width: 300px)' } as any);

expect(convertQuery('(min-width: 300px)')).toMatchObject({
range: 'min',
feature: 'width',
value: '300px',
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ElementQuery {
value: string;
}

const QUERY_REGEX = /^\s*\(\s*(min|max)-(width|height)\s*:\s*([\w\d]+)\s*\)\s*$/;
const QUERY_REGEX = /^(?:\s*all\sand)*\s*\(\s*(min|max)-(width|height)\s*:\s*([\w\d]+)\s*\)\s*$/;

/** @internal */
// tslint:disable-next-line: interface-over-type-literal
Expand Down Expand Up @@ -60,6 +60,9 @@ export function convertQuery(query: string): ElementQuery | QueryResultToken {

// To filter out `not all`, corrupt strings or valid media queries
// we do not support (such as `screen`) we run it through our RegEx.
// Additionally this will remove any queries starting with `all and`
// as they are obsolete, but added by window.matchMedia(query)
// in Microsoft Edge.
const parts = converted.match(QUERY_REGEX);

return parts
Expand Down

0 comments on commit d8e5453

Please sign in to comment.