小程序基础库升级后引起jsEnginScriptError e.page.__callPageLifeTime__ is not a function

背景

最近一个比较久没迭代的公司小程序,出现了只显示首页,其他页面都空白的情况。起初开发者工具中模拟器正常,真机上出现问题,后切换基础库后,模拟器上复现了问题。所以判断系基础库更新引起的兼容问题。

错误提示如下

错误1:启动首页后出现,但是首页正常显示,因为基本逻辑已经执行完

WAService.js:1 App: onLaunch have been invoked
WAService.js:1 App: onShow have been invoked
WAService.js:1 Register Page: page/tabBar/index/index
WAService.js:1 Register Page: page/tabBar/mine/mine
WAService.js:1 Register Page: page/tabBar/inspiration/inspiration
WAService.js:1 On app route: page/tabBar/index/index
WAService.js:1 Update view with init data
WAService.js:1 page/tabBar/index/index: onLoad have been invoked
VM428:1 jsEnginScriptError
s.__callPageLifeTime__ is not a function;onAppRoute
TypeError: s.__callPageLifeTime__ is not a function
    at Ct (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:955103)
    at xt (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:956114)
    at It (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:957427)
    at Function.<anonymous> (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:958295)
    at Nt.<anonymous> (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:931964)
    at Nt.emit (...

错误2:切换页面后出现

VM428:1 jsEnginScriptError
e.page.__callPageLifeTime__ is not a function;onAppRoute
TypeError: e.page.__callPageLifeTime__ is not a function
    at kt (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:955341)
    at http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:957163
    at It (http://127.0.0.1:30653/appservice/__dev__/WAService.js:1:957403)
    at Function.<anonymous> (...

分析

以上错误提示是模拟器上的错误提示,真机上错误提示中还有“onShow”或“onHide”字段,一开始以为是基础库要求必须实现onShow/onHide,结果发现不是。回到错误1发现应该是在onLoad中就已经挂掉。

onLoad code:

  onLoad: function(options) {
    this.getData();
    wxp.getNetworkType(this);
  },

既然index页操作显示正常,那可能问题就在wxp.getNetworkType(this);,跟踪发现项目中getNetworkType存在:

  • wxPromisify.js 微信SDK api的Promise化
  • wxapi.js 微信SDK api的统一处理util,内部function最终调用的wxPromisify

wxp对应wxPromisify.js,也就是对应的微信SDK api。
微信SDK getNetworkType api说明中可以看到接收的Object参数需要的三个属性均为非必填。
正常情况下不应该有上述错误。之前上线也确实没有错误。
wxapi.getNetworkType这个util function中需要接收正是page context,内部在调用wxp.getNetworkType()不传参后执行了一些设置网络状态的操作,不影响原逻辑,于是修改为wxapi.getNetworkType后,错误修复。

结论

在微信基础库更新后getNetworkType参数不能传入page context,但不传参、传入{}、或者传入指定实现的obj都不会出现上述错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值