Long before Roseanne Barr lost her television show for tweeting something racist, she tweeted something racist.

“Susan Rice is a man with big swinging ape balls,” the comedian wrote in 2013 about President Barack Obama’s national security adviser, who is black.

Then Barr suggested Monday that Valerie Jarrett, another prominent former Obama adviser who is black, resembled a primate.

“Muslim brotherhood and planet of the apes had a baby = vj,” Barr tweeted, setting off outrage that pushed ABC to cancel her sitcom.

After the network publicly condemned the actress’s behavior, joining a chorus of Hollywood heavyweights and politicians, comedian Kathy Griffin and other Internet voices pointed out a pattern:

Under pressure, Barr apologized.

"I am truly sorry for making a bad joke about her politics and her looks," she tweeted. "I should have known better. Forgive me -- my joke was in bad taste."

Darnell Hunt, director of the Ralph J. Bunche Center for African American Studies at the University of California at Los Angeles, said he applauded ABC’s decision to cancel its top-rated show in light of the star's Twitter use.

He hopes other networks will learn from the scandal.

“The day of reckoning is going to eventually come,” Hunt said in an interview, “and you’re going to have to pay for that.”

The move blows up a major investment, he said. Up until the network parted ways with Barr, it was heavily promoting her show and planning an Emmy campaign for it, Deadline reported.

“This is a cautionary tale,” Hunt said. “There’s no argument for making a trade-off between what is civil and decent and what you think one group might be attracted to and think you’re going to profit over the long run.”

Chai Feldblum, one of four commissioners at the Equal Employment Opportunity Commission, the government agency that investigates sexual and racial harassment claims, said employers in Hollywood and beyond make an expensive mistake when they ignore a worker’s record of misconduct.

“The cost of keeping a toxic worker in a workplace — no matter how much of a superstar that person is — is ultimately higher than getting rid of that person,” Feldblum said.

A 2015 study from the Harvard Business School found that the upside to keeping a “toxic” worker — even with the most stellar performance reviews — was outweighed by more than 2 to 1 by the cost of retaining that employee.

Toxic behaviors included sexual harassment, workplace violence, fraud or “general workplace misconduct,” the authors wrote.

Hiring a “superstar" generates an average savings of $5,300 for a company, while avoiding a toxic hire reaps $12,500 from reduced turnover alone, the researchers concluded. (They studied the output of roughly 50,000 employees at 11 global firms to reach these figures.)

That's because workers who commit sexual or racial harassment can drive away their co-workers, spark reputation damage and attract more lawsuits, Feldblum said. (She declined to comment on Barr’s case in particular.)

In 2017, the EEOC received 9,009 complaints of race-based harassment, compared with 12,428 reports of gender discrimination.

Marissa Levin, chief executive of Successful Culture, a consulting firm in Virginia, said employers shouldn’t ignore warning signs — which could include racist or anti-Semitic comments — before making an offer.

“Toxic workers are going to cause some major damage,” Levin said. “No one is untouchable.”

The revival of "Roseanne" debuted with 18 million viewers, making it a smash hit. By the end of the show's breakout run, advertisers were buying 30-second commercial slots for as much as $420,000, according to Adweek. (Before the show premiered, they went for $166,573). ABC had already ordered a second season.

Then the network pulled the plug.

“Roseanne’s Twitter statement is abhorrent, repugnant and inconsistent with our values, and we have decided to cancel her show,” ABC Entertainment President Channing Dungey said in a statement.

Sara Gilbert, who played Barr's daughter, also expressed her displeasure Tuesday.

“Roseanne’s recent comments about Valerie Jarrett, and so much more, are abhorrent and do not reflect the beliefs of our cast and crew or anyone associated with our show,” Gilbert tweeted. “I am disappointed in her actions to say the least.”

Barr's bosses, however, did not voice disapproval of the comedian's commentary before launching her reboot.

After photos from a 2009 magazine shoot resurfaced this year showing Barr dressed as Adolf Hitler, Bruce Helford, co-showrunner of “Roseanne,” urged viewers to separate Barr’s personal life from her character.

“My feeling is that people should just watch the show and judge it on its merits," he said in April. "Watch the show without the accompanying background noise.”

Read more: