Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix copilot comments
  • Loading branch information
Assem-Uber committed Nov 20, 2025
commit a9e94696aa2a7d7ad47ad906b1d11cd376e6648b
14 changes: 8 additions & 6 deletions src/views/workflow-history/hooks/use-workflow-history-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ export default function useWorkflowHistoryFetcher(

useEffect(() => {
if (!fetcherRef.current) return;

let lastFlattenedPagesCount: number = 0;
const unsubscribe = fetcherRef.current.onChange((state) => {
const pagesCount = state.data?.pages?.length || 0;
onEventsChange(
state.data?.pages?.flatMap((page) => page.history?.events || []) || []
);
// if the pages count is greater than the last flattened pages count, then we need to flatten the pages and call the onEventsChange callback
if (pagesCount > lastFlattenedPagesCount) {
lastFlattenedPagesCount = pagesCount;
onEventsChange(
state.data?.pages?.flatMap((page) => page.history?.events || []) || []
);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow.

It sounds like historyQuery is throttled.

On the other hand, the unthrottled flow is...

  1. When onChange, then get state.
  2. Take this state and flatten it (for what purpose?)
  3. Then take the flattened result and pass it to onEventsChange (why?)

I'm probably missing something obvious with grouping in the history page.

Copy link
Contributor Author

@Assem-Uber Assem-Uber Nov 20, 2025

Choose a reason for hiding this comment

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

Yes, history queue is throttled. Since it seems hard to understand this pattern i moved lastFlattenedPagesCount to be a ref outside the component.

The reason why we flatten is that Pages is a react-query construct. But helpers and other components accepts arrays of events. It made sense to send events here since the method name is onEventsChange. If we didn't do in this hook we would need to do it in the parent.

Comment on lines +53 to +58
Copy link
Member

Choose a reason for hiding this comment

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

I must be missing something.

My understanding:

  • When onChange fires
  • Then emit onEventsChange with fresh data

I would have expected:

  • Within onChange
  • Call onEventsChange with state.data.pages

I'm a bit confused why we don't pass state.data.pages directly (bypassing the flattening step)?

The hook, as currently implemented, knows too much about the fetcher internals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is a follow up question on this or the message didn't show up for you as it was outdated. We can continue the discussion there.

// immediately set if there is the first page without throttling other wise throttle
const executeImmediately = pagesCount <= 1;
setHistoryQuery(() => state, executeImmediately);
Expand All @@ -62,8 +66,6 @@ export default function useWorkflowHistoryFetcher(
}, [setHistoryQuery, onEventsChange]);

useEffect(() => {
if (!fetcherRef.current) return;

return () => {
fetcherRef.current?.destroy();
};
Expand Down
Loading