Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Dec 1, 2024
1 parent 62caf31 commit 0f6d859
Show file tree
Hide file tree
Showing 7 changed files with 551 additions and 33 deletions.
15 changes: 13 additions & 2 deletions webapp/src/components/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export const expandMessageReferences = (content: string, messages: Message[]): s
processedRefs.add(messageID); // Mark this reference as processed
const referencedMessage = messages.find(m => m.id === messageID);
if (referencedMessage) {
logger.debug('Expanding referenced message', {id: messageID, contentLength: referencedMessage.content.length});
//logger.debug('Expanding referenced message', {id: messageID, contentLength: referencedMessage.content.length});
node.innerHTML = expandMessageReferences(referencedMessage.content, messages);
} else {
logger.debug('Referenced message not found', {id: messageID});
Expand Down Expand Up @@ -234,6 +234,17 @@ const MessageList: React.FC<MessageListProps> = ({messages: propMessages}) => {
const messages = Array.isArray(propMessages) ? propMessages :
Array.isArray(storeMessages) ? storeMessages : [];
const messageListRef = useRef<HTMLDivElement>(null);
// Track processed reference versions to detect changes
const referencesVersions = React.useMemo(() => {
const versions: Record<string, number> = {};
messages.forEach(msg => {
if (msg.id?.startsWith('z')) {
versions[msg.id] = msg.version || 0;
}
});
return versions;
}, [messages]);

const finalMessages = React.useMemo(() => messages
.filter((message) => message.id && !message.id.startsWith("z"))
.filter((message) => message.content?.length > 0).map((message) => (
Expand All @@ -242,7 +253,7 @@ const MessageList: React.FC<MessageListProps> = ({messages: propMessages}) => {
content: expandMessageReferences(message.content, messages)
}
)),
[messages]);
[messages, referencesVersions]); // Add referencesVersions as dependency

// Effect to handle syntax highlighting after render
useEffect(() => {
Expand Down
18 changes: 9 additions & 9 deletions webapp/src/store/slices/messageSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,18 @@ const messageSlice = createSlice({
addMessage: (state: MessageState, action: PayloadAction<Message>) => {
const messageId = action.payload.id;
const messageVersion = action.payload.version;
// Ensure version is set
if (!messageVersion) {
action.payload.version = Date.now();
}

// Batch multiple message updates
if (state.pendingUpdates && state.pendingUpdates.length > 0) {
state.pendingUpdates.push(action.payload);
return;
}
// Process message immediately if no pending updates
const existingVersion = state.messageVersions[messageId];
// Skip processing if message is older or duplicate
if (existingVersion && existingVersion >= messageVersion) {
console.debug(`${LOG_PREFIX} Ignoring older/duplicate message version:`, {
id: messageId,
existing: existingVersion,
received: messageVersion
});
return;
}
state.messageVersions[messageId] = messageVersion;
if (existingVersion) {
// Update the message in place instead of removing and re-adding
Expand All @@ -82,6 +78,10 @@ const messageSlice = createSlice({
console.debug(`${LOG_PREFIX} HTML content sanitized for message ${action.payload.id}`);
}
state.messages[existingIndex] = action.payload;
// Force version update for reference messages
if (messageId.startsWith('z')) {
action.payload.version = Date.now();
}
console.debug(`${LOG_PREFIX} Updated existing message at index ${existingIndex}`);
return;
}
Expand Down
6 changes: 3 additions & 3 deletions webui/src/main/resources/application/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/static/css/main.eb836bdd.css",
"main.js": "/static/js/main.21e6ce4a.js",
"main.js": "/static/js/main.90b2f58a.js",
"static/js/9017.98ad007d.chunk.js": "/static/js/9017.98ad007d.chunk.js",
"static/js/5536.9c75127e.chunk.js": "/static/js/5536.9c75127e.chunk.js",
"static/js/7035.2bce51c5.chunk.js": "/static/js/7035.2bce51c5.chunk.js",
Expand Down Expand Up @@ -73,7 +73,7 @@
"static/js/5195.756798f5.chunk.js": "/static/js/5195.756798f5.chunk.js",
"index.html": "/index.html",
"main.eb836bdd.css.map": "/static/css/main.eb836bdd.css.map",
"main.21e6ce4a.js.map": "/static/js/main.21e6ce4a.js.map",
"main.90b2f58a.js.map": "/static/js/main.90b2f58a.js.map",
"9017.98ad007d.chunk.js.map": "/static/js/9017.98ad007d.chunk.js.map",
"5536.9c75127e.chunk.js.map": "/static/js/5536.9c75127e.chunk.js.map",
"7035.2bce51c5.chunk.js.map": "/static/js/7035.2bce51c5.chunk.js.map",
Expand Down Expand Up @@ -141,6 +141,6 @@
},
"entrypoints": [
"static/css/main.eb836bdd.css",
"static/js/main.21e6ce4a.js"
"static/js/main.90b2f58a.js"
]
}
20 changes: 1 addition & 19 deletions webui/src/main/resources/application/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<link rel="icon" href="favicon.ico"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<meta name="description" content="Web site created using create-react-app"/>
<link rel="apple-touch-icon" href="logo192.png"/>
<link rel="manifest" href="manifest.json"/>
<title>React App</title>
<script defer="defer" src="static/js/main.21e6ce4a.js"></script>
<link href="static/css/main.eb836bdd.css" rel="stylesheet">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.90b2f58a.js"></script><link href="/static/css/main.eb836bdd.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
452 changes: 452 additions & 0 deletions webui/src/main/resources/application/static/js/main.90b2f58a.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*!
* Font Awesome Free 6.7.1 by @fontawesome - https://fontawesome.com
* License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
* Copyright 2024 Fonticons, Inc.
*/

/*! @license DOMPurify 3.2.2 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.2/LICENSE */

/*! Bundled license information:

js-yaml/dist/js-yaml.mjs:
(*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT *)
*/

/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-with-selector.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* Prism: Lightweight, robust, elegant syntax highlighting
*
* @license MIT <https://opensource.org/licenses/MIT>
* @author Lea Verou <https://lea.verou.me>
* @namespace
* @public
*/

Large diffs are not rendered by default.

0 comments on commit 0f6d859

Please sign in to comment.