Prevent ExecuteInEditMode scripts to call Awake OnEnable Start after compiling and game exit

I have trouble with the ExecuteInEditMode Attribute is driving me crazy. Basicly I want to preview a procedural mesh while in editmode and playmode, so a new meshrenderer gameobject should be instantiated and reffered by the script to alter the meshdata (Just like the built-In trailrenderer).

This works so far in both modes, but after every compiling or leaving from Playmode a new meshrender object gets created. How can I maintain for the whole lifetime of the script having only referring the same meshrenderer?

public class CreateMesh : MonoBehaivour {
    [SerializeField] private Mesh mesh;

    void OnEnable(){
        if(meshRenderer == null && !Application.isCompiling && !Application.isPlaying) //STILL CALLS
          CreateMeshRenderer();
    }
    private void CreateMeshRenderer(){
        meshRenderer  = new GameObject("Mesh_"+name, typeof(MeshRenderer), typeof(MeshFilter)).GetComponent<MeshRenderer>();
        mf = meshRenderer.GetComponent<MeshFilter>();
    }

This is also called on stored Prefabs in the ProjectWindow.

Do you want to preview the mesh only when the GameObject is selected in Scene view? If so, you could use an Update() instead and check to see if the object is contained in Selection.transforms.