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

Fix demo mode: use useFarmContext instead of useFarm - #2

Merged
codybmenefee merged 1 commit into
mainfrom
fix/demo-mode-farm-context
Jan 30, 2026
Merged

codybmenefee merged 1 commit into
mainfrom
fix/demo-mode-farm-context

Conversation

@codybmenefee

Copy link
Copy Markdown
Owner

Summary

  • FarmMap and useFarmSettings were using useFarm() which relies on Clerk auth context
  • In demo mode, the farm ID comes from DemoFarmProvider via useFarmContext()
  • This was causing the map to show a loading skeleton and "Farm ID is unavailable" errors in production demo mode

Test plan

  • Test demo mode at /demo - map should render with paddocks
  • Toggle NDVI layer - should not throw "Farm ID is unavailable" error
  • Verify authenticated routes still work normally

Generated with Claude Code

FarmMap and useFarmSettings were using useFarm() which relies on
Clerk auth context. In demo mode, the farm ID comes from
DemoFarmProvider via useFarmContext(). This was causing the map
to show a loading skeleton and "Farm ID is unavailable" errors.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codybmenefee
codybmenefee merged commit 889ee99 into main Jan 30, 2026
2 checks passed
@codybmenefee
codybmenefee deleted the fix/demo-mode-farm-context branch January 30, 2026 15:38
@greptile-apps

greptile-apps Bot commented Jan 30, 2026

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

Fixed demo mode by replacing useFarm() (which depends on Clerk auth) with useFarmContext() in FarmMap and useFarmSettings. The DemoFarmProvider now properly provides farm data through the shared FarmContext, preventing "Farm ID is unavailable" errors in demo mode while maintaining compatibility with authenticated routes.

Changes:

  • FarmMap.tsx: Changed from useFarm() to useFarmContext(), accessing activeFarm instead of farm
  • useFarmSettings.ts: Changed from useFarm() to useFarmContext(), accessing activeFarmId instead of farmId

Architecture:

  • Demo routes (/demo) are wrapped with DemoFarmProvider which provides farm context from demo session
  • Authenticated routes use FarmProvider which provides farm context from Clerk organizations
  • Both providers use the same FarmContext, allowing components to work in either mode

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward refactoring that unifies the farm context interface. Both modified hooks now use the same useFarmContext() which works for both demo and authenticated modes. The changes follow the existing architecture pattern where DemoFarmProvider and FarmProvider both provide the same FarmContext interface.
  • No files require special attention

Important Files Changed

Filename Overview
app/src/components/map/FarmMap.tsx Replaced useFarm() with useFarmContext() to support demo mode farm context from DemoFarmProvider
app/src/lib/convex/useFarmSettings.ts Replaced useFarm() with useFarmContext() to get activeFarmId from demo or auth context

Sequence Diagram

sequenceDiagram
    participant Demo as Demo Route (/demo)
    participant DFP as DemoFarmProvider
    participant FC as FarmContext
    participant FM as FarmMap
    participant UFS as useFarmSettings
    
    Note over Demo,UFS: Demo Mode Flow
    Demo->>DFP: Wraps demo routes
    DFP->>FC: Provides FarmContext value
    Note over DFP,FC: activeFarm from DemoFarm<br/>activeFarmId from DemoAuth
    
    FM->>FC: useFarmContext()
    FC-->>FM: { activeFarm, isLoading }
    Note over FM: Uses activeFarm.id<br/>instead of Clerk-based farmId
    
    UFS->>FC: useFarmContext()
    FC-->>UFS: { activeFarmId, isLoading }
    Note over UFS: Uses activeFarmId<br/>for Convex queries
    
    Note over Demo,UFS: Authenticated Mode Flow
    Note over Demo: Uses FarmProvider (not DemoFarmProvider)
    Note over FC: activeFarm/activeFarmId<br/>come from Clerk organizationId
Loading

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