kitten has linked us to the scientific info. The article doesn't explain how to acclimate fish though
so I will offer my comments on that aspect.
First, fish from the store are different than fish flown in from somewhere that have been confined to the shipping water for many more hours, perhaps days. So there are two different processes.
With fish from a store where you are home in a few hours. My method is to open the bag and float it to equalize the temperature slowly, say for 15-20 minutes (it is not usually far off so this is adequate). Then I add some of the tank water to the bag, about a cup. Wait 15-20 minutes. Add another cup, wait as before. If they are sensitive fish, I do a third, and maybe a fourth. Then net the fish out of the bag and into the aquarium. Never pour the bag water in; it has ammonia you don't want more of, it may have pathogens and various other nasties. An alternative some use is the drip method. Same principle, but here after equalizing the temp, pour the bag water with the fish into a pail, then drip the tank water in with a piece of tubing. After it is 50/50, net the fish from the pail into the tank.
I know professional fish breeders who do not do any of the above, they maintain it is more stressful than simply netting the fish from the bag into the aquarium (provided temp is equal). I'm not a biologist so I can't say which is better, but I do the above.
With fish long in the bag, this can be dangerous for the reason you mention. Only if the tank water is basic (pH above 7) could this occur, but if it is then it may. I have only once had to deal with transported fish that were in the container for several days. There had been a delay, and as it was (to me) an emergency--a third of the fish were already dead--I just broke open the bags and dumped the water and fish into a running aquarium I happened to have going. They were killifish, and none that were alive died. I had soft acidic water in the aquarium, that obviously helped.