Skip to content

Commit cfac4a8

Browse files
committed
Fix candidate for missing definitions
1 parent 11b3123 commit cfac4a8

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

packages/component/src/hooks/useStreamingMarkdownWithDefinitions.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ export default function useStreamingMarkdownWithDefinitions(
7878

7979
const [definitions, setDefinitions] = useState<readonly MarkdownLinkDefinition[]>(EMPTY_DEFINITIONS);
8080

81+
// Reset definitions and markdown ref when the streaming renderer changes.
82+
// This must run before the main streaming effect so that a fresh renderer
83+
// starts clean, but the streaming effect can still set definitions on the same commit.
84+
useLayoutEffect(() => {
85+
previousMarkdownRef.current = '';
86+
setDefinitions(EMPTY_DEFINITIONS);
87+
}, [streamingRenderer]);
88+
8189
useLayoutEffect(() => {
8290
if (!streamingRenderer) {
8391
return;
@@ -177,11 +185,6 @@ export default function useStreamingMarkdownWithDefinitions(
177185
container.textContent = '';
178186
}, [containerRef, fallbackHTML, streamingRenderer]);
179187

180-
useLayoutEffect(() => {
181-
previousMarkdownRef.current = '';
182-
setDefinitions(EMPTY_DEFINITIONS);
183-
}, [streamingRenderer]);
184-
185188
return Object.freeze({ definitions: definitions ?? fallbackDefinitions });
186189
}
187190

0 commit comments

Comments
 (0)