Skip to content
Open
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
93 changes: 93 additions & 0 deletions FIX_PROPOSAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
To address the issue of dismissing the modal during save not cancelling persistence, we can implement a solution that checks if a save is in progress before closing the modal. Here's a possible implementation:

```typescript
// Add a variable to track if a save is in progress
let saveInProgress = false;

// Update the save path to set saveInProgress to true
setSaving(true);
saveInProgress = true;

try {
const promptData = {
title: title().trim(),
content: content().trim(),
description: description().trim(),
category: category(),
tags: tags(),
isFavorite: isFavorite(),
};

if (isEditing()) {
await promptStore.updatePrompt(promptStore.state.editingPrompt!.id, promptData);
} else {
await promptStore.createPrompt(promptData);
}

// Only close the editor if save is not in progress
if (!saveInProgress) {
promptStore.closeEditor();
}
Comment on lines +27 to +30
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

saveInProgress flow contradicts the intended behavior.

At Line 27-Line 30, if (!saveInProgress) will be false during normal successful save, so close-on-success won’t happen. At Line 39-Line 45, dismiss is blocked instead of canceling persistence, which conflicts with the bug requirement.

Suggested direction
- // Only close the editor if save is not in progress
- if (!saveInProgress) {
-   promptStore.closeEditor();
- }
+ // Close on successful save if this save wasn't canceled
+ if (!wasCanceled) {
+   promptStore.closeEditor();
+ }

 const handleClose = () => {
-  if (saveInProgress) {
-    return;
-  }
-  promptStore.closeEditor();
+  wasCanceled = true;
+  abortController?.abort(); // propagate AbortSignal into create/update
+  promptStore.closeEditor();
 };

Also applies to: 39-45

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` around lines 27 - 30, The current check uses if
(!saveInProgress) which prevents closing the editor after a successful save;
change the condition to if (saveInProgress) so promptStore.closeEditor() runs
when a save completes. Also update the dismiss flow (the handler that currently
blocks on dismiss) to cancel any ongoing persistence instead of blocking — call
the persistence cancellation/abort method (e.g., cancelSave or abortSave) before
invoking promptStore.closeEditor() so dismiss cancels save and then closes the
editor rather than blocking it.

} catch (e) {
setErrors([{ field: "general", message: String(e) }]);
} finally {
saveInProgress = false;
setSaving(false);
}

// Update the dismiss paths to check if a save is in progress
const handleClose = () => {
if (saveInProgress) {
// Show a confirmation dialog or disable dismiss affordances
// For example:
// alert("Save is in progress. Please wait for it to complete.");
return;
}
promptStore.closeEditor();
};
```

Alternatively, you can use a save generation id to check if the save has been cancelled:

```typescript
// Add a variable to track the save generation id
let saveGenerationId = 0;

// Update the save path to increment the save generation id
setSaving(true);
saveGenerationId++;

try {
const promptData = {
title: title().trim(),
content: content().trim(),
description: description().trim(),
category: category(),
tags: tags(),
isFavorite: isFavorite(),
};

if (isEditing()) {
await promptStore.updatePrompt(promptStore.state.editingPrompt!.id, promptData);
} else {
await promptStore.createPrompt(promptData);
}
Comment on lines +70 to +74
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Generation-id approach still doesn’t cancel in-flight persistence.

Line 87-Line 90 only invalidates UI close conditions; it does not cancel updatePrompt/createPrompt already awaited at Line 70-Line 74. The operation can still complete after dismiss, which is the original bug.

Also applies to: 87-90, 93-93

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` around lines 70 - 74, The current generation-id check
doesn't stop in-flight persistence: when starting a save via isEditing() →
promptStore.updatePrompt(...) or promptStore.createPrompt(...), create and use
an AbortController (or other cancellable mechanism) so you can cancel the
pending persistence call if the UI is dismissed or a new save begins; modify
promptStore.updatePrompt and promptStore.createPrompt to accept an AbortSignal
(or return a cancellable promise), abort any prior controller before starting a
new save, pass the new signal into the call, and ensure dismissal logic invokes
controller.abort() so the awaited operation is cancelled rather than only
ignored after completion.


// Only close the editor if the save generation id matches
if (saveGenerationId === currentSaveGenerationId) {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "FIX_PROPOSAL.md" -type f

Repository: PlatformNetwork/bounty-challenge

Length of output: 93


🏁 Script executed:

cat -n FIX_PROPOSAL.md | sed -n '60,95p'

Repository: PlatformNetwork/bounty-challenge

Length of output: 1509


🏁 Script executed:

cat -n FIX_PROPOSAL.md | head -100

Repository: PlatformNetwork/bounty-challenge

Length of output: 3546


🏁 Script executed:

wc -l FIX_PROPOSAL.md

Repository: PlatformNetwork/bounty-challenge

Length of output: 94


currentSaveGenerationId is undefined and never declared.

Line 77 references currentSaveGenerationId in the comparison if (saveGenerationId === currentSaveGenerationId), but this variable is not declared or captured anywhere in the proposal. The code declares only saveGenerationId (line 54) but never establishes or assigns a value to currentSaveGenerationId, making this invalid TypeScript. The logic appears incomplete—it should likely capture the saveGenerationId value before the async save operation starts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` at line 77, The code references an undeclared variable
currentSaveGenerationId in the comparison if (saveGenerationId ===
currentSaveGenerationId); to fix, capture the current generation into a properly
scoped variable before the async save begins (e.g., const
currentSaveGenerationId = saveGenerationId) and use that captured value in the
later comparison so the async completion compares against the original
saveGenerationId; ensure the declaration is in the same scope as the async
operation that will later perform the check.

promptStore.closeEditor();
}
} catch (e) {
setErrors([{ field: "general", message: String(e) }]);
} finally {
setSaving(false);
}

// Update the dismiss paths to increment the save generation id
const handleClose = () => {
saveGenerationId++;
promptStore.closeEditor();
};
```

In this implementation, the `saveGenerationId` is incremented every time a save is initiated, and the `handleClose` function increments the `saveGenerationId` when the modal is dismissed. The save path checks if the `saveGenerationId` matches the current `saveGenerationId` before closing the editor. If the `saveGenerationId` does not match, it means the save has been cancelled, and the editor is not closed.
Comment on lines +1 to +93
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

This PR does not implement the bug fix yet (docs-only change).

Line 1 through Line 93 add a proposal document, but no executable Prompt Editor/store/test code is included here. That does not meet the stated objective (“fix + tests”) for this PR.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@FIX_PROPOSAL.md` around lines 1 - 93, The PR only adds a design doc and
doesn't implement the fix or tests; implement the actual protection in the
prompt editor/save flow by wiring one of the proposed strategies: add a
module-scoped state (e.g., saveInProgress or saveGenerationId) and update the
save handler (where setSaving(...) and promptStore.createPrompt /
promptStore.updatePrompt are called) to toggle/increment that state and only
call promptStore.closeEditor() when the save generation matches or when
saveInProgress is false; also update all dismiss paths (e.g., handleClose and
any modal-dismiss handlers) to check/increment that same state to cancel/disable
closing, and add unit/integration tests that simulate cancelling the modal
during an in-flight save to assert persistence still completes and the editor
only closes when appropriate (reference symbols: saveInProgress,
saveGenerationId, handleClose, setSaving, setErrors, promptStore.closeEditor,
promptStore.createPrompt, promptStore.updatePrompt).