Skip to content

fix(h5): prefer scrollTop in pageScrollTo - #19622

Merged
Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:codex/h5-page-scroll-parameter-priority
Nov 10, 2026
Merged

Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:codex/h5-page-scroll-parameter-priority

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #19621

这个 PR 做了什么?

同时传入数值 scrollTop 和 selector 时,按现有提示优先使用 scrollTop。数值 0 也参与此判断。仅通过选择器定位时计算 offsetTop。

这个 PR 是什么类型?

  • 错误修复 (Bugfix)

这个 PR 涉及以下平台?

  • Web 端(H5)

验证

  • 在页面容器和 Window 两种滚动模式中覆盖 scrollTop: 0 与正数,共 4 个回归用例,原实现均失败,修复后均通过。
  • H5 全包 Jest 测试 36 个套件、367 个用例通过。改动文件 ESLint、Git 空白检查及 H5 生产构建通过。
  • 构建仍有已有的 previewImage / Swiper 类型告警及 Sass 弃用告警。验证使用 Jest/JSDOM。

Summary by CodeRabbit

  • 修复
    • 修正页面滚动定位行为:同时提供数字型滚动位置和选择器时,优先使用滚动位置,包括值为 0 的情况。
    • 同时提供数字型滚动位置和选择器时会发出警告;滚动位置为非数字且未提供选择器时,滚动目标位置为 0。

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

H5 pageScrollTo 现在在同时提供数字型 scrollTop 和选择器时优先使用 scrollTop,包括值为 0 的情况。新增测试覆盖目标值 0 和 200,并检查警告次数。

Changes

H5 滚动参数优先级

Layer / File(s) Summary
选择器优先级与回归测试
packages/taro-h5/src/api/ui/scroll/index.ts, packages/taro-h5/__tests__/ui/scroll.test.ts
数字型 scrollTop 存在时,实际选择器置为空;当请求选择器非空时发出警告。无选择器时,数字型 scrollTop(包括 0)作为滚动目标。测试覆盖目标值 0 和 200,并检查操作成功及警告次数。

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

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • NervJS/taro#19584:修复 H5 pageScrollTo 动画越过目标位置;该 PR 说明参数优先级留待后续处理。

Suggested reviewers: zakarycode

Merge Risk: Minimal · up to 58423

Numeric scrollTop takes precedence over the selector in both H5 scrolling modes. No material merge risk remains.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确概括主要变更:在 H5 的 pageScrollTo 中优先使用 scrollTop。
Linked Issues check Passed [#19621] packages/taro-h5/src/api/ui/scroll/index.ts 用 typeof scrollTop === 'number' 判断显式滚动位置,因此值为 0 时也优先使用 scrollTop,并忽略 selector。代码仅在选择器定位时计算 offsetTop。`packages/taro-h5/tests/ui/scrol…
Out of Scope Changes check Passed 检查到的实现和回归测试均针对 [#19621] 的 H5 pageScrollTo 优先级问题。未发现与该目标无关的改动。
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Linked Issues check

Explanation

[#19621] packages/taro-h5/src/api/ui/scroll/index.ts 用 typeof scrollTop === 'number' 判断显式滚动位置,因此值为 0 时也优先使用 scrollTop,并忽略 selector。代码仅在选择器定位时计算 offsetTop。packages/taro-h5/__tests__/ui/scroll.test.ts 在页面容器和 Window 模式下覆盖 0 和 200,并检查结果位置及警告。

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

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

我是小兔,跳到滚动页边,
scrollTop 为零,也看得分明。
选择器遇上它,便暂退一旁,
警告轻轻响起,测试记下回响。
两个目标都验证,胡萝卜也香。

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: c05e351a-4f10-4fef-a29b-b4d06b653a57
Commits

Reviewing files that changed from the base of the PR and between 6ac7740 and 58423af.

Files selected for processing: 1

  • packages/taro-h5/src/api/ui/scroll/index.ts

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

@coderabbitai
coderabbitai Bot requested a review from ZakaryCode November 7, 2026 16:03
@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.53%. Comparing base (3357085) to head (58423af).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #19622    +/-   ##
========================================
  Coverage   58.52%   58.53%            
========================================
  Files         470      470            
  Lines       26065    26067     +2     
  Branches     6541     6497    -44     
========================================
+ Hits        15255    15258     +3     
+ Misses       9014     8889   -125     
- Partials     1796     1920   +124     
Flag Coverage Δ
taro-cli 59.69% <ø> (ø)
taro-runtime 66.45% <ø> (ø)
taro-web 71.35% <100.00%> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
packages/taro-h5/src/api/ui/scroll/index.ts 93.15% <100.00%> (+1.60%) ⬆️

... and 36 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.

@Single-Dancer Single-Dancer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Single-Dancer Single-Dancer added this to the 4.3.3 milestone Nov 10, 2026
@Single-Dancer
Single-Dancer force-pushed the codex/h5-page-scroll-parameter-priority branch from 6ac7740 to 58423af Compare November 10, 2026 12:08
@Single-Dancer
Single-Dancer merged commit 978e477 into NervJS:main Nov 10, 2026
25 checks passed
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.

[Bug]: H5 pageScrollTo 同时传入 scrollTop 和 selector 时优先级与提示不一致

2 participants