When a carrot/potato is planted on a farmland, and a player or mob lands on it and reverts the farmland to dirt, the carrot/potato crop stays there.
When a mob/player lands on a farmland with potato/carrot planted and reverts the farmland to dirt, the potato/carrot wont drop and it'll stay planted even if it's not on farmland until you break the crop to get the potato/carrot.