In Real Life, " trans panic " can have violent or even lethal consequences, as numerous trans people-especially trans women, and especially especially trans women from marginalized ethnicities (for example, Black people in The United States)-have been physically or sexually assaulted, sometimes even murdered, when their genitals are revealed. One common example is that a straight man is attracted to a woman, but finds out that she's transgender and has a penis. It's also worth noting that, in many examples of this trope, it's not the gender (i.e., gender identity) that's a shocker, but the genitals (granted, examples portraying crossdressers vastly outnumber any portraying those who are transgender). It is a sister trope to the related Sweet on Polly Oliver, which refers to when what initially appears to be inexplicable incompatible gender attraction is later revealed to actually be compatible gender attraction ( Example: Straight boy likes a boy, boy turns out to be a girl), although since the unsettling part is averted, this is usually a subversion (usually). This is both a reveal trope as well as a character reaction trope, when what initially appears to be compatible gender attraction is later revealed to actually be incompatible gender attraction ( Example: Straight boy likes a girl, girl turns out to be a boy). Other times it might not bother them, or after a period of consideration, they'll decide If It's You, It's Okay. Almost always there is shock upon The Reveal, probably disappointment and maybe even disgust on the part of the character who was feeling the attraction, but usually the two characters can reconcile by the end and become friends. Her male Gay Best Friend, who was also daydreaming about the same guy (who is "really" a girl) will probably feel similarly.
A straight female might be shocked to realize that hot guy she's been daydreaming about was "actually" a woman. note Asexuals who wouldn't be interested either way and bisexuals and pansexuals who wouldn't mind either way are usually immune to this trope, though. This works equally well with straight people as it does gay ones. Usually, said character's true gender is being kept secret purposefully, and they are a male Disguised in Drag or a female disguised as a male (sometimes even using a realistic mask or a Full-Body Disguise), but, whether the misunderstanding was intentional or not, due to Rule of Drama, they will find out, and it will be awkward, hilarious and possibly traumatizing for all involved. Sexual attraction is a funny thing, and sometimes if a character physically appears to be the right gender to appeal to their sexual orientation, then they'll become attracted to them, regardless of what that character's actual gender might be.