This affects the Farming Profession of Villagers from the 1.14 and subsequent versions of Minecraft, it is not known if it will affect villagers generated from earlier versions (pre-1.14).
Tested using minecraft:carrot on the minecraft:composter block which was the workstation of the villager affected. The villager trade was 22 minecraft:carrot(s) for 1 minecraft:emerald(s).
Can be recreated by composting Carrots in a Composter block while within range of a villager that has a trade for carrots in return for an emerald. This may work with other compostable items.
The villager will continue to hold the emerald in its arms until hotbar slot is changed or another non-trade item is moved into the slot through the inventory.
Related issues
Attachments
Comments


Relates/duplicate of MC-166669
Can confirm in 20w51a.
Can confirm in 21w03a.
Can confirm in 1.16.5 and 21w08b.
Can confirm in 21w15a.
Can confirm in 1.17.
Can confirm in 1.17.1 and 1.18 Pre-release 5.
Can confirm in 1.18.1.
Can confirm in 1.18.2.
Can confirm in 1.19.
Can confirm in 1.19.2.

Still happening in 1.21.4, tested with wheat and it works the same, so I guess all items do, my guess is that the "selected item" is not really updated when the stack runs out at least not for the villagers close by.