Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 30, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

#4957

💡 需求背景和解决方案

使用 JSX 动态渲染 MenuItem 时,HeadMenu 组件会触发 Vue 警告:

[Vue warn]: Slot "default" invoked outside of the render function

原因initVMenu 在 setup 阶段调用 ctx.slots.default?.(),违反了 Vue 的 slot 访问规则。

修复:将 initVMenu(content) 移至 render 函数内部,复用已有的 content 变量。

// 触发警告的用法现已正常工作
const MenuComponent = defineComponent({
  setup() {
    return () => (
      <HeadMenu>
        {menuOptions.map(menu => (
          <MenuItem key={menu.key} value={menu.key}>
            {menu.label}
          </MenuItem>
        ))}
      </HeadMenu>
    )
  }
})

📝 更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-vue-next

  • fix(head-menu): 修复使用 JSX 动态渲染 MenuItem 时控制台警告 "Slot 'default' invoked outside of the render function"

@tdesign-vue-next/chat

@tdesign-vue-next/auto-import-resolver

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供
Original prompt

This section details on the original issue you should resolve

<issue_title>[HeadMenu] 使用jsx写法,menuItem使用代码渲染时,控制台警告 Slot "default" invoked outside of the render function</issue_title>
<issue_description>### tdesign-vue-next 版本

重现链接

No response

重现步骤

<template>
  <component :is="menuComponent"></component>
</template>

<script setup lang="tsx">
const menuOptions = [
  {
    label: '用户信息',
    key: 'info',
  },
  {
    label: '身份验证',
    key: 'security',
  },
]

const menuComponent = () => {
  return (
    <HeadMenu
    >
      {menuOptions.map(menu => (
        <MenuItem
          key={menu.key}
          value={menu.key}
        >
          {menu.label}
        </MenuItem>
      ))}
    </HeadMenu>
  )
}
</script>

期望结果

无警告

实际结果

Image

框架版本

1.15.1

浏览器版本

Microsoft Edge 版本 137.0.3296.68 (正式版本) (arm64)

系统版本

macos 15.3.1

Node版本

v24.2.0

补充说明

使用 Menu 不会,使用 HeadMenu 会</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix slot warning in HeadMenu component fix(head-menu): move initVMenu call inside render function to fix slot warning Nov 30, 2025
Copilot AI requested a review from liweijie0812 November 30, 2025 01:48
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 30, 2025

  • tdesign-vue-next-demo

    npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/auto-import-resolver@6221
    
    npm i https://pkg.pr.new/Tencent/tdesign-vue-next@6221
    
    npm i https://pkg.pr.new/Tencent/tdesign-vue-next/@tdesign-vue-next/chat@6221
    

commit: 7ca8fab

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented Nov 30, 2025

TDesign Component Site Preview Open

Component Preview
tdesign-vue-next 完成
@tdesign-vue-next/chat 完成

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.

[HeadMenu] 使用jsx写法,menuItem使用代码渲染时,控制台警告 Slot "default" invoked outside of the render function

3 participants