in my case, It need more time to work correctly. like this:
setTimeout(function() { mymap.invalidateSize(); }, 500);