Media queries treat unknown and deprecated media types as `all` (`@media tv` matches, `not tv` does not)
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) 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/
- Linguagem predominante
- TypeScript
- Estrelas
- 25.7k
- Forks
- 1.7k
- Merge médio
- 4d 2h
- PRs com merge (30d)
- 41
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de NativeScript/NativeScript
-
bug css
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
NativeScript/NativeScript#11525 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 22/100
NativeScript/NativeScript#11639 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
NativeScript/NativeScript#11631 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
NativeScript/NativeScript#11630 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
iOS variable fonts ignore computed font-weight and normal weight defaultsTalvez já em andamento @aleclarson assumiu há 9 dias. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
NativeScript/NativeScript#11618 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de NativeScript/NativeScript
Issues semelhantes
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
openclaw/openclaw#199885 · 2 comentários · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
feature needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
BoardGamesEmpire/board-games-empire-backend#1306 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
sequant-io/sequant#1689 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100