Right-clicking a leveled up villagers (Trading/summon command) will automatically close the trade UI. This only happens when they is no POI (Jobsite/Workstation block) nearby. Sometimes the trade UI is displayed when right-clicking again.
How to reproduce
Spawn villager
Put a workstation block
trade with the villager once
Destroy the workstation block
Trade with the villager again
Related issues
duplicates
Comments

looks likethis is tracked under MC-154201