LVIV, Ukraine—On brief leave from fighting against Russia’s invasion of Ukraine, soldier Petro Kotovych’s wife, Maria, rushed him to a fertility clinic here.

The couple had struggled to have a baby and undergone five rounds of IVF before the war. Now, with Petro drafted into the Ukrainian army and Moscow’s forces posing an existential threat to the country, their personal battle to conceive seemed more urgent.

“I insisted,” Maria, 35, recalls about the visit.

The clinic put Petro’s sperm on ice in early 2023. In May of that year, he was declared missing in action.

It left his distraught wife to decide whether to carry on trying—without knowing whether the father of any baby conceived was dead or alive.

In the more than three years since Russia invaded, war has ravaged everything in Ukraine, from its churches and children’s play parks to its citizens’ plans for the future. As it drags on, the conflict is reaching deeper into the most personal parts of the lives of Ukrainians, even down to their decisions over when, how and whether to conceive.

Maria learned her husband was missing after an officer knocked on the door of the couple’s apartment in the city of Rivne on the evening of May 4, 2023, and handed her a formal notice bearing a stark message: “The serviceman stopped communicating, absent from the unit.”

Petro, who worked as a cook at a gas station before being drafted, was last seen alive near the front-line city of Bakhmut, a deployment location he had kept secret from his wife.

Thousands of Ukrainian soldiers had died defending the city, but Maria initially clung to the hope that Petro had been separated from his unit and would show up. When that notion faded, she scoured Telegram channels where Russia parades its prisoners of war, searching for her husband among the battered and bruised faces of captured Ukrainians.

At the church where they had married, she lit candles and prayed for Petro’s return. She worked late shifts at a supermarket and slept over at her sister’s apartment to avoid being alone.

One day, months after his disappearance, Maria reread one of Petro’s last messages to her. “You have to fight, just like me. And be happy no matter what,” it read. The fog that had engulfed her since he disappeared began to lift, she says.

She contacted the fertility clinic: Her husband was missing, but could she continue the treatment on her own?

The question had entered Ukrainian lawmakers’ agenda as the war took an increasingly bloody toll. Fertility clinics that rallied behind the military by offering to store soldiers’ reproductive cells free of charge at the outbreak of war found themselves in a legal vacuum as hordes of troops began to die.

Posthumous reproduction—effectively enabling the dead to conceive—is fraught with medical, legal and ethical considerations.

Ukrainian lawmakers looked to other countries for a template. In Germany, Sweden and France, posthumous reproduction is illegal. The U.S., Canada and Australia permit it in certain cases. Israel loosened restrictions in the wake of the Oct. 7, 2023, attacks, allowing partners as well as parents of the deceased to retrieve and make use of their reproductive cells without court approval.

In 2023, Ukraine’s Parliament passed a law allowing posthumous reproduction as long as a soldier has given consent before death.

“The memory of our fallen heroes should live on—not only in street names and memorial plaques, but also in their children,” said one lawmaker.

On the day of her appointment at the fertility clinic, just over a year since she heard Petro had gone missing, Maria traveled to the facility in Lviv alone. She had told no one except her sister that she was going ahead with the embryo transfer.

While in the clinic, Maria summed up how she decided to go ahead and try to conceive without her husband.

“Those are his cells and this is part of him,” she said.

Obstetrician-gynecologist Stefan Khmil regards helping Maria and Petro Kotovych and other couples conceive as a patriotic duty. Charts on his desk paint a dire picture of Ukraine’s demographic trajectory. Last year, Ukraine became the country with both the world’s highest death rate and lowest birthrate, according to the CIA’s World Factbook, compounding the threat to the nation’s future.

“Russia is carrying out a genocide,” said Khmil, who counts some 600 soldiers among his clients. “We must do everything possible for the Ukrainian nation to be reborn.”

Russia dismisses such allegations and says its military campaign aims to prevent Ukraine from posing a threat.

Two weeks after the procedure, Maria received good news: She was pregnant. For the first time since Petro’s disappearance, she stopped searching for him among the prisoners of war on Telegram, and allowed herself to look forward. She hoped the baby would have dimples like Petro’s. They had discussed names: Rostyslav, Vladyslav or Bohdan for a boy. Varvara for a girl. “I was so excited,” she said.

She made plans to reveal the news to her mother-in-law, but the dream ended with a miscarriage .

The loss was overwhelming. Around her, war was everywhere. The supermarket where she works was short-staffed because many male employees had been drafted. Every few months, a batch of gaunt and shaven-headed Ukrainians returned home from Russia in a prisoner exchange. Petro was never among them. If alive, he turned 36 in April.

In one of their last conversations, he had remarked that his deployment might be a one-way ticket. At the time, Maria had brushed the comment aside, but now she couldn’t get it out of her head.

Still, she referred to him in the present tense, refusing to give up hope he would return. As the war entered its fourth year, she began preparing for a seventh round of IVF.

Then a new obstacle emerged. When they embarked on their latest round of fertility treatment, Petro had signed a document authorizing the clinic to use his sperm for one year. That permission, which predated Ukraine’s law on posthumous reproduction, had now expired.

To avoid lengthy court proceedings, Maria would have to seek permission from her mother-in-law, who didn’t even know she was trying to conceive. But Petro’s mother didn’t hesitate; she signed all the paperwork, allowing the treatment to go ahead.

It means as the war rages on, Maria now keeps a steady vigil for two longed-for arrivals.

Write to Isabel Coles at isabel.coles@wsj.com