The other day I was watching some afternoon reruns of How I Met Your Mother on FX (ah, the glamorous life of a journalist!). The first-season episode “The Slutty Pumpkin” was on, and I saw something jarring: a scene where Marshall (Jason Segel) objects to his costume being called a “gay pirate” when he and Lily (Alyson Hannigan) win MacLaren’s Halloween costume contest. He jumps up, and says “Gay pirate!? Where are you getting that from?” When the bartender says, “You’re wearing eyeliner,” Marshall scoffs, “I just want everyone to know that I’m not a gay pirate, I have sex with my parrot (Lily) all the time!”

It was a tiny scene, but it stood out to me, because it made me realize two things: 1) We don’t see “gay panic” jokes like that on sitcoms anymore and 2) It seemed perfectly natural to have jokes like that on shows as recently as 2005, when that episode aired.

How are both of these things possible?

Let’s back up a second and define what a “gay panic” joke or storyline is. I asked a few writers and showrunners about the topic, and Kevin Biegel (Cougar Town, Enlisted), had the best response: “It’s one of those bad, hacky stories where someone confuses a character for being gay — and it causes the character to spiral out in worry and/or go to great lengths to show that they are not gay.” There are variations on the theme: the creeping specter of the gay colleague hitting on the hetero main character, a gay character being called a “fruitcake” by someone who is obviously insecure in his masculinity. It’s pretty much anything where the character who’s being mistaken as gay feels threatened.

Anyone who’s read Brett White’s fine Decider column “That Gay Episode” knows that the history of gay panic in sitcoms doesn’t track linearly; the episode of Friends where Chandler is horrified people think he’s gay because he has a “certain quality” was 20 years after a Mary Tyler Moore episode sensitively handled a character’s coming out. But it seems like gay panic was a thing on sitcoms well into the 21st century, and it feels very retrograde in retrospect.

“When you watch an older TV show or movie and hear a “gay panic” joke and it makes you almost jump in your seat cause you’re so caught by surprise,” says DeAnn Heline, co-showrunner of The Middle. “It hits your ear and makes you cringe, especially when it’s a beloved show. And it’s remarkable how shows from not that long ago were still doing that kind of storyline.”

Even one of my favorite sitcom episodes, Seinfeld‘s “The Outing,” where an NYU journalism student (Paula Marshall) outs Jerry (Jerry Seinfeld) and George (Jason Alexander) as a gay couple in a New York Post article, feels cringeworthy 25 years later. Even the episode’s famous catchphrase – “Not that there’s anything wrong with that!” – feels wrong now, as if Jerry, George and the gang are trying to convince themselves that being considered gay is no big deal. It’s belied by Jerry romancing the journalism student, saying lines like “I was outed! I wasn’t even in!” and George panicking about his feelings when he sees a male orderly give a male hospital patient a spongebath.

Funny in 1993, not so much now. When did our tastes, and the tastes of sitcom writers, change for the better? Again, it’s hard to pinpoint; it depends on your age and perspective. Ken Levine, who was a showrunner on M*A*S*H, and wrote and produced episodes of classic sitcoms like Cheers, Frasier and many more, feels that gay panic started fading in the late ’70s, with the introduction of Billy Crystal’s character Jodie on Soap, who was gay without being flamboyant or any of the other stereotypical portrayals of gay men at the time. “I think [the Baby Boomer] generation was more open to diversity than previous generations,” he says.

But the other showrunners I talked to pinned it to a later date, somewhere in the 2000s. Mike Schur (Parks and Recreation, The Good Place) thinks the change was due to “Probably just the culture slowly maturing and progressing. Not too long ago, a Democratic president [Bill Clinton] supported both Don’t Ask, Don’t Tell and the Defense of Marriage Act, which codified discrimination. Today both would be considered ancient and retrogressive if a Republican signed them.” He also theorizes that the nation coming around to be in favor of same-sex marriage a few years ago was a factor. “Obergefell [the SCOTUS ruling in favor of same-sex marriage] was probably a tipping point — it meant that the government and the majority belief system of the country had merged.”

Then how did such jokes and storylines remain culturally acceptable as recently as 2005 (and maybe even later)? “Mid-century cultural inertia dominated TV for a long time,” says Schur. “In the 1950s, Milton Berle would just walk on stage in a dress and makeup, and people would lose their minds. They’d convulse with laughter. He is just standing there, in a dress, and people howl and double-over because of how entertained they are. It took the expansion of cable, and the sophistication of the audience, to force TV to break out of its lazy patterns.” Still, he’s not sure it’s gone completely. “There are still many shows, including some premium cable and streaming shows that are pretty bad on LGBTQ issues and general representation.”

Levine thinks we’re not quite done with it either. “A year ago it looked like the country was really becoming enlightened. And now we’ve gone right back to horrible homophobia, racism, and stupidity.”

No matter when those jokes or storylines disappeared, though, avoiding “gay panic” was never something that was a network or showrunner edict. However, it’s not like the conversations over the topic never came up in the writers room. For instance, says Heline, a story on The Middle where Axl (Charlie McDermott) found out his first kiss as a kid was accidentally with his buddy Sean (Beau Wirick) generated some discussion. “We liked the story because it was just funny that two good friends found this out much later in life and it was embarrassing, etc. But as we were breaking it, we did discuss many times if it was “gay panic” storyline. Certainly none of us wanted that. We worked really hard to make sure we weren’t falling into those old stereotypes. But we still did almost pull the storyline because we just didn’t want it to be misinterpreted in any way.”

see also The 50 Most Important LGBTQ TV Characters of All-Time We polled over 40 LGBTQ television professionals and critics and...

In many cases, though, it really depends on the writing team on a particular show and how hard they try to avoid stereotypes and cheap jokes. “They’re just jokes that are both offensive and boring – a double sin, in the comedy world — so we just didn’t write them,” says Schur.

“I just think you have to be as creative as you can in your storytelling and make it as true as you can to your characters — if the point of your storyline/show is a character who doesn’t want to be seen as gay, there better be a damn good, real character-based reason behind it to make it a story,” says Biegel. “If your answer is, ‘Oh because we can make gay jokes, wouldn’t that be funny!’ then sorry, you’re just a dipshit.”

Joel Keller (@joelkeller) writes about food, entertainment, parenting and tech, but he doesn’t kid himself: he’s a TV junkie. His writing has appeared in the New York Times, Slate, Salon, VanityFair.com, Playboy.com, Fast Company’s Co.Create and elsewhere.