Skip to content

Conversation

@mackwang112
Copy link
Collaborator

@mackwang112 mackwang112 commented Jul 30, 2025

feat1: web下支持asyncsubpackagerules配置注入placeholder
feat2: react下placeholder使用内置组件时在usingComponents中注入使用到的内置组件,逻辑与wx保持一致

fix1: 修复asyncsubpackagerules中声明的组件名与当前组件中usingComponents已声明组件名冲突时,asyncsubpackagerules无法生效问题

如下:compA的placeholder会被替换为bbb组件,但预期是aaa

asyncSubpackageRules: [
          {
            include: path.resolve('./src/components/compA.mpx'),
            root: 'packageA',
            placeholder: {
              name: 'placeholderComp',
              resource: path.resolve('./src/components/aaa.mpx')
            }
          }
        ]

  {
    "usingComponents": {
        "compA": "../components/compA",
        "placeholderComp": "../components/bbb"
    }
  }

修复后对于冲突的组件名将会在asyncsubpackagerules注入的组件名后加上数字,如下

  {
    "usingComponents": {
        "compA": "../components/compA",
        "placeholderComp": "../components/bbb",
        "placeholderComp1": "../components/aaa" // 注入的内容
    },
    "componentPlaceholder": {
        "compA": "placeholderComp1" // 注入的内容
    }
  }

fix2: 支付宝下asyncsubpackagerules中声明的组件名将会由驼峰转化为破折号

@mackwang112 mackwang112 force-pushed the feat-web-asyncsubpackagerules branch from 2b1673e to 7e8a320 Compare August 26, 2025 08:21
if (placeholderEntry && !jsonObj.usingComponents[placeholder]) jsonObj.usingComponents[placeholder] = placeholderEntry
if (placeholderEntry) {
if (jsonObj.usingComponents[placeholder]) {
// TODO 如果存在placeholder与已有usingComponents冲突, 重新生成一个组件名,在当前组件后增加一个数字
Copy link
Collaborator

@hiyuki hiyuki Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果当前usingComponents中的组件就是规则中配置的组件呢,不就重复注册了?

} = createJSONHelper({
loaderContext,
componentsMap,
localComponentsMap,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

入参希望稳定,看是否能够以注册回调的形式处理不同平台的处理差异

@mackwang112 mackwang112 marked this pull request as draft September 3, 2025 12:31
@mackwang112 mackwang112 marked this pull request as ready for review September 4, 2025 07:52
tarRoot,
placeholder,
resourcePath,
resolveResourcePath,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以直接用resourcePath吧,这个resource是带query的

return placeholder
}

const processAsyncSubpackageRules = (jsonObj, context, { name, tarRoot, placeholder, relativePath, resolveResourcePathMap }, callback) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to processPlaceholder

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonObj, context, { name, tarRoot, placeholder, relativePath, resolveResourcePathMap }这些参数都合成到一个对象参数中吧

})
}

const fillInComponentPlaceholder = (jsonObj, { name: componentName, placeholder, placeholderEntry, resolveResourcePathMap }, callback) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

除callback的参数合成到一个对象参数中

// 处理 驼峰转连字符
input = componentNameCapitalToHyphen('componentPlaceholder')(input)
// 将 placeholder 中使用的内建组件转化为 mpx-xxx, 并在 usingComponents 填充
function fixBuildComponentPlaceholder (input, { mode }) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to fixComponentPlaceholder


const processComponents = (components, context, callback) => {
if (components) {
const asyncComponents = []
Copy link
Collaborator

@hiyuki hiyuki Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

外层可以包一个waterfall处理串行流程,优雅一些,不然好多callback处理

pageConfig: ${JSON.stringify(pageConfig)},
// @ts-ignore
componentsMap: ${shallowStringify(componentsMap)},
componentsMap: componentsMap,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥改动

})
},
({ asyncComponents, resolveResourcePathMap }, callback) => {
async.each(asyncComponents, ({ name, tarRoot, placeholder, relativePath }, callback) => {
Copy link
Collaborator

@hiyuki hiyuki Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额,如果只有这么点逻辑的话要不还是改回去放回调里吧

@hiyuki hiyuki merged commit 1075f74 into master Oct 10, 2025
6 checks passed
@hiyuki hiyuki deleted the feat-web-asyncsubpackagerules branch October 10, 2025 09:08
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.

3 participants