Skip to content

Commit 01c0225

Browse files
cursor[bot]cursoragentscopsy
authored
fix(api-service,dashboard): resolve step id undefined crash and variable editor range error (novuhq#10344)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Dima Grossman <dima@grossman.io>
1 parent 49205f4 commit 01c0225

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

apps/api/src/app/environments-v1/usecases/construct-framework-workflow/construct-framework-workflow.usecase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ export class ConstructFrameworkWorkflow {
205205
}
206206

207207
const stepType = stepTemplate.type;
208-
const { stepId } = staticStep;
208+
const stepId = staticStep.stepId || staticStep._templateId;
209209
if (!stepId) {
210-
throw new InternalServerErrorException(`Step id not found for step ${staticStep.stepId}`);
210+
throw new InternalServerErrorException(`Step id not found for step ${staticStep._id}`);
211211
}
212212
const stepControls = stepTemplate.controls;
213213

apps/dashboard/src/hooks/use-variables.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,27 @@ export function useVariables(viewRef: React.RefObject<EditorView | null>, onChan
3636
isUpdatingRef.current = true;
3737
const { from, to } = selectedVariable;
3838
const view = viewRef.current;
39+
const docLength = view.state.doc.length;
40+
41+
if (from > docLength) return;
42+
3943
const parsedVariable = parseVariable(newValue);
4044
let newVariableText = parsedVariable?.liquidVariable ?? '';
4145

4246
if (!parsedVariable?.name) {
43-
// if the value is empty, remove the variable
4447
newVariableText = '';
4548
}
4649

47-
// Calculate the actual end position including closing brackets
4850
const currentContent = view.state.doc.toString();
4951
const contentAfterFrom = currentContent.slice(from);
5052

51-
// If there are no next opening brackets, or they come after our closing brackets
5253
const closingBracketsPos = contentAfterFrom.indexOf('}}');
5354
const actualEnd = closingBracketsPos > -1 ? from + closingBracketsPos + 2 : to;
55+
const clampedEnd = Math.min(actualEnd, docLength);
5456

5557
const changes = {
5658
from,
57-
to: actualEnd,
59+
to: clampedEnd,
5860
insert: newVariableText,
5961
};
6062

@@ -65,8 +67,7 @@ export function useVariables(viewRef: React.RefObject<EditorView | null>, onChan
6567

6668
onChangeRef.current(view.state.doc.toString());
6769

68-
// Update the selected variable with new bounds
69-
setSelectedVariable({ value: newValue, from, to: actualEnd });
70+
setSelectedVariable({ value: newValue, from, to: clampedEnd });
7071
} finally {
7172
isUpdatingRef.current = false;
7273
}

0 commit comments

Comments
 (0)