-
Notifications
You must be signed in to change notification settings - Fork 4.9k
chore(release): publish 3.6.36 #17505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough此次提交涉及多个模块的改动。主要内容包括调整构建目标(将 wasm32-wasi 修改为 wasm32-wasip1)、升级 GitHub Actions 工作流中 Node.js 与 macOS 环境版本、广泛更新各个 package 的版本号(从 3.6.34 到 3.6.36)、对 SWC 插件、测试、组件、API 与运行时解析逻辑等模块新增或调整相关方法和属性,以及在 Taro 相关平台与插件中引入拓展配置支持和改进文档说明。 Changes
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 转发
Possibly related PRs
Suggested reviewers
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
examples/mini-program-example/src/pages/index/index.tsxOops! 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:
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.tsOops! 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:
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
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
函数,用于根据命令名称过滤全局配置中的插件,只保留与特定命令相关的插件。函数实现逻辑清晰,但有几点可以优化:
- 建议使用可选链操作符,提高代码健壮性
- 考虑创建配置对象的副本而不是直接修改入参对象
- 可以处理数组形式的插件项
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属性中。这种实现可能在某些边缘情况下存在潜在问题。
建议考虑以下改进:
- 处理style属性中已经存在width或height的情况,避免冲突
- 验证width和height值的有效性,确保它们是有效的CSS值
- 考虑添加错误处理,防止潜在的异常
可以参考以下优化方案:
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 注释中描述的默认值(false
或true
)保持一致。这是一个必要的类型修正,可以提高 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.ts
中chooseMediaAssets
方法的定义请在整个代码库中检查并统一修改所有相关调用。
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后安装脚本存在安全隐患
此段代码在安装后自动执行网络请求并安装插件,存在以下问题:
- 向特定域名发送请求可能涉及隐私问题
- 自动添加插件未经用户确认
- 使用了固定的内部注册表地址 (http://registry.m.jd.com)
- 没有提供禁用此行为的选项
建议提供配置项允许用户选择是否启用此功能,并使用 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 行)
特性
小程序
错误修复
Summary by CodeRabbit
新特性
其他改进