Pressing F to swap an item stack from a container into the player’s empty offhand creates a ghost item if the player’s inventory is cleared that tick.
This does not seem to happen when the player’s offhand was not initially empty (which is fortunate because that would have allowed for item duplication). Also, upon opening the creative inventory, the ghost item either disappears or becomes a real item.
To reproduce
/setblock ~ ~ ~ chest{Items:[{count:32,Slot:13b,id:"minecraft:prismarine_shard"}]}Place and power a repeating command block with
execute as @p if data entity @s equipment.offhand at @s run particle minecraft:scrape ~ ~1 ~ 0.3 0 0.3 1 3Place and power a repeating command block with
clear @pOpen the chest, hover over the prismarine shards and press F
The prismarine shards appear in your offhand, but no particles appearDe-power the command block that was clearing your inventory
Open your inventory and click on the prismarine shards
They disappear since they were a ghost item
Can confirm in 1.21.9. This was previously reported in MC-297508 (but it applies to singleplayer too) and the root cause is likely the same as for MC-199643 and MC-251555. I will update the title and description and request “relates to” links to the latter two issues.