fix: batch updates and scrolling issues (#4167)

* use Flush instead of timeout to prevent batch updates

* fix scroll while streaming

* fix: Use setTimeout instead with flushSync for batch updates in buildUtils.ts

* [autofix.ci] apply automated fixes

* fix: Set selected view field when session is visible in IOModal

* fix: Set selected view field when session is visible in IOModal

* fix: Reset selected view field when closing IOModal

* fix: Update date format in DateReader component

- Pad hours, minutes, and seconds with leading zeros
- Remove AM/PM from the formatted date
- Use 24-hour format for hours in the formatted date

fix: Update session ID generation in IOModal component

- Remove AM/PM from the session ID format
- Use 24-hour format for hours in the session ID

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
anovazzi1 2024-10-15 18:23:03 -03:00 • committed by GitHub
commit c9b9fcf63c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 21 additions and 21 deletions

View file

@ -16296,12 +16296,6 @@
"integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==", "integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/tinycolor2": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.6.0.tgz",
"integrity": "sha512-XPaBkWQJdsf3pLKJV9p4qN/S+fm2Oj8AIPo1BTUhg5oxkvm9+SVEGFdhyOz7tTdUTfvxMiAs4sp6/eZO2Ew+pw==",
"license": "MIT"
},
"node_modules/tmp": { "node_modules/tmp": {
"version": "0.2.3", "version": "0.2.3",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz",

View file

@ -9,13 +9,10 @@ export default function DateReader({
const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are 0-indexed in JavaScript const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are 0-indexed in JavaScript
const day = String(date.getDate()).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0");
const hours = date.getHours(); const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0"); const minutes = String(date.getMinutes()).padStart(2, "0");
const seconds = String(date.getSeconds()).padStart(2, "0");
const ampm = hours >= 12 ? "PM" : "AM"; const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
const hours12 = hours > 12 ? hours - 12 : hours === 0 ? 12 : hours; // Convert to 12-hour format
const formattedDate = `${year}-${month}-${day} ${hours12}:${minutes} ${ampm}`;
return <span>{formattedDate}</span>; return <span>{formattedDate}</span>;
} }

View file

@ -133,7 +133,7 @@ export default function ChatMessage({
}, 200); }, 200);
} }
} }
}, [lastMessage]); }, [lastMessage, chat]);
let decodedMessage = chatMessage ?? ""; let decodedMessage = chatMessage ?? "";
try { try {

View file

@ -202,10 +202,16 @@ export default function IOModal({
useEffect(() => { useEffect(() => {
if (!visibleSession) { if (!visibleSession) {
setSessionId( setSessionId(
`Session ${new Date().toLocaleString("en-US", { day: "2-digit", month: "short", hour: "2-digit", minute: "2-digit", hour12: true, second: "2-digit" })}`, `Session ${new Date().toLocaleString("en-US", { day: "2-digit", month: "short", hour: "2-digit", minute: "2-digit", hour12: false, second: "2-digit", timeZone: "UTC" })}`,
); );
} else if (visibleSession) { } else if (visibleSession) {
setSessionId(visibleSession); setSessionId(visibleSession);
if (selectedViewField?.type === "Session") {
setSelectedViewField({
id: visibleSession,
type: "Session",
});
}
} }
}, [visibleSession]); }, [visibleSession]);
@ -437,6 +443,7 @@ export default function IOModal({
<Button <Button
onClick={(_) => { onClick={(_) => {
setvisibleSession(undefined); setvisibleSession(undefined);
setSelectedViewField(undefined);
}} }}
> >
New Chat New Chat

View file

@ -34,8 +34,8 @@ export const useMessagesStore = create<MessagesStoreType>((set, get) => ({
// look for the message list backwards to find the message faster // look for the message list backwards to find the message faster
set((state) => { set((state) => {
const updatedMessages = [...state.messages]; const updatedMessages = [...state.messages];
for (let i = get().messages.length - 1; i >= 0; i--) { for (let i = state.messages.length - 1; i >= 0; i--) {
if (get().messages[i].id === message.id) { if (state.messages[i].id === message.id) {
updatedMessages[i] = { ...updatedMessages[i], ...message }; updatedMessages[i] = { ...updatedMessages[i], ...message };
break; break;
} }

View file

@ -3,6 +3,7 @@ import { performStreamingRequest } from "@/controllers/API/api";
import { useMessagesStore } from "@/stores/messagesStore"; import { useMessagesStore } from "@/stores/messagesStore";
import { AxiosError } from "axios"; import { AxiosError } from "axios";
import { timeStamp } from "console"; import { timeStamp } from "console";
import { flushSync } from "react-dom";
import { Edge, Node } from "reactflow"; import { Edge, Node } from "reactflow";
import { BuildStatus } from "../constants/enums"; import { BuildStatus } from "../constants/enums";
import { getVerticesOrder, postBuildVertex } from "../controllers/API"; import { getVerticesOrder, postBuildVertex } from "../controllers/API";
@ -285,11 +286,12 @@ export async function buildFlowVertices({
return true; return true;
} }
case "token": { case "token": {
// await one milisencond so we avoid react batched updates // flushSync and timeout is needed to avoid react batched updates
await new Promise((resolve) => { setTimeout(() => {
useMessagesStore.getState().updateMessagePartial(data); flushSync(() => {
setTimeout(resolve, 10); useMessagesStore.getState().updateMessagePartial(data);
}); });
}, 10);
return true; return true;
} }
case "end": { case "end": {