fix: pass treeData directly to startSession to avoid stale state
setTree(treeData) hasn't committed when startSession runs immediately after, so tree is still null and getStepsFromTree returns []. This caused the step detail area to render empty on new session start. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -185,7 +185,7 @@ export function ProceduralNavigationPage() {
|
|||||||
|
|
||||||
// Start session immediately — no intake form modal
|
// Start session immediately — no intake form modal
|
||||||
// Variables will be filled inline during execution
|
// Variables will be filled inline during execution
|
||||||
await startSession(id, {})
|
await startSession(id, {}, treeData)
|
||||||
} catch {
|
} catch {
|
||||||
toast.error('Failed to load flow')
|
toast.error('Failed to load flow')
|
||||||
navigate('/trees')
|
navigate('/trees')
|
||||||
@@ -194,7 +194,7 @@ export function ProceduralNavigationPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const startSession = async (id: string, variables: Record<string, string>) => {
|
const startSession = async (id: string, variables: Record<string, string>, treeData?: Tree) => {
|
||||||
try {
|
try {
|
||||||
const newSession = await sessionsApi.create({
|
const newSession = await sessionsApi.create({
|
||||||
tree_id: id,
|
tree_id: id,
|
||||||
@@ -203,9 +203,9 @@ export function ProceduralNavigationPage() {
|
|||||||
setSession(newSession)
|
setSession(newSession)
|
||||||
setSessionVariables(variables)
|
setSessionVariables(variables)
|
||||||
|
|
||||||
// Initialize step states
|
// Initialize step states — use passed treeData since `tree` state may not have committed yet
|
||||||
const initialStates = new Map<string, StepState>()
|
const initialStates = new Map<string, StepState>()
|
||||||
const allSteps = getStepsFromTree(tree!)
|
const allSteps = getStepsFromTree(treeData || tree!)
|
||||||
for (const step of allSteps) {
|
for (const step of allSteps) {
|
||||||
initialStates.set(step.id, { notes: '', verificationValue: '', completedAt: null })
|
initialStates.set(step.id, { notes: '', verificationValue: '', completedAt: null })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user