Media queries treat unknown and deprecated media types as `all` (`@media tv` matches, `not tv` does not)

Aberta Para iniciantes
#11,643 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
82/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
css, typescript
Domínio
frontend

Direção de pesquisa

Comece em packages/core/css-mediaquery/index.ts por volta da linha 138, onde um tipo desconhecido recorre a all; depois leia matchQuery/checkIfMediaQueryMatches para ver como o tipo da query é comparado ao tipo do contexto. Siga isso em packages/core/media-query-list (matchMedia) e no caminho _populateRules em packages/core/ui/styling/style-scope.ts. Execute a repro spec com npx nx run core:test -t 'unknown and deprecated media types'; concluído significa que tipos obsoletos/desconhecidos nunca correspondem, not tv corresponde, e os testes de media query existentes ainda passam.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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) and main (2a41eb1)
  • Node.js: v26.13.0
  • Platform-independent (shared @nativescript/core styling and matchMedia code)
Please accept these terms

Credit: https://ucsbplse.github.io/

Linguagem predominante
TypeScript
Estrelas
25.7k
Forks
1.7k
Merge médio
4d 2h
PRs com merge (30d)
41

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de NativeScript/NativeScript

Todas as issues de NativeScript/NativeScript

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.