Skip to content

关于自定义组件的问题 #1

Description

@HaveF

首先抱歉,我算是 vibe coding..., 源码确实是不懂。

但让 AI 读了好几遍,它的意思是,自定义组件有点问题。

组件原生支持 public/ 前缀 -- 这部分没有问题

    // components/x/index.tsx — 核心动态加载器
    if (name.startsWith('public/')) {
        // SystemJS 路径:运行时从服务器加载,不修改 CUI bundle
        return lazy(() => System.import(`${origin}/components/${name}.js`))
    }
    // 否则:webpack bundle 内的懒加载
    return lazy(() => import(`@/components/${type}/${name}`))

CUI 的源码作者明确写了这个分支——它就是为了"热插拔"组件设计的。

这部分可能有问题? 也许王老板一眼就清楚它说的对不对了

Dashboard Item 不传递 public/ 前缀

这是核心问题。CUI 的组件渲染链路:

Dashboard Item(Item.tsx)
  └→ ChartRender / ViewRender
       └→ <X type='chart/view' name={item.view.type.split('/')[1]} />

当 item.view.type = 'public/CustomStats' 时:

// ChartRender.tsx
<X
    type='chart'                              // type = 'chart'(硬编码)
    name={item.view.type.split('/')[1]}       // name = 'CustomStats'(只取后半段)
/>

然后 检查 name.startsWith('public/') → 'PTMStats'.startsWith('public/') → false → 走 import('@/components/chart/CustomStats') → 404。

渲染链路的设计缺陷:public/ 这个业务语义放在了 type 位置(第一个 / 之前),但 组件检测 public/ 前缀时只看 name 参数(第二个参数)。两端对不上。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions