fix: Prevent errors from optional fields in chat history and chunk content

The code was relying on optional fields like `content` in chat history and chunk objects, leading to potential errors if these fields were missing. This commit ensures proper handling of these fields by adding optional chaining (`?.`) for safer access. This prevents crashes and ensures the application handles the missing fields gracefully.
This commit is contained in:
n4ze3m
2024-11-10 12:37:48 +05:30
parent f8791a0707
commit 9c7a3f5ddc
4 changed files with 19 additions and 17 deletions

View File

@@ -355,8 +355,8 @@ export const useMessage = () => {
)
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}
@@ -590,8 +590,8 @@ export const useMessage = () => {
)
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}
@@ -855,8 +855,8 @@ export const useMessage = () => {
)
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}
@@ -1064,8 +1064,8 @@ export const useMessage = () => {
})
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}

View File

@@ -276,8 +276,8 @@ export const useMessageOption = () => {
)
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}
@@ -533,8 +533,8 @@ export const useMessageOption = () => {
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}
@@ -800,8 +800,8 @@ export const useMessageOption = () => {
)
let count = 0
for await (const chunk of chunks) {
contentToSave += chunk.content
fullText += chunk.content
contentToSave += chunk?.content
fullText += chunk?.content
if (count === 0) {
setIsProcessing(true)
}