On Monday, Donald Trump handed Nancy Pelosi an opportunity to reclaim the narrative, and, swiftly, she took it. “This morning,” she wrote in a letter to her caucus, “the president doubled down on his attacks on our four colleagues”—Congresswomen Alexandria Ocasio-Cortez, Rashida Tlaib, Ayanna Pressley, and Ilhan Omar, whom Trump suggested should “go back” to whatever countries they came from. “Let me be clear, our Caucus will continue to forcefully respond to these disgusting attacks.” The following evening, Pelosi took the fight to the House floor, where a vote to condemn Trump devolved into parliamentary chaos when the speaker said Trump’s tweets were “racist,” running afoul of the House rules of decorum. Her words were found out of order, but not stricken from the record, and ultimately the entirety of the Democratic caucus and four Republicans voted in favor of the resolution.

The vote capped off a remarkable couple of weeks for the speaker—her first apparent stumble. Since the Democrats retook the House last November, Pelosi’s run as the de facto leader of the Democratic Party has been charmed. Her most obvious potential problem has been on her left flank, more specifically with the four congresswomen known as “the Squad,” and even more specifically, with Ocasio-Cortez. She’s mostly dealt with the problem by insisting there was no problem; the freshmen had little real power, she intimated publicly. Amazingly to many observers, her gybes were taken with good humor by Ocasio-Cortez and her colleagues—but after an interview with Maureen Dowd, in which Pelosi dismissed them as “four people” who “didn’t have any following,” festering tensions spilled into public view. “When these comments first started, I kind of thought that she was keeping the progressive flank at more of an arm’s distance in order to protect more-moderate members, which I understood,” Ocasio-Cortez told the Washington Post. But, she added, “the persistent singling out” had reached a point “where it was just outright disrespectful.”

It was Trump who saved the day for Democratic unity with his racist tweets and allowed Pelosi to get back on track at the head of her caucus. But the wounds inflicted by the dustup between the Squad and leadership won’t be healed by Trump’s racism. More acutely, this chapter epitomizes a central challenge Pelosi faces as Speaker of the House in the Trump era: reconciling the progressive and moderate wings of her party without losing the majority.

In many ways, this recent spate of Democratic infighting can be explained by Pelosi’s approach to the speakership. Though ideologically she’s a progressive, as a politician she’s a pragmatist, and that puts her on one side of the central schism in current Democratic politics. “She sees that her job as speaker is for us to win,” a Democratic staffer told me. “She is willing to do what she needs to do to make that happen and to do what she thinks is in the broadest, best interest of the caucus.” For Pelosi, winning is defined by consensus and hitting the 218-vote majority in the House. As Pelosi sees it, policy disagreements are never personal and she often compares the Democratic caucus to a kaleidoscope. “You look through it one day and the dial is turned a certain way, there’s a certain alignment of the members. This half of the room may be with this other corner. Then on another vote, the dial is turned and it’s a totally different arrangement,” a senior Democratic aide explained.

She’s comfortable with many species of Democrats. On every vote, sources stressed, Pelosi knows each member’s strengths and their weaknesses. She knows if they can be coaxed into a “yes” vote or if a sign-on to a particular piece of legislation would amount to political suicide in their home district. “She has her finger on the pulse of where everybody in the caucus is. If there’s one thing she’s good at, it is counting votes,” Congresswoman Stephanie Murphy, a cochair of the moderate Blue Dog Coalition, told me. Through this lens, the Squad really is just four votes to Pelosi; she doesn’t view them as a substantial voting block that can tank a vote on its own given the 40 seats Democrats picked up in the midterms.