MELISSA STERN is 22 months old now, and she has been at the center of an emotional, well-publicized legal battle since the day she was born. Her mother, Marybeth Whitehead-Gould -- she has divorced and remarried during the course of the litigation -- signed a contract with William Stern, the baby's father, in which she agreed to carry the child to term and surrender her to Mr. Stern and his wife for a fee of $10,000. When the child was born she couldn't do it, and the courts of New Jersey have been trying to resolve the ensuing dispute for almost two years.

After a lengthy trial last spring, the trial court held that the contract was enforceable, turned the child over to Mr. Stern, terminated Mrs. Gould's parental rights and consented to Melissa's adoption by Mr. Stern's wife, Elizabeth. The ruling was a sweeping victory for the Sterns and a complete defeat for Mrs. Gould. This week, however, the state's Supreme Court reversed. This doesn't dramatically alter Melissa's life now, because she will remain in the custody of the Sterns. But because the appeals court held that the surrogacy contract is unenforceable in New Jersey, it greatly changes the legal landscape for these arrangements. While the decision is only binding in New Jersey, this is the first such case to be decided by the highest court of any state and is likely to be followed elsewhere.

The contract is in violation of state law, wrote Chief Justice Robert N. Wilentz, because it requires the sale of a child for money. It is also against public policy because it requires permanent separation of the baby from one of her natural parents, because it grants the father more rights than the mother and because it guarantees the father custody without any provision for a hearing on the best interests of the child. Surrogacy agreements that are voluntary and do not involve the payment of money will be permitted. And the state legislature, of course, retains the right to change the statute that was the basis for the ruling. But until that happens -- and legislatures across the country have been slow to grapple with this issue -- courts in New Jersey will not enforce any more surrogacy contracts.

The ruling is a good one. The Baby M case alone demonstrates the pitfalls of surrogacy arrangements, and it did not deal with some of the more heart-wrenching questions involving handicapped children, fathers who change their minds or genetic defects transmitted by the mother. The welfare of small children is at stake in these cases, and judges should be guided by common sense and compassion, not hamstrung by contracts. Very recent technological advances give great hope to couples who want but cannot conceive children. And adoption is also a sensible, time-tested option. These alternatives remain preferable to contractual arrangements, which can so easily backfire and cause great heartache.