Skip to content

fix(h5): preserve zero in media query descriptors - #19704

Open
Jarvis636431 wants to merge 2 commits into
NervJS:mainfrom
Jarvis636431:codex/h5-media-query-zero
Open

Jarvis636431 wants to merge 2 commits into
NervJS:mainfrom
Jarvis636431:codex/h5-media-query-zero

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #19703

这个 PR 做了什么?

maxWidth: 0 等条件被真值判断过滤,导致 matchMedia 收到空查询。

保留显式的数值 0,覆盖六个尺寸条件和新旧监听模式。

这个 PR 是什么类型?

  • 错误修复 (Bugfix)

这个 PR 涉及以下平台:

  • Web 端(H5)

Summary by CodeRabbit

  • Bug Fixes
    • 修复媒体查询中显式设为 0 的宽度和高度条件被忽略的问题,确保查询包含对应的 CSS 属性和值。

验证结果

媒体查询定向 28 项测试通过,H5 全套 51 个套件、597 项测试通过。

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T08:21:19.427377Z af824d6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

媒体查询生成逻辑现在会保留显式设为 0 的非 orientation 描述符。新增测试覆盖六种尺寸条件,并检查生成的查询包含对应 CSS 属性名和 0px。

Changes

媒体查询尺寸零值

Layer / File(s) Summary
保留零值并验证尺寸条件
packages/taro-h5/src/api/wxml/MediaQueryObserver.ts, packages/taro-h5/__tests__/wxml/mediaQueryObserver.test.ts
generateMediaQueryStr 现在接受非 orientation 描述符的显式零值。参数化测试覆盖 width、minWidth、maxWidth、height、minHeight 和 maxHeight。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: heiazu, zakarycode, single-dancer

Merge Risk: Minimal · up to af824

This change makes explicit zero values in media query descriptors, such as maxWidth: 0, produce the correct query instead of being dropped. The change is small and tested, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(h5): preserve zero in media query descriptors”描述了主要变更:修复 H5 中媒体查询描述符的 0 值被真值判断丢弃的问题。变更摘要显示,六个尺寸条件(width、minWidth、maxWidth、height、minHeight、maxHeight)在显式设为 0 时,生成的查询现在会保留 0px。标题与变更集直接相关,并说明了主要改动…
Linked Issues check Passed [#19703] 要求保留显式数值 0,覆盖六个尺寸条件(width、minWidth、maxWidth、height、minHeight、maxHeight)以及新旧监听模式。

在 packages/taro-h5/src/api/wxml/MediaQueryObserver.ts 的 generateMediaQueryStr 中,条件由 descriptor[item] 改为 `(d…
Out of Scope Changes check Passed 整体 diff 仅包含两处变更:1)MediaQueryObserver.ts 中一行条件修改,仅影响尺寸描述符对数值 0 的处理;2)测试文件中新增一个 test.each,验证该修复。两处变更均直接服务于 #19703 的目标。未发现与该问题无关的变更。orientation 分支未被修改。
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

标题“fix(h5): preserve zero in media query descriptors”描述了主要变更:修复 H5 中媒体查询描述符的 0 值被真值判断丢弃的问题。变更摘要显示,六个尺寸条件(width、minWidth、maxWidth、height、minHeight、maxHeight)在显式设为 0 时,生成的查询现在会保留 0px。标题与变更集直接相关,并说明了主要改动点。

Full details: Linked Issues check

Explanation

[#19703] 要求保留显式数值 0,覆盖六个尺寸条件(width、minWidth、maxWidth、height、minHeight、maxHeight)以及新旧监听模式。

在 packages/taro-h5/src/api/wxml/MediaQueryObserver.ts 的 generateMediaQueryStr 中,条件由 descriptor[item] 改为 (descriptor[item] || descriptor[item] === 0)。因此数值 0 不再被真值判断过滤。后续的 Number(descriptor[item]) >= 0 检查保留,负数和 NaN 仍被过滤。输出为 (max-width: 0px) 等形式。

在 packages/taro-h5/tests/wxml/mediaQueryObserver.test.ts 中,新增的 test.each 覆盖六个尺寸键,断言 matchMedia 收到 (<css-name>: 0px)。该测试位于 describe.each(['modern', 'legacy']) 内,因此两种监听模式均被覆盖。所有目标需求均已在源码和测试中实现。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

兔子捧来零点点,
六种尺寸排成列。
查询留下 0px,
属性名字都看见。
耳朵轻摇,测试过关。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7f1c218e-6ea8-4693-9f72-6b430755fda4
Commits

Reviewing files that changed from the base of the PR and between 033c823 and af824d6.

Files selected for processing: 2

  • packages/taro-h5/__tests__/wxml/mediaQueryObserver.test.ts
  • packages/taro-h5/src/api/wxml/MediaQueryObserver.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.53%. Comparing base (033c823) to head (af824d6).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #19704   +/-   ##
=======================================
  Coverage   59.53%   59.53%           
=======================================
  Files         473      473           
  Lines       26652    26652           
  Branches     6710     6713    +3     
=======================================
  Hits        15868    15868           
+ Misses       8993     8948   -45     
- Partials     1791     1836   +45     
Flag Coverage Δ
taro-cli 59.69% <ø> (ø)
taro-runtime 66.45% <ø> (ø)
taro-web 75.56% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ackages/taro-h5/src/api/wxml/MediaQueryObserver.ts 97.05% <100.00%> (ø)

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(h5): preserve zero in media query descriptors

1 participant