Skip to content

feat: Optimize the loading style of the conversation - #8291

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@feat_loading
Dec 3, 2026
Merged

shaohuzhang1 merged 1 commit into
v3from
pr@v3@feat_loading

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

feat: Optimize the loading style of the conversation

@shaohuzhang1
shaohuzhang1 merged commit d131261 into v3 Dec 3, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@feat_loading branch December 3, 2026 10:16
<ConversationLoading :size="20" />
</div>
</ReverseInfiniteScroll>
<ShareFooter v-if="isShared" />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. null is not handled

    • Default parameter contents: ChatContent[] = [] only handles undefined, not null.
    • If children or content can be null from the API, contents.some(...) may throw.
    • Prefer Array.isArray(contents) guard.
  2. Recursive traversal can overflow / loop

    • Deep or cyclic children structures 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/Set for visited nodes.
  3. 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, or STREAMING should suppress the bottom loader.
  4. Only the last message is checked

    • messages.value.at(-1)?.content assumes streamLoading always refers to the last message.
    • If streamLoading can be true while running content exists in an earlier message, the logic may be incorrect.
    • Verify this invariant or check all relevant messages/contents.
  5. 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]
  6. CSS / visual regression

    • The old .mk-conversation-loading class is removed. Check whether its CSS is now dead and remove it if unused.
    • Verify ConversationLoading accepts a numeric size prop and renders the same visual size as the old loader.
    • Check snapshots/tests that may depend on the old markup.
  7. Import consistency

    • ConversationLoading uses 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 if ConversationLoading can be placed directly:
    <ConversationLoading v-if="showStreamLoading" :size="20" />
    only if no wrapper styling/layout is required.

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>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the diff

  1. Inconsistent :size usage — 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.
  2. shrink-0 on body spinner is likely meaningless

    • The body wrapper is <div v-else-if="loading">, not a flex container, so shrink-0 does nothing there. Only meaningful in the header flex row. Remove it from the body instance to avoid confusion.
  3. Possible layout regression in header

    • Previously <span class="mk-conversation-loading" /> relied on CSS (mk-conversation-loading class) 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-loading usage elsewhere — if unused after this change, remove the stale CSS.
  4. Accessibility / semantics

    • Loading indicators should ideally expose role="status" / aria-label. Check whether ConversationLoading handles that internally; if not, add aria-label="Loading" at call sites.
  5. Import path depth

    • @/conversation-panel/components/loading/index.vue reaches 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.
  6. No lazy loading

    • ConversationLoading is a small component, but if it pulls additional deps, defineAsyncComponent could keep the patch diff chunk lean while loading only when needed. Optional.
  7. Test coverage

    • Snapshot/DOM tests asserting .mk-conversation-loading will break. Search for that selector in tests and update.
  8. 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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant