WASHINGTON — On Wednesday afternoon, House Republicans suffered an embarrassing defeat in trying to pass immigration legislation. The Trump administration was still reeling from the debate over the separation of migrant families. And a slew of public polls this week — including from NBC News/Marist — showed the GOP at a disadvantage for the upcoming midterms.

And then, in the blink of an eye, the story changed with Supreme Court Justice Anthony Kennedy’s decision to step down from the court, immediately triggering a political battle over his successor that will last through the summer and maybe into the fall.

For all of the focus on how Kennedy’s likely successor could change the court and its decisions over the next generation or two, there’s a more immediate political storyline — how the upcoming Supreme Court fight could upend the midterms.

The vacancy is going to complicate things for the vulnerable red-state Senate Democrats like Joe Manchin, Claire McCaskill, Heidi Heitkamp and Joe Donnelly, who’ve already been walking a fine line appealing to liberals, conservatives and independents in their home states. (Can they really abide by Senate Minority Leader Chuck Schumer’s call to delay any vote until after the midterms? Remember the government shutdown over DACA?)

It also won’t make things easy for Republicans Susan Collins, Lisa Murkowski, Jeff Flake and Bob Corker — the latter two who decided not to run for re-election in November. Assuming Sen. John McCain’s, R-Ariz., continued absence, Republicans can’t afford to lose a SINGLE vote if the Trump pick can’t get Democratic support in the 51-49 Senate. Flake could be a real wild card here. And be sure to read NBC’s Leigh Ann Caldwell on Collins and Murkowski.

Will the focus on the Supreme Court — instead of the debate over immigration and tariffs over the past week — help energize Republicans? Our NBC/WSJ poll from earlier this month found 63 percent of Democratic voters expressing a high level of interest in the midterms, versus 47 percent of Republicans with high interest. Or would Republicans be better off having the vacancy on the ballot through the midterms to sustain that energy (assuming the confirmation vote would take place sometime in September)?

Or could the Supreme Court battle fire up Democrats even more, putting the legality of abortion on voters’ minds. Also don’t be surprised if Dems make health care, the constitutionality of the Affordable Care Act, and pre-existing conditions their focus in grilling Trump’s eventual nominee. (Remember that health care, unlike abortion, unites Democrats in the red states.)

Or does it dampen Democratic enthusiasm if they don’t see their leaders trying to fight? And with Republicans controlling the U.S. Senate, remember that they hold the cards — not the Democrats.

Bottom line: This Supreme Court battle infuses a tremendous amount of uncertainty heading into what was looking like a traditional midterm environment — in which the president’s party loses a significant amount of seats. (The only question was: How many seats? Enough to lose control of the U.S. House?) But does this new storyline change that?

It certainly changed yesterday’s subject.

The Mueller wild card

One thing that makes this Supreme Court fight different from the ones during the Bush or Obama years is the Mueller probe. The president’s 2016 campaign — and the president himself — is under investigation for its possible ties to Russian interests.

And if there’s a significant development in the next month — like another indictment or guilty plea — could Democrats make the case to the public that the president shouldn’t be able to appoint a justice to the court who will probably have to rule on some aspect of the Mueller probe?

Right now, this is just speculation. But it’s also a real wild card.

Here’s why this SCOTUS fight is so charged for Democrats

Former Obama strategist David Axelrod also summed up why this Supreme Court vacancy is so charged, especially for Democrats. “This @SCOTUS nomination will determine a lot about the nature of American life for a generation or more. Yet the decision will be made by a president who lost the popular vote and a Senate whose majority represents less than half of a deeply divided country,” he tweeted.

Another way to look at it: Republicans have lost the election or the popular vote to Democrats in SIX of the last SEVEN presidential contests. But they’re possibly on the verge of a permanent conservative-majority Supreme Court for another generation or two.

Throw in Mitch McConnell’s decision not to hold a vote — or even hearings — on Barack Obama’s Supreme Court pick in 2016, and it all raises an important question: How is this good for America’s democracy?

Yes, elections have consequences. Rules are rules (like the Electoral College deciding presidential contests, not the popular vote). And politics ain’t beanbag.

But how much strain does it put on a democracy when a political minority — at least when it comes to the popular vote — not only controls the Supreme Court, but also doesn’t allow the other party to get a hearing on their Supreme pick when they controlled the presidency?

This has been a very good week for Trump

If last week was a political disaster for President Trump, as our colleague Beth Fouhy observes, this week has been a winner. Victory at the Supreme Court with the travel ban. Victory at the Supreme Court over union dues. And now his chance to put another justice on the Supreme Court.

Experts: North Korea is expanding its nuclear research center

By the way, if it weren’t for the Supreme Court, this would be a MUCH bigger story right now. “North Korea continues to make improvements to a major nuclear facility, raising questions about President Donald Trump's claim that Kim Jong Un has agreed to disarm, independent experts tell NBC News,” per Ken Dilanian and Courtney Kube. “New satellite images made public by 38north, a web site devoted to analyzing North Korea, show that ‘improvements to the infrastructure at North Korea's Yongbyon Nuclear Scientific Research Center are continuing at a rapid pace,’ three 38north analysts concluded in a paper.”