Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(chat): keep the welcome view honest about loading, history and dead prompts

Etienne Lescote436ab3f5cf4
diff --git a/src/components/ai-edition/ChatWelcome.test.tsx b/src/components/ai-edition/ChatWelcome.test.tsx
index 5902d6c47..94ee3902d 100644
--- a/src/components/ai-edition/ChatWelcome.test.tsx
+++ b/src/components/ai-edition/ChatWelcome.test.tsx
@@ -47,9 +47,7 @@ describe("ChatWelcome", () => {
const onOpen = vi.fn();
renderIn("en", <ChatWelcome onOpenProviderSettings={onOpen} />);
- const cta = screen.getByTestId("chat-welcome-cta");
- expect(cta).toBeInTheDocument();
- fireEvent.click(cta);
+ fireEvent.click(screen.getByRole("button", { name: /set up a provider/i }));
expect(onOpen).toHaveBeenCalledTimes(1);
});
@@ -83,8 +81,8 @@ describe("ChatWelcome", () => {
it("exposes the welcome region to assistive tech", () => {
renderIn("en", <ChatWelcome onOpenProviderSettings={vi.fn()} />);
- // The component marks itself as a region with the title as its
- // accessible name — screen readers announce the title on focus.
+ // The region is labelled by the <h2> itself (aria-labelledby), so the
+ // title is announced once, not duplicated by a redundant aria-label.
const region = screen.getByRole("region", { name: /bring your own ai/i });
expect(region).toBeInTheDocument();
});
diff --git a/src/components/ai-edition/ChatWelcome.tsx b/src/components/ai-edition/ChatWelcome.tsx
index 3012b01c5..78510a329 100644
--- a/src/components/ai-edition/ChatWelcome.tsx
+++ b/src/components/ai-edition/ChatWelcome.tsx
@@ -1,19 +1,17 @@
// Welcome view for the LM chat panel.
//
-// Shown in the chat body when no LLM provider is connected (whether the user
-// has just installed the app, or used to have a provider and removed all
-// credentials). It explains what the chat can do, then routes the user to the
-// provider settings dialog with a single CTA. A small disclaimer under the
-// button makes it clear that, once a provider IS connected, the video's
-// transcript will be sent to it.
+// Shown in the chat body when the chat has nothing it can talk to — see
+// canSendChat() in chatAvailability.ts for the exact condition. It explains
+// what the chat can do, then routes the user to the provider settings dialog
+// with a single CTA. A small disclaimer under the button makes it clear that,
+// once a provider IS connected, the video's transcript will be sent to it.
//
-// We deliberately do NOT keep the prior "no messages yet" placeholder in this
-// branch — without a provider there is no way to send a first message, so the
-// hint would be a dead end. The regular `chat.emptyState` line still appears
-// for the brief window where a provider is connected but no messages have
-// been exchanged yet.
+// It replaces the `chat.emptyState` hint (which would be a dead end with no
+// provider), but only while the conversation is empty: a user who disconnects
+// mid-project keeps their history on screen, with the composer disabled.
import { ArrowRight, Info, Sparkles } from "lucide-react";
+import { useId } from "react";
import { useScopedT } from "@/contexts/I18nContext";
import styles from "./NewEditorShell.module.css";
@@ -24,14 +22,17 @@ interface ChatWelcomeProps {
export function ChatWelcome({ onOpenProviderSettings }: ChatWelcomeProps) {
const t = useScopedT("editor");
+ const titleId = useId();
return (
- <div className={styles.chatWelcome} role="region" aria-label={t("chat.welcome.title")}>
+ <div className={styles.chatWelcome} role="region" aria-labelledby={titleId}>
<header className={styles.chatWelcomeHero}>
<span className={styles.chatWelcomeIcon} aria-hidden="true">
<Sparkles size={20} />
</span>
- <h2 className={styles.chatWelcomeTitle}>{t("chat.welcome.title")}</h2>
+ <h2 className={styles.chatWelcomeTitle} id={titleId}>
+ {t("chat.welcome.title")}
+ </h2>
<p className={styles.chatWelcomeSubtitle}>{t("chat.welcome.subtitle")}</p>
</header>
@@ -50,12 +51,7 @@ export function ChatWelcome({ onOpenProviderSettings }: ChatWelcomeProps) {
</li>
</ul>
- <button
- type="button"
- className={styles.chatWelcomeCta}
- onClick={onOpenProviderSettings}
- data-testid="chat-welcome-cta"
- >
+ <button type="button" className={styles.chatWelcomeCta} onClick={onOpenProviderSettings}>
{t("chat.welcome.cta")}
<ArrowRight size={14} />
</button>
diff --git a/src/components/ai-edition/LeftPanel.tsx b/src/components/ai-edition/LeftPanel.tsx
index 9c2631d96..051700364 100644
--- a/src/components/ai-edition/LeftPanel.tsx
+++ b/src/components/ai-edition/LeftPanel.tsx
@@ -674,7 +674,8 @@ function ChatStripPanel() {
bottom: number;
} | null>(null);
const [reasoningBusy, setReasoningBusy] = useState(false);
- const [connectedProviders, setConnectedProviders] = useState<string[]>([]);
+ // null until the first llmGetSnapshot() lands: "unknown", not "none".
+ const [connectedProviders, setConnectedProviders] = useState<string[] | null>(null);
// Derive "can the user actually chat right now?" once, then use it
// everywhere. A stale active config that points at a provider with no
// credentials still counts as not-ready — the welcome view + disabled
@@ -783,8 +784,11 @@ function ChatStripPanel() {
// to the settings modal instead of sending a doomed request and
// surfacing a generic LLM error. The composer is also disabled in this
// state, but Enter-to-send could still slip through (e.g. focus
- // restored via shortcut), so the check lives here too.
+ // restored via shortcut), so the check lives here too. The toast is what
+ // explains the modal to prompts that never touched the composer — the
+ // timeline's Auto-enhance hands its text straight to send().
if (!canChat) {
+ toast.error(t("chat.composerDisabledNoProvider"));
setSettingsOpen(true);
return;
}
@@ -1423,7 +1427,7 @@ function ChatStripPanel() {
</div>
<div className={styles.panelBody} ref={scrollRef}>
- {!canChat ? (
+ {!canChat && messages.length === 0 ? (
<ChatWelcome onOpenProviderSettings={() => setSettingsOpen(true)} />
) : messages.length === 0 ? (
<p
@@ -1695,7 +1699,7 @@ function ChatStripPanel() {
<ModelQuickPopover
anchorRect={modelPopoverRect}
llmConfig={llmConfig}
- connectedProviders={connectedProviders}
+ connectedProviders={connectedProviders ?? []}
onClose={() => setModelPopoverOpen(false)}
onConfigChange={() => void refreshLlm()}
onOpenFullSettings={() => setSettingsOpen(true)}
diff --git a/src/components/ai-edition/NewEditorShell.module.css b/src/components/ai-edition/NewEditorShell.module.css
index 7da864548..d497cc9c1 100644
--- a/src/components/ai-edition/NewEditorShell.module.css
+++ b/src/components/ai-edition/NewEditorShell.module.css
@@ -2118,15 +2118,15 @@
.backBtn:disabled { opacity: 0.5; cursor: not-allowed; }
/* ─── chat welcome (no provider connected) ──────────────────────── */
+/* .panelBody supplies the horizontal inset (var(--sp-3) var(--sp-4)); only the
+ top breathing room is ours, or the card sits twice as far in as the messages. */
.chatWelcome {
display: flex;
flex-direction: column;
align-items: stretch;
gap: var(--sp-3);
- padding: var(--sp-4) var(--sp-4) var(--sp-3);
+ padding: var(--sp-2) 0 0;
text-align: left;
- /* The .panelBody parent already centers, but a slightly tighter card
- keeps the welcome readable when the rail is at its narrowest. */
}
.chatWelcomeHero {
diff --git a/src/components/ai-edition/chatAvailability.test.ts b/src/components/ai-edition/chatAvailability.test.ts
index c1a9d8521..87f98c3da 100644
--- a/src/components/ai-edition/chatAvailability.test.ts
+++ b/src/components/ai-edition/chatAvailability.test.ts
@@ -7,6 +7,14 @@ function cfg(provider: string, model = "gpt-4o-mini"): AiEditionLlmConfig {
}
describe("canSendChat", () => {
+ it("stays optimistic while the snapshot is still in flight", () => {
+ // null connectedProviders = not loaded yet. Returning false here would
+ // flash the welcome view on every mount, and leave it up for good when
+ // llmGetSnapshot fails (refreshLlm swallows the error).
+ expect(canSendChat(null, null)).toBe(true);
+ expect(canSendChat(cfg("openai"), null)).toBe(true);
+ });
+
it("returns false when there is no config at all", () => {
expect(canSendChat(null, [])).toBe(false);
});
diff --git a/src/components/ai-edition/chatAvailability.ts b/src/components/ai-edition/chatAvailability.ts
index b8e8d0e6f..cfa9c4373 100644
--- a/src/components/ai-edition/chatAvailability.ts
+++ b/src/components/ai-edition/chatAvailability.ts
@@ -7,6 +7,10 @@
// stale config that points at a provider with no credentials should look
// the same as "nothing set up yet" to the UI.
//
+// This mirrors `runChat`'s own preflight in electron/ai-edition/chat-service.ts
+// (config present → provider known → credential resolves), so the composer is
+// disabled exactly when a send would have failed.
+//
// Kept as a tiny pure function so the welcome-vs-composer gating in
// <LeftPanel /> can be tested in isolation.
@@ -14,8 +18,15 @@ import type { AiEditionLlmConfig } from "@/native/contracts";
export function canSendChat(
llmConfig: AiEditionLlmConfig | null,
- connectedProviders: string[],
+ connectedProviders: string[] | null,
): boolean {
+ // null = the snapshot has not landed yet, which is "unknown", not "none".
+ // Treating it as none flashed the welcome view at every user on every mount
+ // and, since refreshLlm() swallows its errors, locked the panel behind an
+ // undismissable welcome whenever the IPC call failed. Staying optimistic
+ // degrades to the pre-welcome behaviour instead: type, send, get the real
+ // error from the main process.
+ if (connectedProviders === null) return true;
if (llmConfig === null) return false;
if (llmConfig.provider === "") return false;
return connectedProviders.includes(llmConfig.provider);