Media queries treat unknown and deprecated media types as `all` (`@media tv` matches, `not tv` does not)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- css, typescript
- 领域
- frontend
调研方向
从 packages/core/css-mediaquery/index.ts 第 138 行附近开始,这里未知类型会回退到 all;然后阅读 matchQuery/checkIfMediaQueryMatches,了解查询类型如何与上下文类型比较。沿着它进入 packages/core/media-query-list(matchMedia)以及 _populateRules 路径所在的 packages/core/ui/styling/style-scope.ts 中。用 npx nx run core:test -t 'unknown and deprecated media types' 运行 repro spec;完成意味着 deprecated/unknown 类型从不匹配,not tv 匹配,并且现有的 media-query 测试仍然通过。
由索引模型根据 Issue 内容生成。
描述
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/
- 主要语言
- TypeScript
- 星标
- 25.7k
- 派生
- 1.7k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 41
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NativeScript/NativeScript 的其他 Issue
-
bug css
难度 2/5 1-3 小时 新手友好度 70/100
NativeScript/NativeScript#11525 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 22/100
NativeScript/NativeScript#11639 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
NativeScript/NativeScript#11631 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
NativeScript/NativeScript#11630 · 3 条评论 ·
维护者通常 1 天内回复
-
iOS variable fonts ignore computed font-weight and normal weight defaults可能已有人在做 @aleclarson 于 9 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
NativeScript/NativeScript#11618 ·
维护者通常 1 天内回复
查看 NativeScript/NativeScript 的全部 Issue
相似的 Issue
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
难度 2/5 1-3 小时 新手友好度 68/100
openclaw/openclaw#199885 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
-
feature needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
BoardGamesEmpire/board-games-empire-backend#1306 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
sequant-io/sequant#1689 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100