Skip to content
Merged
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 @@ -119,6 +119,8 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
});
// ref to track if there are unsaved changes
const hasUnsavedChanges = useRef(false);
// ref to track last saved content (to skip onChange when content hasn't actually changed)
const lastSavedContent = useRef(initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>"));
// store hooks
const { getWorkspaceBySlug } = useWorkspace();
const { uploadEditorAsset, duplicateEditorAsset } = useEditorAsset();
Expand All @@ -139,21 +141,26 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
const handleDescriptionFormSubmit = useCallback(
async (formData: TFormData) => {
await onSubmit(formData.description_html, formData.isMigrationUpdate);
// Update lastSavedContent after successful save
lastSavedContent.current = formData.description_html;
},
[onSubmit]
);

// reset form values
useEffect(() => {
if (!entityId) return;
const normalizedValue = initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>");
// Update last saved content when entity/initialValue changes
lastSavedContent.current = normalizedValue;
reset({
id: entityId,
description_html: initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>"),
description_html: normalizedValue,
isMigrationUpdate: false,
});
setLocalDescription({
id: entityId,
description_html: initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>"),
description_html: normalizedValue,
isMigrationUpdate: false,
});
// Reset unsaved changes flag when form is reset
Expand Down Expand Up @@ -219,6 +226,8 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
projectId={projectId}
dragDropEnabled
onChange={(_description, description_html, options) => {
// Skip if content hasn't actually changed (handles editor normalization on init)
if (description_html === lastSavedContent.current) return;
setIsSubmitting("submitting");
onChange(description_html);
setValue("isMigrationUpdate", options?.isMigrationUpdate ?? false);
Expand Down
Loading