The bug
If you look into a container, which is a chest, ender chest, trap chest or shulker box, in spectator mode and hover over an item with your mouse and then press F, you will have a ghost item in your offhand when you go back into another gamemode. This item can’t be removed from the offhand using F. If you click on the item in creative mode, it will become a normal item, if you click on it in survival, it will disappear.
How to reproduce:
Place a chest
Take any block
Go into spectator mode
Look into the chest
Hover over an item in your inventory
Press F
Go back into creative mode
❌ You will have a ghost item in your offhand, if you place the block, it will instantly vanish.
Linked issues
is duplicated by
Attachments
Comments

Confirmed for 1.16.3 RC1
Can confirm in 1.17.1.

Can confirm 23w43b. I would like to request ownership of this issue to maintain it.
I can confirm for 1.16.2