Repository navigation
feat: Optimize the loading style of the conversation - #8291
Conversation
| <ConversationLoading :size="20" /> | ||
| </div> | ||
| </ReverseInfiniteScroll> | ||
| <ShareFooter v-if="isShared" /> |
There was a problem hiding this comment.
Overall, the change is reasonable. The code is syntactically fine and the computed property correctly reacts to nested status/children changes. Main concerns are robustness, type safety, and assumptions about the content tree.
Potential issues
-
nullis not handled- Default parameter
contents: ChatContent[] = []only handlesundefined, notnull. - If
childrenorcontentcan benullfrom the API,contents.some(...)may throw. - Prefer
Array.isArray(contents)guard.
- Default parameter
-
Recursive traversal can overflow / loop
- Deep or cyclic
childrenstructures could cause a stack overflow or infinite recursion. - If the tree is guaranteed acyclic and small, recursion is acceptable. Otherwise, use an iterative stack and optionally a
WeakSet/Setfor visited nodes.
- Deep or cyclic
-
Hard-coded status string
'RUNNING'is a magic string. If there is a shared enum/union/constant, use it, e.g.ContentStatus.RUNNING.- Also confirm whether other statuses such as
PENDING,QUEUED, orSTREAMINGshould suppress the bottom loader.
-
Only the last message is checked
messages.value.at(-1)?.contentassumesstreamLoadingalways refers to the last message.- If
streamLoadingcan be true while running content exists in an earlier message, the logic may be incorrect. - Verify this invariant or check all relevant messages/contents.
-
Array.prototype.at()compatibility.at(-1)requires ES2022 or a polyfill depending on your build targets.- If the project supports older runtimes, use:
messages.value[messages.value.length - 1]
-
CSS / visual regression
- The old
.mk-conversation-loadingclass is removed. Check whether its CSS is now dead and remove it if unused. - Verify
ConversationLoadingaccepts a numericsizeprop and renders the same visual size as the old loader. - Check snapshots/tests that may depend on the old markup.
- The old
-
Import consistency
ConversationLoadinguses an absolute alias path while nearby local components use relative paths. This is not necessarily wrong, but run lint/import-order checks.
Suggested refactor
const RUNNING_STATUS = 'RUNNING' as const
function hasRunningContent(contents?: ChatContent[] | null): boolean {
if (!Array.isArray(contents) || contents.length === 0) return false
const stack = [...contents]
// Only needed if the content tree can contain cycles.
// const visited = new Set<ChatContent>()
while (stack.length > 0) {
const content = stack.pop()!
// if (visited.has(content)) continue
// visited.add(content)
if (content.status === RUNNING_STATUS) return true
if (Array.isArray(content.children)) {
stack.push(...content.children)
}
}
return false
}
const lastMessageContent = computed(
() => messages.value[messages.value.length - 1]?.content,
)
const showStreamLoading = computed(
() => streamLoading.value && !hasRunningContent(lastMessageContent.value),
)Minor optimization
- The wrapper
<div v-if="showStreamLoading">may be unnecessary ifConversationLoadingcan be placed directly:only if no wrapper styling/layout is required.<ConversationLoading v-if="showStreamLoading" :size="20" />
Best next checks: run tsc, ESLint, unit tests, and a visual regression for the loading state.
| <ConversationLoading class="shrink-0" :size="16" /> | ||
| </div> | ||
| </div> | ||
| </MkCollapse> |
There was a problem hiding this comment.
Review of the diff
-
Inconsistent
:sizeusage — biggest concern- Header spinner:
:size="16"matches the icon - Body spinner:
:size="16"but previous was a bare<span class="mk-conversation-loading" />with no sizing; visually this may now render too small inside an empty body area. Consider a larger size (e.g., 20/24) or no size for the body placeholder to preserve prior look.
- Header spinner:
-
shrink-0on body spinner is likely meaningless- The body wrapper is
<div v-else-if="loading">, not a flex container, soshrink-0does nothing there. Only meaningful in the header flex row. Remove it from the body instance to avoid confusion.
- The body wrapper is
-
Possible layout regression in header
- Previously
<span class="mk-conversation-loading" />relied on CSS (mk-conversation-loadingclass) for styling/alignment. Replacing with<ConversationLoading>means the old CSS class is no longer applied. If that class contained margin/size/color adjustments besides sizing, those are lost. Double-check.mk-conversation-loadingusage elsewhere — if unused after this change, remove the stale CSS.
- Previously
-
Accessibility / semantics
- Loading indicators should ideally expose
role="status"/aria-label. Check whetherConversationLoadinghandles that internally; if not, addaria-label="Loading"at call sites.
- Loading indicators should ideally expose
-
Import path depth
@/conversation-panel/components/loading/index.vuereaches across feature boundaries. Fine, but if this component is used in multiple features, consider promoting it to a shared location to avoid coupling the patch panel to the conversation panel module.
-
No lazy loading
ConversationLoadingis a small component, but if it pulls additional deps,defineAsyncComponentcould keep the patch diff chunk lean while loading only when needed. Optional.
-
Test coverage
- Snapshot/DOM tests asserting
.mk-conversation-loadingwill break. Search for that selector in tests and update.
- Snapshot/DOM tests asserting
-
Styling consistency
- Consider replacing inline
:size="16"with a shared constant/prop default so all spinners in this file stay consistent if sizes change later.
- Consider replacing inline
Summary: Functionally fine, but verify (a) body spinner size/appearance vs. before, (b) leftover .mk-conversation-loading CSS and test selectors, (c) drop the redundant shrink-0 on the non-flex body case.
feat: Optimize the loading style of the conversation