[BUG] <微信小程序,多次编译打包,部分addNativeEventListener添加的小程序原生事件(onPullDownRefresh、onShareAppMessage,)失效>
- Dominant language
- JavaScript
- Stars
- 8k
- Forks
- 611
- PR merge metrics
- No merged PRs in 30d
Description
### ⌨️
- [ ] 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_
Contributor guide
Research direction
Start with build.json, build.plugin.js, and src/settings.js, then reproduce repeated yarn build:prod runs in the WeChat developer tools using the addNativeEventListener and registerNativeEventListeners example. Compare the generated mini-program behavior after consecutive builds, checking whether onPullDownRefresh and onShareAppMessage remain active without changing the registration code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100