Skip to content

Commit ccbd4f7

Browse files
committed
fix: 修复输出RN externalClasses 变化时未触发组件render
1 parent 925c222 commit ccbd4f7

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

packages/core/src/platform/patch/getDefaultOptions.ios.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,11 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
639639
})
640640
}
641641
const validProps = Object.assign({}, rawOptions.props, rawOptions.properties)
642+
if (global.__externalClasses && global.__externalClasses.length > 0) {
643+
global.__externalClasses.forEach((name) => {
644+
validProps[name] = null
645+
})
646+
}
642647
const { hasDescendantRelation, hasAncestorRelation } = checkRelation(rawOptions)
643648
if (rawOptions.methods) rawOptions.methods = wrapMethodsWithErrorHandling(rawOptions.methods)
644649
const defaultOptions = memo(forwardRef((props, ref) => {

packages/webpack-plugin/lib/loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = function (content) {
3838
return content
3939
}
4040
const { resourcePath, queryObj } = parseRequest(this.resource)
41-
41+
const externalClasses = mpx.externalClasses || []
4242
const packageRoot = queryObj.packageRoot || mpx.currentPackageRoot
4343
const packageName = packageRoot || 'main'
4444
const independent = queryObj.independent
@@ -178,6 +178,7 @@ module.exports = function (content) {
178178
originalUsingComponents,
179179
componentGenerics,
180180
autoScope,
181+
externalClasses,
181182
callback
182183
})
183184
}

packages/webpack-plugin/lib/react/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = function ({
2424
originalUsingComponents,
2525
componentGenerics,
2626
autoScope,
27+
externalClasses,
2728
callback
2829
}) {
2930
if (ctorType === 'app' && !queryObj.isApp) {
@@ -95,7 +96,8 @@ module.exports = function ({
9596
wxsModuleMap: templateRes.wxsModuleMap,
9697
localComponentsMap: jsonRes.localComponentsMap,
9798
localPagesMap: jsonRes.localPagesMap,
98-
rnConfig
99+
rnConfig,
100+
externalClasses
99101
}, callback)
100102
}
101103
], (err, scriptRes) => {

packages/webpack-plugin/lib/react/processScript.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = function (script, {
1515
localPagesMap,
1616
rnConfig,
1717
componentGenerics,
18-
genericsInfo
18+
genericsInfo,
19+
externalClasses
1920
}, callback) {
2021
const { appInfo, i18n } = loaderContext.getMpx()
2122

@@ -49,7 +50,7 @@ import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext,
4950
jsonConfig,
5051
rnConfig
5152
})
52-
output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, pagesMap, firstPage, hasApp })
53+
output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, pagesMap, firstPage, hasApp, externalClasses })
5354
output += getRequireScript({ ctorType, script, loaderContext })
5455
output += `export default global.__mpxOptionsMap[${JSON.stringify(moduleId)}]\n`
5556
} else {

packages/webpack-plugin/lib/react/script-helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ function buildGlobalParams ({
150150
firstPage,
151151
outputPath,
152152
genericsInfo,
153-
hasApp
153+
hasApp,
154+
externalClasses
154155
}) {
155156
let content = ''
156157
if (ctorType === 'app') {
@@ -165,6 +166,7 @@ global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
165166
global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
166167
global.__appComponentsMap = ${shallowStringify(componentsMap)}
167168
global.__preloadRule = ${JSON.stringify(jsonConfig.preloadRule)}
169+
global.__externalClasses = ${JSON.stringify(externalClasses || [])}
168170
global.currentInject.pagesMap = ${shallowStringify(pagesMap)}
169171
global.currentInject.firstPage = ${JSON.stringify(firstPage)}\n`
170172
} else {

0 commit comments

Comments
 (0)