Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app): fix stale failedCommand during Error Recovery #15973

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function useFailedLabwareUtils({
failedCommandByRunRecord,
runCommands,
}),
[failedCommandByRunRecord?.error?.errorType, runCommands]
[failedCommandByRunRecord?.key, runCommands?.meta.totalLength]
)

const tipSelectionUtils = useTipSelectionUtils(recentRelevantFailedLabwareCmd)
Expand All @@ -74,12 +74,12 @@ export function useFailedLabwareUtils({
recentRelevantFailedLabwareCmd,
runRecord
),
[protocolAnalysis, recentRelevantFailedLabwareCmd, runRecord]
[protocolAnalysis?.id, recentRelevantFailedLabwareCmd?.key]
)

const failedLabware = React.useMemo(
() => getFailedLabware(recentRelevantFailedLabwareCmd, runRecord),
[recentRelevantFailedLabwareCmd, runRecord]
[recentRelevantFailedLabwareCmd?.key]
)

const relevantWellName = getRelevantWellName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export function useRetainedFailedCommandBySource(
})
}
}
}, [failedCommandByRunRecord?.key, protocolAnalysis?.id])
}, [
failedCommandByRunRecord?.key,
failedCommandByRunRecord?.error?.errorType,
protocolAnalysis?.id,
])
Comment on lines -44 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a React idiom question, I think:

Would it not be safer for the useEffect dependencies to be failedCommandByRunRecord (the object reference) and protocolAnalysis (the object reference)? And then some memoization thing elsewhere ensures that those object references change when, and only when, the object contents change? Is that even possible?

I ask because it seems easy to miss a dependency when we list out specific scalars like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good question. To question #2, It is possible. To question #1, in general, I don't see this done elsewhere, and my guess would be that:

  • It's more code to maintain and reason about.
  • You still have the base problem of thinking about what causes a re-render, and now it exists apart from the useEffect.
  • It's arguably less efficient.
  • ESlint has a react-hooks plugin that gives us a rough idea of what dependencies we should think about adding/exclude. It's not perfect, but it's at least there.

But yes, it's incredibly easy to miss dependencies, and that's why I think a lot of React developers hesitate every time they think about reaching for useEffect.


return retainedFailedCommand
}
Loading