Your website might be doing something different between the two ways of modifying window size.
I cannot reproduce this issue with my sample.
Please give it a try.
https://github.com/adamenagy/Container/blob/master/ViewerTest.zip
Just serve the HTML page using any HTTP server - e.g. "Live Server" in Visual Studio Code:
https://youtu.be/pqS4h7WpeWc