Repository navigation
fix(weapp): compile custom tabbar with vite runner - #19465
Conversation
Walkthrough此变更支持自定义 TabBar 页面。编译器在配置和脚本存在时收集该页面。运行时使用 Changes自定义 TabBar 页面支持
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant TaroCompilerContext
participant compilePage
participant pages
participant page_ts
TaroCompilerContext->>TaroCompilerContext: 检查自定义 TabBar 配置和脚本
TaroCompilerContext->>compilePage: 编译 custom-tab-bar/index
compilePage->>pages: 加入编译后的页面
page_ts->>page_ts: 检查 page.name
page_ts->>page_ts: 使用 Component 和 createComponentConfig
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/taro-vite-runner/src/utils/compiler/mini.ts (1)
96-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win将 'custom-tab-bar/index' 提取为共享常量。 两个文件各自硬编码了相同的字符串
'custom-tab-bar/index',用于标识自定义 tabBar 页面。这是同一个根本原因:缺少一个共享常量。将其提取为常量并在两处引用,能避免未来修改时出现不一致。
packages/taro-vite-runner/src/utils/compiler/mini.ts#L96: 将字面量'custom-tab-bar/index'替换为从共享模块导入的常量。packages/taro-vite-runner/src/mini/page.ts#L62: 将字面量'custom-tab-bar/index'替换为同一个共享常量,用于page.name === CUSTOM_TAB_BAR_NAME判断。♻️ 提取常量示例
+export const CUSTOM_TAB_BAR_NAME = 'custom-tab-bar/index'collectCustomTabBar () { if (!this.app.config.tabBar?.custom) return - const customTabBarName = 'custom-tab-bar/index' + const customTabBarName = CUSTOM_TAB_BAR_NAME const scriptPath = resolveMainFilePath(path.join(this.sourceDir, customTabBarName), this.frameworkExts)- const isCustomTabBar = page.name === 'custom-tab-bar/index' + const isCustomTabBar = page.name === CUSTOM_TAB_BAR_NAME🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/taro-vite-runner/src/utils/compiler/mini.ts` at line 96, Extract the shared custom tabBar identifier into a common module, then replace the hardcoded string in packages/taro-vite-runner/src/utils/compiler/mini.ts at lines 96-96 with the shared constant and likewise replace the literal in packages/taro-vite-runner/src/mini/page.ts at lines 62-62 used by the page.name comparison. Import the same constant in both locations so future changes remain consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/taro-vite-runner/src/utils/compiler/mini.ts`:
- Line 96: Extract the shared custom tabBar identifier into a common module,
then replace the hardcoded string in
packages/taro-vite-runner/src/utils/compiler/mini.ts at lines 96-96 with the
shared constant and likewise replace the literal in
packages/taro-vite-runner/src/mini/page.ts at lines 62-62 used by the page.name
comparison. Import the same constant in both locations so future changes remain
consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fdf7a769-2fb6-4aeb-8fa6-681f7032894d
📒 Files selected for processing (2)
packages/taro-vite-runner/src/mini/page.tspackages/taro-vite-runner/src/utils/compiler/mini.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19465 +/- ##
=======================================
Coverage 55.68% 55.68%
=======================================
Files 451 451
Lines 23764 23764
Branches 5889 5885 -4
=======================================
Hits 13233 13233
- Misses 8681 8777 +96
+ Partials 1850 1754 -96
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
方向正确。Vite 下补充 custom-tab-bar 收集,并用 Component(createComponentConfig(...)) 注册,符合微信自定义 tabBar 的预期,可以合。 |
… mini program
这个 PR 做了什么? (简要描述所做更改)
修复微信小程序使用 Vite 编译器时,自定义 tabbar 未被收集和编译的问题。
当项目配置
tabBar.custom: true,并存在src/custom-tab-bar/index时,Vite runner 现在会自动收集该组件并生成对应的小程序产物。同时,custom tabbar 使用
Component(createComponentConfig(...))进行注册,普通页面仍使用
Page(createPageConfig(...))注册。修复后,React 函数组件形式的 custom tabbar 可以正常生成并渲染。
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
新功能
问题修复