Serialized list erase content when changing focus on Unity custom EditorWindow

I’ve a custom unity editor window that displays a list of this type of objects:

  [Serializable]
    public class CustomAdditionalData
    {
        public string PayloadKey;
        public string PayloadValue;
    }

The list is correctly displayed, but when I type on any of the fields, if I change the focus to another field, it erase the content of the previous one, this is how I build the editor window:

  #if UNITY_EDITOR
    using System;
    using UnityEditor;
    using UnityEngine;
    using System.Collections.Generic;
    using System.Linq;
  
    namespace Tiles
    {
        public class CustomEditorWindow : EditorWindow
        {
            [SerializeField]
            private List<CustomAdditionalData> payloadList = new List<CustomAdditionalData>();
          
            [MenuItem("Tools/Custom Window")]
            public static void ShowWindow()
            {
                var desiredDockWindow = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
                GetWindow<CustomEditorWindow>("Custom Window", true, desiredDockWindow).Show();
            }
          
            private void OnGUI()
            {
                ScriptableObject target = this;
                var so = new SerializedObject(target);
                var payloadListProperty = so.FindProperty(nameof(payloadList));
                EditorGUILayout.PropertyField(payloadListProperty, true);
                so.ApplyModifiedProperties();
                EditorUtility.SetDirty(target); //I also tried without setting target to dirty, it does the same :(
  
                EditorGUILayout.Space();
                if (GUILayout.Button("Simulate")) {
                    SimulateButton();
                }
            }
  
            private void SimulateButton()
            {
                var payloadDict = payloadList.ToDictionary<CustomAdditionalData, string, object>(payloadAdditionalData => payloadAdditionalData.PayloadKey, payloadAdditionalData => payloadAdditionalData.PayloadValue);
                //Do something with the payloadDict
            }
        }
    }
    #endif

This is a video example of what is happening:gevdyz

SOLVED:

What I do now is to cache the so variable ONLY if it’s null (to only do it once) using:

so ??= new SerializedObject(target);

This is the final code:

#if UNITY_EDITOR
using System;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

namespace Tiles
{
[Serializable]
public class CustomAdditionalData
{
   public string PayloadKey;
   public string PayloadValue;
}
   public class CustomEditorWindow : EditorWindow
   {
       [SerializeField]
       private List<CustomAdditionalData> payloadList = new List<CustomAdditionalData>();
      
       private SerializedObject so;

       [MenuItem("Tools/Custom Window")]
       public static void ShowWindow()
       {
           var desiredDockWindow = Type.GetType("UnityEditor.InspectorWindow,UnityEditor.dll");
           GetWindow<CustomEditorWindow>("Custom Window", true, desiredDockWindow).Show();
       }
      
       private void OnGUI()
       {
           so ??= new SerializedObject(target);
           var payloadListProperty = so.FindProperty(nameof(payloadList));
           EditorGUILayout.PropertyField(payloadListProperty, true);
           so.ApplyModifiedProperties();

           EditorGUILayout.Space();
           if (GUILayout.Button("Simulate")) {
               SimulateButton();
           }
       }

       private void SimulateButton()
       {
           var payloadDict = payloadList.ToDictionary<CustomAdditionalData, string, object>(payloadAdditionalData => payloadAdditionalData.PayloadKey, payloadAdditionalData => payloadAdditionalData.PayloadValue);
           //Do something with the payloadDict
       }
   }
}
#endif