U.S. District Judge David Alan Ezra struck down a Texas law on Wednesday that would have required hospitals and clinics to bury cremate fetal remains, causing another courtroom setback for state leaders and anti-abortion groups.

Under Senate Bill 8, passed in 2017, health care facilities including hospitals and abortion clinics would be required to bury or cremate any fetal remains — whether from abortion, miscarriage, stillbirth, or treatments for ectopic pregnancy regardless of patients’ personal wishes or beliefs. Legislators passed the bill following a ruling that year by U.S. District Judge Sam Sparks that struck down a similar rule implemented by the Texas Department of State Health Services. At the time Sparks said it was vague, caused undue burden on women and had high potential for irreparable harm.

Over the course of a nearly 30-minute hearing at a federal court in Austin on Wednesday, Ezra gave a synopsis of the ruling, calling the case "a very emotional topic." The requirement would have been challenging for health providers, in part because it would be difficult to find medical waste vendors willing to participate. In addition, Ezra expressed wariness about the state having to reach out to private cemeteries to help with fetal remain disposals.

"The implementation of this law, as I have pointed out, would cause and, if allowed to go into effect, would be a violation of a woman's right to obtain a legal abortion under the law as it stands today," Ezra said.

Ezra issued a temporary injunction on SB 8 in January after the Center for Reproductive Rights and Whole Woman’s Health sued Texas, blocking the law from going into effect on Feb. 1.

The ruling comes after a five-day trial in July at which a slew of patients, health providers, state agency officials, bioethicists, cemetery directors and religious leaders got on the witness stand.

Abortion opponents have argued that the law is a means to bring human dignity to fetuses. But reproductive rights advocates said it was another way for Texas to punish women who choose to have an abortion, and that the cost of the burials would be passed on to patients, making abortions harder to obtain for low-income Texans. But during the trial, state attorneys dropped their argument that SB 8 protects the health or safety of patients and plaintiffs' attorneys cast aside their arguments about costs to patients and providers.

Texas Attorney General Ken Paxton said in a news release that the decision "is disappointing" but his office would continue fighting for the rule to be implemented.

“I remain confident the courts will ultimately uphold the Texas law, which honors the dignity of the unborn and prevents fetal remains from being treated as medical waste," Paxton said.

Joe Pojman, executive director of Texas Alliance for Life, an anti-abortion group, said that he is not surprised by Ezra's ruling but believes Paxton's office defended the law well. He took issue with Ezra saying access to abortion would be hindered.

"Absolutely not true," Pojman said. "If the law were to go into effect, abortion would remain regularly available."

Multiple doctors and health advocates who testified said women often don’t ask what happens to their fetal tissue, since they assume it’ll be treated like medical waste. Providers also said they have experienced challenges trying to find medical waste vendors willing to work with their clinics. A top reason, they said, is that vendors are unwilling to endure backlash and harassment from anti-abortion advocates.

Amy Hagstrom Miller, founder and president of Whole Woman’s Health and Whole Woman’s Health Alliance, said in a news release that the ruling is "a victory for all Texan women."

“Make no mistake, these restrictions were designed to shame and stigmatize patients and health care providers," Hagstrom Miller said. "This decision reaffirms that Texan women are fully capable of making their own personal medical decisions about their families, futures, and reproductive health care.”

Meanwhile, state attorneys said the rule was designed to provide fetuses a better resting place than a landfill. They argued that women would not be harmed by the law and that there were churches and cemeteries statewide willing to help medical providers dispose of fetal remains.

Ezra's decision comes ahead of U.S. Senate confirmation hearings beginning Sept. 4 for President Donald Trump's Supreme Court nominee Brett Kavanaugh. If confirmed, Kavanaugh would replace Justice Anthony Kennedy, who announced his retirement in July. The prospect of Trump appointing a second Supreme Court justice has fueled speculation about the future of abortion policy, including the potential overturning of Roe v. Wade.