Closed fluiddot closed 1 month ago
I tested this PR and it works, but only for chats that already have messages. Chat, which doesn't have a conversation started, still re-renders.
Should we have a custom comparison function for
AuthenticatedView
?
Ah, interesting. I'll take a look to figure out how to prevent re-renders in that case. From my testing, this case seems to have less impact on performance as the content being re-rendered is lighter than when having several messages.
While testing this PR, I noticed another issue - entered text is preserved across the sites. I added Automattic/dotcom-forge#9208 for that.
Good catch and thanks for creating the GitHub issue 🙇 !
Should we have a custom comparison function for
AuthenticatedView
?
@wojtekn I've addressed this issue in https://github.com/Automattic/studio/pull/550/commits/8c14f0decaa4dd3f675b1863b62a5dc263fd378c.
[...] The only thing I don't think I fully understand is why the AuthenticatedView is rendering twice as soon as I access the Assistant tab with no messages 🤔 Perhaps this is a different issue though:
I checked in React Profile and AuthenticatedView
component is only rendered once when navigating to the Assistant tab. I'd like to note that checking re-renders with console logs might not be accurate in some cases.
I'd like to note that checking re-renders with console logs might not be accurate in some cases.
Interesting, thanks for checking @fluiddot - that sounds like the case I was running into 👍
Related to https://github.com/Automattic/studio/pull/549 (this issue was spotted while testing that PR) and https://github.com/Automattic/dotcom-forge/issues/9207.
Proposed Changes
AuthenticatedView
is already memorized to avoid re-renders, but still, I identified the following props to be the culprit of the re-renders:handleSend
(incomponents/content-tab-assistant.tsx
)markMessageAsFeedbackReceived
(inhooks/use-assistant.ts
)handleSend
withuseCallback
.handleSend
function, instead of theinput
state value. Otherwise, the function is re-generated when typing in the input field.markMessageAsFeedbackReceived
is already memorized but it was being re-generated due to the functionsendFeedback
from theuseSendFeedback
hook. This functional has been memorized withuseCallback
.Testing Instructions