react-native-sse
react-native-sse copied to clipboard
Fix greedy regex
When processing an event right now, if a SSE event starts with a space or is just made up of space characters, the regex filtering the data:
field will remove all of the spaces before it finds a non-space character.
I read the spec and says the space after the colon should be ignored, but all other characters until the newline.
Example streaming response from ChatGPT showing when this is an issue: when asking What is 10-3
, it returns:
handleLLMNewToken { token: '' }
handleLLMNewToken { token: '10' }
handleLLMNewToken { token: ' -' }
handleLLMNewToken { token: ' ' }
handleLLMNewToken { token: '3' }
handleLLMNewToken { token: ' equals' }
handleLLMNewToken { token: ' ' }
handleLLMNewToken { token: '7' }
handleLLMNewToken { token: '.' }
handleLLMNewToken { token: '' }
Which will currently produce:
"10"
"-" // <- missing space
// <-missing event with just a space
"3"
"equals" // <- missing space
// <-missing event with just a space
"7"
"."