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

runtime.esm.js中mergePageInstance方法报错。Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method. #8526

Closed
young-ren opened this issue Jan 14, 2021 · 7 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@young-ren
Copy link

相关平台

微信小程序

小程序基础库: 2.14.3
使用框架: React

复现步骤

进入首页未报错,然后进入一个webview界面(webview是单独注册在app.config.js中的单独页面),然后在webview中使用wx.miniProgram.reLaunch回到首页就报错,调试后发现。next[item] = [...(next[item] || []), ...prev[item]]; next[item],prev[item] item为props时,2个都是对象,在数组中使用展开运算符就会报错

        mergePageInstance(prev, next) {
            if (!prev || !next)
                return;
            // 子组件使用 lifecycle hooks 注册了生命周期后,会存在 prev,里面是注册的生命周期回调。
            Object.keys(prev).forEach(item => {
                if (isFunction(next[item])) {
                    next[item] = [next[item], ...prev[item]];
                }
                else {
                    next[item] = [...(next[item] || []), ...prev[item]];
                }
            });
        }
react-reconciler.production.min.js:106 TypeError: Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.
    at _nonIterableSpread (nonIterableSpread.js:2)
    at _toConsumableArray (toConsumableArray.js:6)
    at eval (react.ts:109)
    at Array.forEach (<anonymous>)
    at Object.mergePageInstance (react.ts:105)
    at injectPageInstance (common.ts:22)
    at inject (react.ts:29)
    at jg (react-reconciler.production.min.js:154)
    at push../node_modules/scheduler/cjs/scheduler.production.min.js.exports.unstable_runWithPriority (scheduler.production.min.js:18)
    at hc (react-reconciler.production.min.js:29)

期望结果

不报错

实际结果

报错

环境信息

  Taro CLI 3.0.22 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.6.0 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.5 - C:\Program Files\nodejs\yarn.CMD
      npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Jan 14, 2021
@young-ren
Copy link
Author

从这个页面返回后prev有值,next也有,我有尝试在其他小程序原生页面使用api返回,没有prev

@young-ren
Copy link
Author

从这个页面返回后prev有值,next也有,我有尝试在其他小程序原生页面使用api返回,没有prev

之前是使用的navigateTo会有内存存在。目前改为relaunch之后prev的值为undefined

@Chen-jj
Copy link
Contributor

Chen-jj commented Jan 15, 2021

@young-ren 提供一下 demo

@young-ren
Copy link
Author

@young-ren 提供一下 demo

公司的代码,不好发出来,不然我都提上来了,这种问题必现就是,mergePageInstance function 参数中prev 和next都有值,当item为props时就会出现,最后导致,当前页面的setstate无效

@weiq
Copy link

weiq commented Mar 16, 2021

+1

@young-ren
Copy link
Author

@young-ren 提供一下 demo

大佬有时间看看这个问题不,还是有一些同学有问题了。虽然都使用relaunch暂时解决

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 2, 2021

@young-ren 提供一下 demo

公司的代码,不好发出来,不然我都提上来了,这种问题必现就是,mergePageInstance function 参数中prev 和next都有值,当item为props时就会出现,最后导致,当前页面的setstate无效

是提供 Demo,不是提供项目。无法对着文字 debug。

也可以先试试升级到最新版再试试,类似的问题有被解决过。

@Chen-jj Chen-jj closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

3 participants