This is an automated email from the ASF dual-hosted git repository.

msyavuz pushed a commit to branch msyavuz/chore/unsaved-changes-new-charts
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b8229913a055f00c2c716da3df2ec04c15ca01dd
Author: Mehmet Salih Yavuz <[email protected]>
AuthorDate: Fri Feb 6 00:27:00 2026 +0300

    fix(explore): Don't show unsaved changes modal on new charts
---
 .../components/ExploreChartHeader/index.jsx        | 23 ++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git 
a/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx 
b/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx
index dccc438a187..21ee14b4b15 100644
--- a/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx
+++ b/superset-frontend/src/explore/components/ExploreChartHeader/index.jsx
@@ -192,13 +192,23 @@ export const ExploreChartHeader = ({
   const metadataBar = useExploreMetadataBar(metadata, slice);
   const oldSliceName = slice?.slice_name;
 
+  // Capture initial form data for new charts
+  const [initialFormDataForNewChart] = useState(() =>
+    !slice ? { ...formData, chartTitle: oldSliceName } : null,
+  );
+
   const originalFormData = useMemo(() => {
+    // For new charts (no slice), use the captured initial formData
+    if (!slice && initialFormDataForNewChart) {
+      return initialFormDataForNewChart;
+    }
+    // For existing charts, use the saved sliceFormData if available
     if (!sliceFormData) return {};
     return {
       ...sliceFormData,
       chartTitle: oldSliceName,
     };
-  }, [sliceFormData, oldSliceName]);
+  }, [sliceFormData, oldSliceName, slice, initialFormDataForNewChart]);
 
   const currentFormData = useMemo(
     () => ({ ...formData, chartTitle: sliceName }),
@@ -210,6 +220,15 @@ export const ExploreChartHeader = ({
     [originalFormData, currentFormData],
   );
 
+  useEffect(() => {
+    console.log('slice:', slice);
+    console.log('sliceFormData:', sliceFormData);
+    console.log('formDiffs:', formDiffs);
+    console.log('hasUnsavedChanges:', Object.keys(formDiffs).length > 0);
+  }, [slice, sliceFormData, formDiffs]);
+
+  const hasUnsavedChanges = Object.keys(formDiffs).length > 0;
+
   const {
     showModal: showUnsavedChangesModal,
     setShowModal: setShowUnsavedChangesModal,
@@ -217,7 +236,7 @@ export const ExploreChartHeader = ({
     handleSaveAndCloseModal,
     triggerManualSave,
   } = useUnsavedChangesPrompt({
-    hasUnsavedChanges: Object.keys(formDiffs).length > 0,
+    hasUnsavedChanges,
     onSave: () => dispatch(setSaveChartModalVisibility(true)),
     isSaveModalVisible,
     manualSaveOnUnsavedChanges: true,

Reply via email to