Media queries treat unknown and deprecated media types as `all` (`@media tv` matches, `not tv` does not)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- css, typescript
- Domain
- frontend
Research direction
Start at packages/core/css-mediaquery/index.ts around line 138, where an unknown type falls back to all; then read matchQuery/checkIfMediaQueryMatches to see how the query type is compared against the context type. Follow it into packages/core/media-query-list (matchMedia) and the _populateRules path in packages/core/ui/styling/style-scope.ts. Run the repro spec with npx nx run core:test -t 'unknown and deprecated media types'; done means deprecated/unknown types never match, not tv matches, and existing media-query tests still pass.
Written by the indexing model from the issue text.
Description
Issue Description
Runtime bug in @nativescript/core CSS media query parsing (packages/core/css-mediaquery/index.ts, line 138):
type: MediaQueryType[type ? type.toLowerCase() : 'all'] ?? 'all',
Because MediaQueryType only contains all, print, and screen, any other media type (tv, speech, handheld, projection, or an unknown identifier) falls back to 'all' instead of remaining distinct from 'screen'. Since checkIfMediaQueryMatches evaluates queries with type: MediaQueryType.screen, @media tv { ... } and @media speech { ... } rules are applied on every screen, matchMedia('tv').matches returns true, and @media not tv { ... } / matchMedia('not tv').matches evaluate to false.
Per Media Queries Level 4 section 2.3 and section 3.2 (and in browsers and upstream ericf/css-mediaquery), deprecated and unknown media types never match, and negating them with not evaluates to true.
Reproduction
Save as packages/core/css-mediaquery/repro.spec.ts and run npx nx run core:test -t 'unknown and deprecated media types':
import { matchQuery, MediaQueryType } from '.';
import { matchMedia } from '../media-query-list';
import { parse } from '../css';
import { StyleSheetSelectorScope } from '../ui/styling/css-selector';
import { _populateRules } from '../ui/styling/style-scope';
describe('unknown and deprecated media types', () => {
it('repro', () => {
const screen = { type: MediaQueryType.screen, width: 400, height: 800, orientation: 'portrait' };
console.log('matchQuery tv:', matchQuery('tv', screen));
console.log('matchQuery speech:', matchQuery('speech', screen));
console.log('matchQuery tv and portrait:', matchQuery('tv and (orientation: portrait)', screen));
console.log('matchQuery not tv:', matchQuery('not tv', screen));
console.log('matchQuery print:', matchQuery('print', screen));
console.log('matchMedia tv:', matchMedia('tv').matches);
console.log('matchMedia not tv:', matchMedia('not tv').matches);
const ast = parse(`
@media tv { button { color: red; } }
@media speech { button { color: orange; } }
@media not tv { button { color: green; } }
@media print { button { color: blue; } }
`);
const rulesets = [];
_populateRules(ast.stylesheet.rules, rulesets, []);
const matched = new StyleSheetSelectorScope(rulesets)
.query({ cssType: 'button' })
.selectors.map((s) => s.ruleset.declarations[0].value);
console.log('@media matched colors:', matched);
});
});
Expected output:
matchQuery tv: false
matchQuery speech: false
matchQuery tv and portrait: false
matchQuery not tv: true
matchQuery print: false
matchMedia tv: false
matchMedia not tv: true
@media matched colors: [ 'green' ]
Relevant log output (if applicable)
matchQuery tv: true
matchQuery speech: true
matchQuery tv and portrait: true
matchQuery not tv: false
matchQuery print: false
matchMedia tv: true
matchMedia not tv: false
@media matched colors: [ 'red', 'orange' ]
Environment
@nativescript/core:9.1.4(npm latest) andmain(2a41eb1)- Node.js:
v26.13.0 - Platform-independent (shared
@nativescript/corestyling andmatchMediacode)
Please accept these terms
- I have searched the existing issues as well as StackOverflow and this has not been posted before
- This is a bug report
- I agree to follow this project's Code of Conduct
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 25.7k
- Forks
- 1.7k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 41
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NativeScript/NativeScript
-
bug css
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NativeScript/NativeScript#11525 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 22/100
NativeScript/NativeScript#11639 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
NativeScript/NativeScript#11631 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
NativeScript/NativeScript#11630 · 3 comments ·
Maintainers usually reply within 1 day
-
iOS variable fonts ignore computed font-weight and normal weight defaultsPossibly taken @aleclarson claimed this 9 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
NativeScript/NativeScript#11618 ·
Maintainers usually reply within 1 day
All issues in NativeScript/NativeScript
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openclaw/openclaw#199885 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
feature needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
BoardGamesEmpire/board-games-empire-backend#1306 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
sequant-io/sequant#1689 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100