I'm not sure if this is server lag or what the issue is (which itself needs to be looked at because dear lord the servers have been terrible lately), but ever since I came back 3 days ago to the game, I have been trading with villagers and most of the time when I use emeralds to purchase something, at least 50% of the bought items disappear. This happens a lot more often with the hero of the village effect. It may have something to do with the server updating weirdly and it takes the discount, then a few seconds later it updates and removes the discount and essentially steals the items from me. That's just my guess, but it is truly unfortunate that my items are quite literally disappearing after all the hard work to get emeralds. I have mostly been noticing this with buying enchanted Mending books from the librarian. Regardless if this is server lag or not, it needs to be fixed so that when the server is laggy the code doesn't go wacky and remove items from my inventory, that's just ridiculous.
Related issues
Comments

Same thing happens to me and MC has deemed it a pricing issue but I do not believe this is the case. You have done a better job of describing it than I have and it happens with mending Lib for me as well.
Duplicate of MC-148454