Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

fix(task-detail): guard against undefined task in TaskDetail render - #3774

Closed
posthog[bot] wants to merge 2 commits into
mainfrom
posthog-code/fix-task-detail-undefined-crash
Closed

fix(task-detail): guard against undefined task in TaskDetail render#3774
posthog[bot] wants to merge 2 commits into
mainfrom
posthog-code/fix-task-detail-undefined-crash

Conversation

@posthog

@posthog posthog Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Problem

Opening a task in the Code app could hard-crash the whole TaskDetail view with Cannot read properties of undefined (reading 'repository'), thrown inside React's render loop.

useRefreshedTask (added in #3758) returned its query data as if it were always a Task. But the route components subscribe to the same query key without initialData; when their observer creates the cache entry first while the fetch is still in flight, React Query drops useRefreshedTask's initialData and data comes back undefined. That undefined flowed straight into getTaskRepository, which dereferenced task.repository with no guard and threw during render.

This is a same-day regression from #3758 on a core flow (opening a task).

Changes

  • useRefreshedTask now returns data ?? initialTask, restoring the pre-regression guarantee that useTaskData always receives a defined task.
  • getTaskRepository is now null-safe on its task argument as defense in depth.

How did you test this?

  • Added a unit test to useRefreshedTask.test.tsx asserting the hook falls back to initialTask when the query yields undefined data.
  • Added repository.test.ts covering getTaskRepository with undefined / null / missing / populated inputs (plus parseRepository).
  • Verified both new tests fail without the fix and pass with it.
  • Ran pnpm --filter @posthog/ui typecheck and pnpm --filter @posthog/shared typecheck (clean) and Biome lint on the changed files.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code from this inbox report.

useRefreshedTask could return undefined when another observer subscribed to
the same query key without initialData and created the cache entry first
while the fetch was in flight, causing React Query to drop this hook's
initialData. That undefined flowed into getTaskRepository, which dereferenced
task.repository unguarded and threw inside React's render loop, crashing the
whole TaskDetail view.

Restore the pre-regression guarantee that useTaskData always has a defined
task by returning `data ?? initialTask`, and make getTaskRepository null-safe
on its argument as defense in depth.

Generated-By: PostHog Code
Task-Id: 400e2a89-4ede-447f-8ce9-97f61889cd19
@trunk-io

trunk-io Bot commented Jul 23, 2026

Copy link
Copy Markdown

🚫 This pull request was removed from the merge queue because it was closed by @tatoalo. See more details here.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 318369c.

@tatoalo tatoalo self-assigned this Jul 24, 2026
@tatoalo
tatoalo marked this pull request as ready for review July 24, 2026 08:18
@tatoalo
tatoalo enabled auto-merge (squash) July 24, 2026 08:23
@tatoalo tatoalo closed this Jul 29, 2026
auto-merge was automatically disabled July 29, 2026 10:56

Pull request was closed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant