Change of Status H-1B petition doesn't require you to leave the US. Visa is only for entry.
https://www.wsmimmigration.com/immigration-resources/faqs/fi...
F1 is the same. You can have an expired visa but maintain legal student status in the US because visa is for entry only.