Skip to content

Commit 6fa1d46

Browse files
fix(reasoning): make "Thought for a few seconds" message reachable (#223)
* fix(reasoning): make "Thought for a few seconds" message reachable The "Thought for a few seconds" fallback message was unreachable due to useControllableState defaulting duration to 0 instead of undefined. - Changed defaultProp from 0 to undefined in useControllableState - Updated ReasoningContextValue type to allow undefined duration - Added test coverage for the undefined duration case Fixes the conditional logic where duration === 0 would trigger the shimmer animation, preventing the undefined check from ever executing. * Create odd-grapes-behave.md --------- Co-authored-by: Hayden Bleasel <hello@haydenbleasel.com>
1 parent 80a384a commit 6fa1d46

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.changeset/odd-grapes-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ai-elements": patch
3+
---
4+
5+
fix(reasoning): make "Thought for a few seconds" message reachable

packages/elements/__tests__/reasoning.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ describe("ReasoningTrigger", () => {
126126
expect(screen.getByText("Thinking...")).toBeInTheDocument();
127127
});
128128

129+
it("renders generic message when duration is undefined", () => {
130+
render(
131+
<Reasoning isStreaming={false}>
132+
<ReasoningTrigger />
133+
</Reasoning>
134+
);
135+
expect(screen.getByText("Thought for a few seconds")).toBeInTheDocument();
136+
});
137+
129138
it("renders custom children", () => {
130139
render(
131140
<Reasoning>

packages/elements/src/reasoning.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ReasoningContextValue = {
1717
isStreaming: boolean;
1818
isOpen: boolean;
1919
setIsOpen: (open: boolean) => void;
20-
duration: number;
20+
duration: number | undefined;
2121
};
2222

2323
const ReasoningContext = createContext<ReasoningContextValue | null>(null);
@@ -59,7 +59,7 @@ export const Reasoning = memo(
5959
});
6060
const [duration, setDuration] = useControllableState({
6161
prop: durationProp,
62-
defaultProp: 0,
62+
defaultProp: undefined,
6363
});
6464

6565
const [hasAutoClosed, setHasAutoClosed] = useState(false);

0 commit comments

Comments
 (0)