I originally wanted to leave a comment but I don't have enough rep. So the answer is honestly, it depends. Usually for my team and I we have our cloud integration set up using Azure Dev Ops where we deploy our services to AWS lambda functions. Our deployment pipeline is a separate process from our actual environments. On one of my old teams, we would change the environment variables manually for our frontend deployments by commenting and uncommenting out the variables, because we never had the time to figure out how to dynamically handle that issue. On another team, we did the same for our .NET backend services using boolean logic gates.
For some of my personal projects, I'm currently dealing with the issue of deploying frontend to both my staging/dev environment and prod environment where I have to manually change the server URI before deploying the latest changes from main into the environments. I haven't had time to figure out a good solution (think the best would be to just write some shell script that will dynamically write to the .env file the server uri based on the flag I pass it).
A former teammate also told me, there is no such thing as best practice, only what is best for your needs after a careful calculation of your trade offs.