Fix trajectory viewer showing wrong data by using unique step IDs#165
Fix trajectory viewer showing wrong data by using unique step IDs#165khaliqgant merged 1 commit intomainfrom
Conversation
Step IDs were generated as `step-0`, `step-1`, etc. regardless of which
trajectory they belonged to. This caused React key collisions when
switching between trajectories - React would reuse DOM elements for
steps with the same key, displaying stale data from the previous
trajectory.
Fix: Include trajectory ID in step IDs: `{trajectoryId}-step-{index}`
This ensures each step has a unique key across all trajectories, so
React properly unmounts old steps and mounts new ones when the user
switches between trajectories.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 My Senior Dev — Analysis Complete👤 For @khaliqgant📁 Expert in View your contributor analytics → 📊 1 file reviewed • 3 need attention
🚀 Open Interactive Review →The full interface unlocks features not available in GitHub:
💬 Chat here: 📖 View all 12 personas & slash commandsYou can interact with me by mentioning In PR comments or on any line of code:
Slash commands:
AI Personas (mention to get their perspective):
For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews. |
| @@ -582,10 +582,13 @@ export async function listTrajectorySteps(trajectoryId?: string): Promise<{ | |||
| } | |||
There was a problem hiding this comment.
AI Conversation Transcript
👤 khaliqgant
so how was this loading in a trajectory at all?
🤖 AI Assistant
The code in question is part of a function that likely retrieves and processes steps from a trajectory, which is a series of events or actions taken in a certain context (like a simulation, animation, or user actions).
Here's how it relates to loading a trajectory:
-
Trajectory Identification: The trajectory is identified by an ID, which is retrieved using
const trajId = trajectory.id || 'unknown';. This line attempts to get theidof the trajectory being processed. If the ID is not available, it defaults to'unknown'. -
Event Processing: The nested loops iterate over
trajectory.chaptersand their respectiveevents. For each event, a step is created and pushed into thestepsarray. This is where the line in question comes into play:id: `${trajId}-step-${stepIndex++}`,
Here, the step ID is constructed using the trajectory ID and the current step index. This helps in ensuring that each step has a unique identifier, which is crucial for rendering in frameworks like React.
-
Output: The function likely returns the constructed
stepsarray, which contains all the processed steps of the trajectory, each identified uniquely based on the trajectory ID and step index.
If the trajectory ID is invalid or missing, the function defaults to using 'unknown', which could lead to non-unique step IDs if multiple trajectories are processed without valid IDs. This is a potential issue that could affect how the trajectory is displayed or interacted with, as outlined in the AI analysis summary.
From My Senior Dev
Summary
step-0,step-1, etc. regardless of trajectoryTechnical Details
When viewing trajectory A and switching to trajectory B:
step-0,step-1,step-2step-0,step-1,step-2(same keys!)React sees the same keys and reuses the existing DOM elements, potentially displaying old data from trajectory A instead of the new data from trajectory B.
Fix
Include trajectory ID in step IDs to ensure uniqueness:
traj_abc-step-0,traj_abc-step-1traj_xyz-step-0,traj_xyz-step-1(different keys!)Now React properly unmounts old steps and mounts new ones when switching trajectories.
Test plan
🤖 Generated with Claude Code