Skip to content

fix(analytics): add chatId to handleSubmit deps to prevent stale closure#3914

Closed
waleedlatif1 wants to merge 1 commit intostagingfrom
fix/posthog-chatid-stale-closure
Closed

fix(analytics): add chatId to handleSubmit deps to prevent stale closure#3914
waleedlatif1 wants to merge 1 commit intostagingfrom
fix/posthog-chatid-stale-closure

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Fix stale closure in `handleSubmit` in `home.tsx` — `chatId` was used inside the callback to compute `is_new_task` but not included in the `useCallback` dependency array
  • If the component re-renders with a different `chatId` (e.g. navigating between task URLs), `is_new_task` would report the wrong value
  • Added `chatId` to the dep array alongside `sendMessage`

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 3, 2026 8:13am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 3, 2026

PR Summary

Low Risk
Low risk: a one-line React hook dependency fix affecting only the task_message_sent analytics property calculation.

Overview
Fixes a stale-closure bug in Home where handleSubmit used chatId to set the task_message_sent.is_new_task analytics flag but didn’t list it in the useCallback dependency array.

Adds chatId to the handleSubmit dependencies so the analytics payload stays correct when navigating between different chat/task URLs.

Written by Cursor Bugbot for commit ed4c337. Configure here.

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

Closing — false positive. TaskPage renders <Home key={taskId} chatId={taskId} />, so every taskId change remounts the component entirely. chatId never changes on a live Home instance, meaning no stale closure can occur in practice.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR fixes a stale closure bug in handleSubmit within home.tsx where chatId was used inside a useCallback to compute is_new_task for analytics but was missing from the dependency array. Without this fix, navigating between different chat URLs could cause the analytics event to report an incorrect is_new_task value if chatId changed without sendMessage changing.

  • Bug fixed: chatId added to useCallback dep array for handleSubmit (line 227), ensuring the is_new_task analytics property always reflects the current prop value
  • Scope: Single-line change with no side effects beyond recreating the callback on chatId changes (which is the correct behavior)
  • No other missing deps: The remaining variables inside the callback (posthogRef, initialViewInputRef) are refs and don't need to be listed, and setIsInputEntering is a stable state setter

Confidence Score: 5/5

Safe to merge — minimal, targeted fix with no functional regressions

Single-line dependency array fix for a legitimate stale closure bug. The change is correct, well-scoped, and has no unintended side effects. All other deps in the callback are either refs or stable setters, so no other missing deps exist.

No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/home.tsx Adds chatId to the useCallback dependency array of handleSubmit, fixing a stale closure that caused incorrect is_new_task analytics values when navigating between chats

Reviews (1): Last reviewed commit: "fix(analytics): add chatId to handleSubm..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 deleted the fix/posthog-chatid-stale-closure branch April 3, 2026 08:22
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