I believe expanding or collapsing should not alter the original window size. As you can see, after repeatedly opening and closing it multiple times, the window gets progressively shrunk.
Hi, unfortunately this is a well-known weird behaviou of default Blender areas. If I recreate absolutely exact area manually, API works normally, but on default workspace it has unpredictable splitting