[BUG] <微信小程序,多次编译打包,部分addNativeEventListener添加的小程序原生事件(onPullDownRefresh、onShareAppMessage,)失效>
fengyepiaoling opened this issue · 1 comments
⌨️
- Would you like to work on a fix?
Where is the bug from?
Rax Core
Minimal code and steps to reproduce the bug
// 执行 yarn build:prod 多次,以下addNativeEventListener添加的onPullDownRefresh会失效,页面下拉无效果。
const ProfileUser = () => {
useEffect(() => {
if (isWeChatMiniProgram) {
addNativeEventListener('onPullDownRefresh', handlePullDownRefresh);
}
return () => {
if (isWeChatMiniProgram) {
removeNativeEventListener('onPullDownRefresh', handlePullDownRefresh);
}
};
}, []);
return
};
if (isWeChatMiniProgram) {
registerNativeEventListeners(ProfileUser, ['onPullDownRefresh']);
}
export default ProfileUser;
Current and expected behavior
多次编译打包,部分addNativeEventListener添加的小程序原生事件(onPullDownRefresh、onShareAppMessage,)失效,
只有重新修改registerNativeEventListeners周边的代码,再次打包才会重新生效。
即每次build要反复修改如下:
=======================反复
if (isWeChatMiniProgram) {
registerNativeEventListeners(ProfileUser, ['onPullDownRefresh']);
}
=======================反复
// if (isWeChatMiniProgram) {
registerNativeEventListeners(ProfileUser, ['onPullDownRefresh']);
// }
Environment
微信开发者工具
build.json
const path = require('path');
const settings = require(path.resolve(__dirname, './src/settings.js'));
const ossEnv = process.env.npm_lifecycle_event.split(':')[1] || 'local';
module.exports = {
targets: ['web', 'wechat-miniprogram'],
// targets: ['wechat-miniprogram'],
webpack5: true,
plugins: ['build-plugin-fusion-mobile', './build.plugin.js'],
inlineStyle: false,
lessLoaderOptions: {
additionalData: @ossURL:"
+ settings[ossEnv].ossURL + ";
,
},
'wechat-miniprogram': {
// buildType: 'runtime', // 开启运行时引擎
nativeConfig: {
appid: 'wx8407a97a7b55d6cd',
setting: {
ignoreDevUnusedFiles: false,
ignoreUploadUnusedFiles: false,
},
},
// subPackages: {
// shareMemory: true,
// },
subPackages: true,
},
web: {
mpa: true,
tabbar: true,
},
};
Possible solution
No response
Additional context
No response
同样碰到了,同样的代码 有时候打包好的,有时候打包出来分享就失效了