Skip to content

Comments

fix(button): taro button cannot be compiled into an h5 tag#2998

Closed
oasis-cloud wants to merge 1 commit intojdf2e:feat_v3.xfrom
oasis-cloud:fix_button_h5
Closed

fix(button): taro button cannot be compiled into an h5 tag#2998
oasis-cloud wants to merge 1 commit intojdf2e:feat_v3.xfrom
oasis-cloud:fix_button_h5

Conversation

@oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Feb 18, 2025

Summary by CodeRabbit

  • 重构
    • 按钮组件现已使用标准 HTML 按钮实现,确保了跨设备一致性和更稳定的交互体验。
    • 更新了按钮属性命名,使表单交互更加直观,明确了按钮类型定义,同时保持了原有的点击和样式行为。

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2025

Walkthrough

该 PR 修改了 button 组件的实现,将原先依赖 TaroButton 的方式替换为使用原生 HTML 的 <button> 元素。文件中移除了对 TaroButton 的导入,同时更改了属性传递方式,将 formType 改为 form-type,并显式设置 type 属性为 nativeType。此外,还移除了此前用于抑制 TypeScript 错误的注释,整体结构保持不变。

Changes

文件 变更摘要
src/packages/button/button.taro.tsx 移除 TaroButton 导入,使用原生 <button> 替代;修改属性名称 formTypeform-type,显式设置 type 属性为 nativeType;移除 TS 错误抑制注释

Possibly related PRs

Poem

我是一只跳跃的小兔子,
看到代码焕然一新真开心。
Taro按钮变作 HTML之美,
属性换名轻舞飞扬在晨曦,
代码世界如花丛般欢欣,
愿未来每次提交都满载惊喜!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Feb 18, 2025
@codecov
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.79%. Comparing base (7ab99e4) to head (6a98409).
Report is 7 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2998   +/-   ##
==========================================
  Coverage      85.79%   85.79%           
==========================================
  Files            281      281           
  Lines          18527    18527           
  Branches        2810     2810           
==========================================
  Hits           15896    15896           
  Misses          2626     2626           
  Partials           5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oasis-cloud oasis-cloud changed the title fix: taro button cannot be compiled into an h5 tag fix(button): taro button cannot be compiled into an h5 tag Feb 18, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/packages/button/button.taro.tsx (1)

149-174: 建议优化按钮实现的类型安全性

当前实现存在以下几点可以改进的地方:

  1. 使用 form-type 属性需要禁用 ESLint 规则,这不是最佳实践
  2. 类型定义可以更严格

建议如下修改:

-      <button
+      <button
+        type={nativeType}
         {...rest}
         ref={ref}
-        /* eslint-disable-next-line react/no-unknown-property */
-        form-type={nativeType}
-        type={nativeType}
+        data-form-type={nativeType}
         className={buttonClassNames}
         style={{ ...getStyle, ...style }}
         onClick={(e) => handleClick(e as any)}
       >

这样可以:

  1. 避免使用 ESLint 禁用注释
  2. 使用 data- 属性来保持与原有功能的兼容性
  3. 确保 type 属性位于其他属性之前,防止被 rest 覆盖
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ab99e4 and 6a98409.

📒 Files selected for processing (1)
  • src/packages/button/button.taro.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
src/packages/button/button.taro.tsx (2)

2-2: 导入更改看起来合理!

移除 TaroButton 的导入并保留类型定义是正确的做法,这与使用原生 HTML button 元素的目标相符。

Also applies to: 4-4


143-145:

Details

❓ Verification inconclusive

验证 WEB 环境下的类型处理

当前在 WEB 环境下的类型转换逻辑可能需要更新以匹配新的实现方式。


🏁 Script executed:

#!/bin/bash
# 检查是否存在其他使用 formType 的地方
rg "formType" --type ts --type tsx

Length of output: 62


请核查 WEB 环境下的类型转换逻辑一致性

目前代码在 WEB 环境中将 rest.formType 赋值给 rest.type。由于我们在自动搜索 formType 的过程中遇到了文件类型识别的问题(例如 tsx 未被正确识别),请你手动验证整个代码库中是否存在其他相关用法,确保所有组件中的类型处理逻辑均已与最新实现保持一致。如果有其他地方也依赖于 formType 的转换,请同步相应更新。

  • 请检查 src/packages/button/button.taro.tsx 文件中(第 143-145 行)的处理是否符合预期。
  • 手动搜索或验证其他 .ts.tsx 文件中对 formType 的使用情况,以避免遗漏修改。

Copy link
Collaborator

@xiaoyatong xiaoyatong left a comment

Choose a reason for hiding this comment

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

这个是不是可以区分一下 web 和 其他端。

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

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants