Skip to content

Conversation

Single-Dancer
Copy link
Collaborator

@Single-Dancer Single-Dancer commented Apr 9, 2025

特性

小程序

错误修复

Summary by CodeRabbit

  • 新特性

    • 升级了 WebAssembly 构建目标,提高了跨平台兼容性。
    • 小程序示例中改进了页面导航和混合路由体验。
    • UI 组件库新增对引用转发的支持,并扩展了部分组件的导出。
    • HTML 解析逻辑优化,改善了图片样式和特殊元素映射处理。
  • 其他改进

    • 持续集成环境升级(Node.js 和 macOS 版本调高),整体构建效率提升。
    • 全线插件和包版本统一升级至 3.6.36,增强了系统稳定性与性能。
    • 文档及 API 说明进一步完善和优化。

Copy link

coderabbitai bot commented Apr 9, 2025

Walkthrough

此次提交涉及多个模块的改动。主要内容包括调整构建目标(将 wasm32-wasi 修改为 wasm32-wasip1)、升级 GitHub Actions 工作流中 Node.js 与 macOS 环境版本、广泛更新各个 package 的版本号(从 3.6.34 到 3.6.36)、对 SWC 插件、测试、组件、API 与运行时解析逻辑等模块新增或调整相关方法和属性,以及在 Taro 相关平台与插件中引入拓展配置支持和改进文档说明。

Changes

文件组 变更摘要
.cargo 与 GitHub 工作流 修改构建别名及目标(wasm32-wasip1);更新 build-rust-binding.yml、build-rust-wasm.yml、nodejs.yml 与 publish.yml 的配置(包括 Node.js 版本、macOS 版本、分支触发等)
Package 版本更新 各模块(crates、npm、packages、taro 等)的 package.json 中版本均从 3.6.34 更新到 3.6.36
SWC 插件及测试 修改 swc_plugin_compile_mode 相关文件(如 tests/mod.rs、transform.rs、utils/mod.rs),增加 skyline 模块与测试用例,更新环境变量处理及 JSX 元素转换逻辑
组件与 API 变更 调整原生导航方法与 API(如 nativeApi),新增 ref 转发支持(button、icon、image、input、pull-down-refresh、scroll-view、swiper、text、view 等组件),并增加 List/ListItem 类型声明
运行时与构建工具更新 改进 runtime 中 HTML 解析(新增 attributesArray2Props、img 标签处理及特殊元素映射),以及 H5WebpackRunner、Taro CLI 等工具中引入 modifyAppConfig 配置
Harmony 相关平台与插件 更新 Harmony 平台构建目标,新增 NativeApi 的 onStorageStatusChange 与 offStorageStatusChange 方法,并引入 syncAndNotRelease 装饰器;调整 exitMiniProgram 配置
其他模块及文档更新 包括 babel-preset-taro 插件改进、新增组件导出、Taro CLI postinstall 脚本、蓝牙接口及 open-api 配置文档修改等

Sequence Diagram(s)

sequenceDiagram
    participant Parent as 父组件
    participant Wrapper as createForwardRefComponent
    participant Component as 原始组件
    participant DOM as DOM 元素

    Parent->>Wrapper: 调用并传递 ref
    Wrapper->>Component: 注入 props 与 forwardedRef
    Component->>DOM: 渲染并将 forwardedRef 绑定至 DOM
    DOM-->>Component: 返回 DOM 节点引用
    Component-->>Wrapper: 返回组件实例
    Wrapper-->>Parent: 完成 ref 转发
Loading

Possibly related PRs

Suggested reviewers

  • tutuxxx

Poem

我是一只小兔子,跳跃在代码林间,
构建目标换新颜,版本更新真鲜甜;
工作流流畅如溪水,组件焕发自信边;
每一行代码都在歌唱,开发之路亮晶晶 🌟
愿我们的改动精彩纷呈,前进的步伐永不停!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/mini-program-example/src/pages/index/index.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react-hooks".

(The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "/examples/mini-program-example".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react-hooks@latest --save-dev

The plugin "eslint-plugin-react-hooks" was referenced from the config file in "examples/mini-program-example/.eslintrc » eslint-config-taro/react » /packages/eslint-config-taro/rules/jsx.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/mini-program-example/src/util/nativeApi.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-react-hooks".

(The package "eslint-plugin-react-hooks" was not found when loaded as a Node module from the directory "/examples/mini-program-example".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-react-hooks@latest --save-dev

The plugin "eslint-plugin-react-hooks" was referenced from the config file in "examples/mini-program-example/.eslintrc » eslint-config-taro/react » /packages/eslint-config-taro/rules/jsx.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@Single-Dancer Single-Dancer changed the base branch from main to 3.x April 9, 2025 10:11
@coderabbitai coderabbitai bot requested a review from tutuxxx April 9, 2025 10:13
@Single-Dancer Single-Dancer changed the title Chore/release 3.6.36 chore(release): publish 3.6.36 Apr 9, 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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 4

🧹 Nitpick comments (24)
examples/mini-program-example/src/util/nativeApi.ts (1)

2-2: 建议使用可选链提高代码健壮性

当前代码在访问window.MethodChannel时没有使用可选链,可能会在某些环境下导致错误。

建议修改为使用可选链,提高代码健壮性:

-const sync = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)
+const sync = window.MethodChannel?.jsBridgeMode({ isAsync: false, autoRelease: true }) || (target => target)
🧰 Tools
🪛 Biome (1.9.4)

[error] 2-2: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/taro-service/src/utils/index.ts (1)

120-134: 新增全局配置过滤函数

添加了 filterGlobalConfig 函数,用于根据命令名称过滤全局配置中的插件,只保留与特定命令相关的插件。

函数实现逻辑清晰,但有几点可以优化:

  1. 建议使用可选链操作符,提高代码健壮性
  2. 考虑创建配置对象的副本而不是直接修改入参对象
  3. 可以处理数组形式的插件项
export function filterGlobalConfig (globalConfig: IProjectConfig, command: string) {
  if (!command) {
    return globalConfig
  }
-  const config = globalConfig
+  const config = { ...globalConfig }

  const RelatedPluginTag = `@jdtaro/plugin-${command}-`
-  if (config.plugins?.length) {
-    config.plugins = config.plugins.filter(pluginName => {
-      return pluginName.includes(RelatedPluginTag)
-    })
+  if (config.plugins?.length) {
+    config.plugins = config.plugins.filter(pluginItem => {
+      const pluginName = typeof pluginItem === 'string' ? pluginItem : Array.isArray(pluginItem) ? pluginItem[0] : '';
+      return pluginName.includes(RelatedPluginTag)
+    })
  }

  return config
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 127-128: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/taro-runtime/src/dom-external/inner-html/tags.ts (1)

24-31: 实现了特殊元素映射

创建了一个新的Map specialElements,为'a'标签定义了特殊处理逻辑。根据属性决定渲染为'view'或'navigator'的实现逻辑合理,但条件表达式缺少清晰的括号分组。

建议优化条件表达式的可读性:

-      return !props.href || isString(props.href) && (/^javascript/.test(props.href)) ? 'view' : 'navigator'
+      return !props.href || (isString(props.href) && (/^javascript/.test(props.href))) ? 'view' : 'navigator'
packages/taro-runtime/src/dom-external/inner-html/parser.ts (1)

154-171: 添加了img标签的特殊处理逻辑

为img标签添加了特殊处理逻辑,将width、height和style属性合并到单个style属性中。这种实现可能在某些边缘情况下存在潜在问题。

建议考虑以下改进:

  1. 处理style属性中已经存在width或height的情况,避免冲突
  2. 验证width和height值的有效性,确保它们是有效的CSS值
  3. 考虑添加错误处理,防止潜在的异常

可以参考以下优化方案:

if (child.tagName === 'img') {
  let styleText = ''
  const toBeRemovedIndexs: number[] = []
  const styleValues: Record<string, string> = {}
  
  for (let i = 0; i < child.attributes.length; i++) {
    const attr = child.attributes[i]
    const [key, value] = splitEqual(attr)
    if (key === 'width' || key === 'height') {
      styleValues[key] = value
      toBeRemovedIndexs.push(i)
    } else if (key === 'style') {
      styleText = value
      toBeRemovedIndexs.push(i)
    }
  }
  
  // 解析现有的style
  const existingStyles = styleText.split(';').filter(Boolean).reduce((acc, style) => {
    const [k, v] = style.split(':').map(s => s.trim())
    if (k && v) acc[k] = v
    return acc
  }, {})
  
  // 合并style
  Object.assign(existingStyles, styleValues)
  
  // 生成新的style字符串
  const newStyleText = Object.entries(existingStyles)
    .map(([k, v]) => `${k}:${v}`)
    .join(';')
  
  child.attributes = child.attributes.filter((_, index) => !toBeRemovedIndexs.includes(index))
  if (newStyleText) {
    child.attributes.push(`style=${newStyleText.replace(/['"]/g, '')}`)
  }
}
packages/taro-platform-harmony-hybrid/src/api/apis/harmony-native/ApiDecorator.ts (1)

5-5: 新增的同步不释放装饰器完善了API调用模式

这个新增的syncAndNotRelease装饰器提供了同步调用且不自动释放资源的能力,有效地完善了现有的API调用模式矩阵。这对于需要持续监听或长期保持连接的API场景非常有用。

建议考虑使用可选链操作符来提高代码健壮性:

-export const syncAndNotRelease = window.MethodChannel && window.MethodChannel.jsBridgeMode({ isAsync: false, autoRelease: false }) || (target => target)
+export const syncAndNotRelease = window.MethodChannel?.jsBridgeMode({ isAsync: false, autoRelease: false }) ?? (target => target)
🧰 Tools
🪛 Biome (1.9.4)

[error] 5-5: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.ts (1)

631-635: 新增存储状态变化监听相关方法

添加了两个用于监听存储状态变化的方法:

  • onStorageStatusChange: 用于注册存储状态变化的回调
  • offStorageStatusChange: 用于注销之前注册的存储状态变化回调

这两个方法都使用 @(syncAndNotRelease) 装饰器,表明它们是同步执行且不会自动释放资源的。

建议为这两个方法添加简要的方法文档注释,说明其用途和参数含义,以便其他开发者理解如何使用它们。例如:

+  /**
+   * 注册存储状态变化的监听器
+   * @param _options 监听器配置选项
+   */
  @(syncAndNotRelease)
  onStorageStatusChange (_options: any): void {}

+  /**
+   * 注销存储状态变化的监听器
+   * @param _options 要注销的监听器配置选项
+   */
  @(syncAndNotRelease)
  offStorageStatusChange (_options: any): void {}
packages/taro-components/src/components/script/readme.md (1)

1-10: 文档:taro-script-core 组件说明

这是一个由 StencilJS 自动生成的文档文件,为 taro-script-core 组件提供基本介绍。

虽然目前内容比较简单,建议在后续更新中添加更多关于此组件的使用方法、示例和注意事项等详细信息,以便开发者更好地理解如何使用该组件。

packages/taro-components/types/RichText.d.ts (1)

21-21: 类型修正:将 selectable 属性从 string 改为 boolean

selectable 属性的类型从 string 修改为 boolean,使其与 JSDoc 注释中描述的默认值(falsetrue)保持一致。这是一个必要的类型修正,可以提高 API 的类型安全性。

注意,这是一个破坏性更改,可能会影响依赖于旧类型的现有代码。建议在更新日志中说明这一变更。

packages/taro-components/src/components/script/script.tsx (1)

1-18: 新增的 Script 组件仅为占位符

新添加的 Script 组件当前仅调用 notSupport 函数,表明此功能尚未支持。这是一个有效的占位实现,但缺少详细的文档说明。

建议添加 JSDoc 注释,解释此组件的预期用途以及什么时候会实现完整功能。例如:

/**
 * Script 组件 - 用于在小程序环境中模拟 HTML script 标签功能
 * @note 当前版本不支持此组件,将在后续版本中实现
 */
packages/taro-webpack5-runner/src/utils/app.ts (1)

64-67: 实现了应用配置的动态修改

这段代码实现了通过 modifyAppConfig 函数动态修改应用配置的功能。实现逻辑清晰,包含了类型检查以确保安全执行。这种模式在 Taro 其他部分也有使用,保持了一致性。

建议添加注释说明 modifyAppConfig 函数的预期行为(是否应该返回新配置对象或直接修改传入的对象)。

+      // modifyAppConfig 用于修改应用配置,函数直接修改传入的 appConfig 对象
       const { modifyAppConfig } = this.options
       if (typeof modifyAppConfig === 'function') {
         modifyAppConfig(appConfig)
       }
.github/workflows/nodejs.yml (1)

154-154: 更新 Rust WebAssembly 目标

与 build-rust-wasm.yml 文件中的更改保持一致,将 Rust 工具链目标从 wasm32-wasi 更新为 wasm32-wasip1

建议在代码库中添加文档说明为什么要从 wasm32-wasi 切换到 wasm32-wasip1,以便团队成员了解这一变更的原因和影响。

packages/taro-components-react/src/components/pull-down-refresh/index.tsx (1)

50-50: 检查 forwardedRef 类型定义

forwardedRef 的类型被定义为 React.MutableRefObject<HTMLBaseElement>,但在代码中实际引用的是 pull-down-refresh 自定义元素。建议将类型改为 React.MutableRefObject<HTMLElement> 以更准确地反映实际使用情况,因为 HTMLBaseElement 通常用于 HTML 的 <base> 元素。

-  forwardedRef?: React.MutableRefObject<HTMLBaseElement>
+  forwardedRef?: React.MutableRefObject<HTMLElement>
packages/shared/src/template.ts (1)

213-217: 建议为 list 字段提供更灵活的配置方式
当前将 'i.cn' 直接写死在 list 字段里,可能在后续功能扩展或多场景兼容时受到限制。可以考虑通过方法或属性配置使其更加灵活,便于后期维护。

packages/taro-components-react/src/index.ts (1)

67-70: 保证命名与团队约定保持一致
Snapshot、Span、StickyHeader、StickySection 与现有组件风格相比略显不统一(大部分组件名较短或为名词),如团队已有命名约定可适当统一。

packages/babel-preset-taro/transform-taro-components.js (1)

210-210: 导出默认最后
整段结尾空行或多余字符可做适度清理,保持文件简洁。

packages/taro-jd/src/components.ts (1)

31-44: Editor 组件属性设置合理,但请确保小程序端兼容。
若后续需要支持更多编辑功能,可考虑增加更细粒度的组件接口或事件。

packages/taro-components-react/src/components/swiper/index.tsx (1)

8-8: 导入 debounce 尚未在该文件内使用。
如果不需要,可移除以减少包体大小并保持代码整洁。

crates/swc_plugin_compile_mode/src/transform.rs (5)

200-203: visit_mut_jsx_element 中调用 transform_taro_component
建议覆盖更多测试用例,验证处理逻辑对不同类型的 JSX 节点均有效。


239-275: collect_import_info 方法中解析所有导入声明以建立映射。
该函数功能集中,逻辑清晰。但建议在后续 PR 中为不同的导入类型加单元测试,预防极端用法。


281-285: 检测到对属性 slot:item 的特殊逻辑处理。
此段逻辑能否与 transform_taro_component 整体流程统一?若后续需求增加,建议抽离成工具函数避免横向重复。


506-510: wx:for 表达式的处理逻辑嵌入此处。
需注意与其他小程序端类似指令冲突;完善单测覆盖更安全。


828-831: PreVisitor::new 在编译模式下被调用,可见插件流程已改造兼容。
若后续需要动态切换其他编译模式,可考虑抽象配置管理。

crates/swc_plugin_compile_mode/src/utils/mod.rs (2)

443-475: 属性提取函数实现合理,但可考虑优化克隆操作

extract_list_props 函数通过目标属性集合和别名映射来过滤并修改 JSX 元素的属性。实现逻辑清晰,但注意第 450 行中的 clone() 操作可能在属性数量较多时影响性能。

考虑使用迭代器直接筛选目标属性并应用别名转换,无需先克隆整个属性数组:

-  let mut attrs = el.opening.attrs.clone();
-  attrs.retain(|attr| {
-    if let JSXAttrOrSpread::JSXAttr(jsx_attr) = attr {
-      if let JSXAttrName::Ident(Ident { sym: name, .. }) = &jsx_attr.name {
-        let attr_name = name.to_string();
-        return target_attrs.contains(attr_name.as_str());
-      }
-    }
-    false
-  });
+  let mut attrs: Vec<JSXAttrOrSpread> = el.opening.attrs.iter()
+    .filter(|attr| {
+      if let JSXAttrOrSpread::JSXAttr(jsx_attr) = attr {
+        if let JSXAttrName::Ident(Ident { sym: name, .. }) = &jsx_attr.name {
+          let attr_name = name.to_string();
+          return target_attrs.contains(attr_name.as_str());
+        }
+      }
+      false
+    })
+    .cloned()
+    .collect();

552-587: 组件转换入口函数功能完整,但可考虑结构优化

transform_taro_component 函数能够正确识别并转换从 @tarojs/components 导入的 List 和 ListItem 组件。此功能与 PR 目标完全一致。

不过,该函数存在多层嵌套条件判断,可能影响代码可读性。

考虑使用早期返回模式简化嵌套结构:

  pub fn transform_taro_component(
    el: &mut JSXElement,
    import_specifiers: &HashMap<String, String>,
    import_aliases: &HashMap<String, String>,
  ) {
    match &el.clone().opening.name {
      JSXElementName::Ident(ident) => {
-        if let Some(import) = import_aliases.get("List") {
-          if ident.sym.as_str() == import {
-            // 检查导出模块来源
-            if let Some(src) = import_specifiers.get(import) {
-              // 如果是 @tarojs/components 导出的 List 组件,需要特殊处理
-              if src == "@tarojs/components" {
-                transform_list_component(el);
-              }
-            }
-          }
-        }
+        // 处理 List 组件
+        let component_name = ident.sym.as_str();
+        if let Some(import) = import_aliases.get("List") {
+          if component_name == import {
+            if let Some(src) = import_specifiers.get(import) {
+              if src == "@tarojs/components" {
+                transform_list_component(el);
+                return;
+              }
+            }
+          }
+        }

-        if let Some(import) = import_aliases.get("ListItem") {
-          if ident.sym.as_str() == import {
-            // 检查导出模块来源
-            if let Some(src) = import_specifiers.get(import) {
-              // 如果是 @tarojs/components 导出的 ListItem 组件,需要特殊处理
-              if src == "@tarojs/components" {
-                transform_list_item_component(el);
-              }
-            }
-          }
-        }
+        // 处理 ListItem 组件
+        if let Some(import) = import_aliases.get("ListItem") {
+          if component_name == import {
+            if let Some(src) = import_specifiers.get(import) {
+              if src == "@tarojs/components" {
+                transform_list_item_component(el);
+                return;
+              }
+            }
+          }
+        }
      }
      _ => (),
    };
  }
🛑 Comments failed to post (4)
packages/taro-platform-harmony-hybrid/src/api/apis/media/image/chooseImage.ts (1)

60-60: 💡 Verification agent

🧩 Analysis chain

方法名称更新:chooseMediaAssets → chooseMediumAssets

方法名从chooseMediaAssets更改为chooseMediumAssets,确保与其他文件的命名保持一致性。这种变更有助于统一整个API的命名规范。


🏁 Script executed:

#!/bin/bash
# 检查是否所有相关文件都已更新方法名
echo "检查原方法名是否仍在代码库中使用..."
rg "chooseMediaAssets" --type ts

Length of output: 485


方法名称需确保全局一致

在文件 packages/taro-platform-harmony-hybrid/src/api/apis/media/image/chooseImage.ts 中已更新为 chooseMediumAssets,以实现与其他文件一致的命名规范。但代码库中仍存在以下处使用旧方法名 chooseMediaAssets,请一并更新以保持统一:

  • packages/taro-platform-harmony-hybrid/src/api/apis/media/video/chooseMedia/chooseMedia.ts 中对 native.chooseMediaAssets({ 的调用
  • packages/taro-platform-harmony-hybrid/src/api/apis/NativeApi.tschooseMediaAssets 方法的定义

请在整个代码库中检查并统一修改所有相关调用。

packages/taro-cli/postinstall.js (2)

13-14: 🛠️ Refactor suggestion

错误处理不完善

catch 块为空,没有处理网络请求失败的情况。应该添加适当的错误日志和处理逻辑。

-  .catch(() => {
-  })
+  .catch((error) => {
+    console.log(`网络请求失败,性能插件未安装: ${error.message}`)
+  })
+}

Committable suggestion skipped: line range outside the PR's diff.


4-12: ⚠️ Potential issue

后安装脚本存在安全隐患

此段代码在安装后自动执行网络请求并安装插件,存在以下问题:

  1. 向特定域名发送请求可能涉及隐私问题
  2. 自动添加插件未经用户确认
  3. 使用了固定的内部注册表地址 (http://registry.m.jd.com)
  4. 没有提供禁用此行为的选项

建议提供配置项允许用户选择是否启用此功能,并使用 HTTPS 进行安全连接。

-axios.get('https://taro.jd.com/', { timeout: 5000 })
-  .then(() => {
-    exec('./bin/taro global-config add-plugin  @jdtaro/plugin-build-report-performance@latest --registry http://registry.m.jd.com', (error, _stdout, _stderr) => {
+// 检查环境变量是否允许安装性能插件
+if (process.env.TARO_INSTALL_PERFORMANCE_PLUGIN !== 'false') {
+  axios.get('https://taro.jd.com/', { 
+    timeout: 5000,
+    httpsAgent: new https.Agent({ rejectUnauthorized: true })
+  })
+    .then(() => {
+      // 使用用户配置的注册表或默认值
+      const registry = process.env.NPM_REGISTRY || 'https://registry.npmjs.org'
+      exec(`./bin/taro global-config add-plugin @jdtaro/plugin-build-report-performance@latest --registry ${registry}`, (error, _stdout, _stderr) => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

// 检查环境变量是否允许安装性能插件
if (process.env.TARO_INSTALL_PERFORMANCE_PLUGIN !== 'false') {
  axios.get('https://taro.jd.com/', { 
    timeout: 5000,
    httpsAgent: new https.Agent({ rejectUnauthorized: true })
  })
    .then(() => {
      // 使用用户配置的注册表或默认值
      const registry = process.env.NPM_REGISTRY || 'https://registry.npmjs.org'
      exec(`./bin/taro global-config add-plugin @jdtaro/plugin-build-report-performance@latest --registry ${registry}`, (error, _stdout, _stderr) => {
        if (error) {
          console.error(`install performance plugin error: ${error}`)
        }
      })
      console.log('cli postinstall success')
    })
}
packages/taro-components-react/src/components/icon/index.tsx (1)

14-14: 💡 Verification agent

🧩 Analysis chain

注意 forwardedRef 类型定义

forwardedRef 的类型被定义为 React.MutableRefObject<HTMLLIElement>,但该组件渲染的是 <i> 元素而非 <li> 元素。建议将类型更改为 React.MutableRefObject<HTMLElement> 或者更具体的 React.MutableRefObject<HTMLIElement>(如果支持)。


🏁 Script executed:

#!/bin/bash
# 检查其他组件是否有类似的类型定义不匹配问题
grep -r "MutableRefObject<HTML.*Element>" --include="*.tsx" packages/taro-components-react/src/components

Length of output: 1312


请修正 Icon 组件中 forwardedRef 的类型定义

目前,Icon 组件渲染的是 <i> 元素,但其 forwardedRef 类型被定义为 React.MutableRefObject<HTMLLIElement>。为保持与实际渲染元素一致,建议将类型修改为 React.MutableRefObject<HTMLIElement>(如果支持)或者通用的 React.MutableRefObject<HTMLElement>

  • 文件:packages/taro-components-react/src/components/icon/index.tsx(第 14 行)

This was referenced Apr 12, 2025
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.

1 participant