Skip to content

Commit 62be82e

Browse files
authored
Merge branch 'master' into fix-runOnjs-animation
2 parents fddded2 + 0691a19 commit 62be82e

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

docs-vitepress/guide/platform/rn.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,21 @@ mpx.config.rnConfig.downloadChunkAsync = function (packages) {
25902590
}
25912591
```
25922592

2593+
针对异步分包加载异常的场景:
2594+
2595+
* 异步组件加载失败:微信小程序提供了 [`wx.onLazyLoadError`](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onLazyLoadError.html) 的全局 api 来监听异步组件加载失败,这个 api 同样在Mpx转RN场景下生效;
2596+
* 异步页面加载失败:微信小程序未提供相关的监听异常的 api,Mpx转RN提供了一个额外的全局监听函数:
2597+
2598+
```javascript
2599+
// RN 场景下监听异步页面加载失败的全局配置
2600+
mpx.config.rnConfig.lazyLoadPageErrorHandler = function (error) {
2601+
console.log(
2602+
error.subpackage, // 加载失败的分包名
2603+
error.errType // 加载失败的类型:'timeout' | 'fail'
2604+
)
2605+
}
2606+
```
2607+
25932608
此外针对Mpx转RN的场景,还提供了一些异步分包的配置选项:
25942609

25952610
```javascript
@@ -2650,7 +2665,7 @@ module.exports = defineConfig({
26502665
其参数为当前页面的 onShareAppMessage 钩子返回内容,如果返回返回内容中包含 promise,将会在 fulfilled 后将其结果合并再触发 onShareAppMessage
26512666

26522667
`(shareInfo: { title: string, path: string, imageUrl?: string }) => void`
2653-
2668+
26542669

26552670

26562671
#### 路由
@@ -2712,4 +2727,4 @@ module.exports = defineConfig({
27122727
可在此方法中返回修改后的 dimensions,如果无返回或返回undefined,则以入参作为返回值
27132728

27142729

2715-
例如在折叠屏中我们期望只在其中一半屏上展示,可在customDimensions中判断当前是否为折叠屏展开状态,如果是则将 ScreenWidth 设置为原来的一半。
2730+
例如在折叠屏中我们期望只在其中一半屏上展示,可在customDimensions中判断当前是否为折叠屏展开状态,如果是则将 ScreenWidth 设置为原来的一半。

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const HelperRuntimeModule = require('webpack/lib/runtime/HelperRuntimeModule')
55
class LoadAsyncChunkRuntimeModule extends HelperRuntimeModule {
66
constructor (timeout) {
77
super('load async chunk')
8-
this.timeout = timeout || 5000
8+
this.timeout = timeout || 10000
99
}
1010

1111
generate () {

packages/webpack-plugin/lib/runtime/components/react/mpx-async-suspense.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
146146
})
147147
})
148148
}
149+
if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.lazyLoadPageErrorHandler === 'function') {
150+
mpxGlobal.__mpx.config.rnConfig.lazyLoadPageErrorHandler({
151+
subpackage: chunkName,
152+
errType: e.type
153+
})
154+
}
149155
loadChunkPromise.current = null
150156
setStatus('error')
151157
})

packages/webpack-plugin/lib/runtime/components/react/types/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ declare let global: {
4040
__formatValue (value: string): string | number
4141
} & Record<string, any>
4242

43+
declare let mpxGlobal: Record<string, any>
44+
4345
declare module '@react-navigation/native' {
4446
export function useNavigation (): Record<string, any>
4547
export function usePreventRemove(

0 commit comments

Comments
 (0)