You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My problem was the following: I have an app that has a chatgpt type chat, with an textinput and buttons for predefined questions.
The input and the predefined questions use the same hook to send themselves, which is basically this:
/** * Create a chat message via SSE. * @param {object} params * @param {string} params.query - User message. * @param {string} params.token - API key. * @param {object} params.eventRef - Ref to store EventSource. * @param {Function} params.setMessages - Function to update messages state. * @param {Function} params.setLoadingMessageState - Function to update loading state. * @returns {void} */constcreateChatMessage=({ query, token, eventRef, setMessages, setLoadingMessageState })=>{consteventSource=newEventSource(getAiChat(query),{headers: {Authorization: `Bearer ${token}`},debug: APP_TEST_BUILD,timeoutBeforeConnection: 250,autoStartPolling: false,});eventRef.current=eventSource;constupdatePendingMessage=({ newContent, isLoading =false, finalUpdate =false})=>{setMessages((prevMessages)=>{// boring code here});};eventSource.addEventListener('open',()=>{setLoadingMessageState(true);updatePendingMessage({isLoading: true});});eventSource.addEventListener('close',()=>{setLoadingMessageState(false);});eventSource.addEventListener('error',()=>{// boring code here});eventSource.addEventListener('message',(event)=>{// boring code here});// este metodo es no oficial agregado por mieventSource.startPolling();};constuseSendMessage=()=>{consteventSourceRef=useRef(null);constapiKey=useSelector(({ user })=>user.apiKey);constsetMessages=useSetAtom(chatMessagesAtom);constsetLoadingMessageState=useSetAtom(isLoadingMessageAtom);constsetIsShowWelcome=useSetAtom(isShowWelcomeAtom);constcloseEventSource=()=>eventSourceRef.current?.close();useEffect(()=>{return()=>{closeEventSource();};},[]);returnuseMutation(async({ message })=>{returnawaitabstractApiControl(()=>createChatMessage({query: message,token: apiKey,eventRef: eventSourceRef,setMessages: setMessages,setLoadingMessageState: setLoadingMessageState,}),);},{onMutate: async({ message })=>{setIsShowWelcome(false);setMessages(...);},// esto es para apagar los reintengtos y que sea inmediatoretry: false,networkMode: 'always',},);};exportdefaultuseSendMessage;
But the following started to happen... in some cases the buttons with defined questions did not generate any sse event. But if I used them from other scenarios they did. And if I used the input box it always generated them.... Everything used the same hook so it was very strange.
After debugging for a while I noticed that what was happening was that in those specific scenarios what was failing was that the setTimeout() of the constructor was not executed (the one called in _pollAgain).
So I made these changes and executed it manually and it didn't fail anymore........!
If someone has problems you can use my patch with patch-package and leave a comment in this ticket to know if it is useful to add the functionality to the library.
In case you don't understand the idea is to disable the autostart and do it manually by calling the new method.
The text was updated successfully, but these errors were encountered:
I think it is related to #70
My problem was the following: I have an app that has a chatgpt type chat, with an textinput and buttons for predefined questions.
The input and the predefined questions use the same hook to send themselves, which is basically this:
But the following started to happen... in some cases the buttons with defined questions did not generate any sse event. But if I used them from other scenarios they did. And if I used the input box it always generated them....
Everything used the same hook so it was very strange.
After debugging for a while I noticed that what was happening was that in those specific scenarios what was failing was that the setTimeout() of the constructor was not executed (the one called in _pollAgain).
So I made these changes and executed it manually and it didn't fail anymore........!
react-native-sse+1.2.1.patch
If someone has problems you can use my patch with patch-package and leave a comment in this ticket to know if it is useful to add the functionality to the library.
In case you don't understand the idea is to disable the autostart and do it manually by calling the new method.
The text was updated successfully, but these errors were encountered: