Grocers offset some of this risk by processing some of the food onsite, selling precooked meals, premade salads, etc.
If it was more profitable to further reduce costs, then they would, but there are diminishing returns on end of the line food processing, since the kitchens and packaging required are generalized for a broad range of foods instead of being a specialized operation that is more efficient.
It sucks, but it's the system that capital built, and pretty much the only thing we can do if we don't like it is to focus on buying local, or electing politicians who will target food waste as a policy.