📄 SKILL.md

← Vault

name: comercialrs-kanban-auto-refresh

description: Fix Kanban board not auto-refreshing when new tasks are created via Supabase realtime in ComercialRS

category: devops


ComercialRS — Kanban Auto-Refresh Bug

Problem

Kanban board (Tasks.tsx / KanbanBoard.tsx) doesn't update when new tasks are created via WhatsApp/Uazapi webhook. User must press F5 to see new meetings.

Root Cause

KanbanBoard maintains internal state: useState(externalTasks). A useEffect syncs when externalTasks changes:

`typescript

useEffect(() => {

setTasks(externalTasks);

}, [externalTasks]);

`

The problem: when AppDataContext receives a realtime INSERT from Supabase, it calls setAllTasks(prev => [...prev, newTask]). React may reuse the same array reference if the context state was already stable, so the useEffect never fires.

Fix

Track task IDs to force re-sync when content changes (not just reference):

`typescript

const [lastTaskIds, setLastTaskIds] = useState(() => externalTasks.map(t => t.id).join(','));

useEffect(() => {

const newIds = externalTasks.map(t => t.id).join(',');

if (newIds !== lastTaskIds) {

setLastTaskIds(newIds);

setTasks(externalTasks);

}

}, [externalTasks, lastTaskIds]);

`

Files Modified

Kanban Auto-Refresh Bug

Kanban board (Tasks.tsx / KanbanBoard.tsx) doesn't update when new tasks are created via WhatsApp webhook. User must press F5.

Root Cause

Supabase realtime updates arrive via AppDataContext subscription. The KanbanBoard's local state copy needs explicit ID-based comparison to catch additions from realtime INSERT events that may not change the array reference.