Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] <微信小程序,多次编译打包,部分addNativeEventListener添加的小程序原生事件(onPullDownRefresh、onShareAppMessage,)失效> #2401

Open
1 task
fengyepiaoling opened this issue Jan 12, 2023 · 1 comment
Labels

Comments

@fengyepiaoling
Copy link

⌨️

  • 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

@wsyks
Copy link

wsyks commented Jun 28, 2023

同样碰到了,同样的代码 有时候打包好的,有时候打包出来分享就失效了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants