Skip to content

Commit 7934697

Browse files
committed
fix: add bounds check for line number and clear stale handler highlight
- Guard against RangeError when lineNumber is out of document bounds - Clear highlightedHandler when clicked step has no service calls
1 parent 5257e31 commit 7934697

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

frontend/src/features/cookbook/components/linked-detail.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function LinkedPatternDetail({ flow, starlarkContent }: LinkedPatternDeta
2626

2727
const handleStepClick = useCallback((stepName: string, lineNumber: number) => {
2828
const view = editorViewRef.current
29-
if (view) {
29+
if (view && lineNumber >= 1 && lineNumber <= view.state.doc.lines) {
3030
const line = view.state.doc.line(lineNumber)
3131
view.dispatch({
3232
selection: { anchor: line.from },
@@ -38,6 +38,8 @@ export function LinkedPatternDetail({ flow, starlarkContent }: LinkedPatternDeta
3838
if (step && step.serviceCalls.length > 0) {
3939
const firstCall = step.serviceCalls[0]
4040
setHighlightedHandler(`${firstCall.service}.${firstCall.method}`)
41+
} else {
42+
setHighlightedHandler(null)
4143
}
4244
}, [flow])
4345

0 commit comments

Comments
 (0)