🐛[BUG]在js中使用出现chatList.push is not a function
wxf12345 opened this issue · comments
xfwu commented
🐛 bug 描述
报错信息
chatList.push is not a function
TypeError: chatList.push is not a function
📷 复现步骤
在nodejs中使用,如下方式引入ProChat进行demo测试,出现报错
<ProChat
style={{
height: '10vh',
width: '10vw',
}}
request={async (messages) => {
const response = "aaa"
return Response(response);
}}
/>
调试信息
in useChatList.js:71:104
var _useMergedState3 = useMergedState([], {
value: props.chatList,
defaultValue: props.initialChatList,
onChange: function () {
var _onChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(value) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!(props !== null && props !== void 0 && props.onChatsChange)) {
_context.next = 3;
break;
}
_context.next = 3;
return props === null || props === void 0 ? void 0 : props.onChatsChange(value);
case 3:
case "end":
return _context.stop();
}
}, _callee);
}));
function onChange(_x) {
return _onChange.apply(this, arguments);
}
return onChange;
}(),
postState: function postState(value) {
chatListRef.current = value;
return value;
}
}),
_useMergedState4 = _slicedToArray(_useMergedState3, 2),
chatList = _useMergedState4[0],
setChatList = _useMergedState4[1];
在第二次跳到这个断点时,发现
_useMergedState4:Array(2)
0: Response {type: 'default', url: '', redirected: false, status: 200, ok: true, …}
1: ƒ ()
_useMergedState4:Array(2)
0: Response {type: 'default', url: '', redirected: false, status: 200, ok: true, …}
1: ƒ ()
然后chatList便取到了_useMergedState4的首位Response而不是原来的Array
最后在useChatList:194
出现报错chatList.push is not a function,因为此时chatList已经不是Array而是Response了
chatList.push(genMessageRecord({
content: message
}, 'user'));
这里可能是因为useMergedState将_useMergedState3错误的赋值为了Response
环境信息
nodejs 18.5.0
demo@0.1.0
├── @ant-design/pro-chat@2.1.4
├── @ant-design/pro-components@2.5.1
├── @antv/g6@4.8.14
├── @dnd-kit/core@6.1.0
├── @dnd-kit/sortable@7.0.2
├── @dnd-kit/utilities@3.2.2
├── @reactflow/node-resizer@2.2.13
├── antd-style@3.6.2
├── antd@5.17.1
├── babel-plugin-import@1.13.6
├── buffer@6.0.3
├── crypto-browserify@3.12.0
├── crypto@1.0.1
├── dagre@0.8.5
├── localforage@1.10.0
├── md5@2.3.0
├── pako@2.1.0
├── react-dom@18.2.0
├── react-flow-renderer@10.3.17
├── react-scripts@5.0.1
├── react@18.2.0
├── reactflow@11.11.3
├── stream-browserify@3.0.0
└── stream@0.0.2
Shinji-Li commented
@wxf12345 版本问题,请先不要使用 ProChat 2.0 版本,2.0 还没有实装完成,请使用 1.x。 lateset 的 tag 也是 1.x 的,改动下版本号即可
xfwu commented
好的,感谢🙏
Allen commented
Allen commented
Shinji-Li commented