This issue comes up quite a bit and the short answer is that in many cases, even with a diagnosis of dementia, a person may still have the requisite mental capacity to execute a will. The capacity to execute a will is fairly low and simply requires the person to understand the extent of their estate and "the natural objects of their bounty" which is a fancy way of saying they need to know what the own and who their relatives are. If the person is clear about these things, they may very well be able to sign a will, assuming there are no other impediments like a degree of undue influence or a sense of coercion by a caregiver or close family member who stands to benefit from the will.
Dementia typically impacts short term memory in its early stages so the awareness of familial relationships is generally not impacted and in my experience people usually have a good handle of their assets. Of course, as the disease progresses, the ability to recall the specifics of one's asset holdings begins to diminish to the point where they may no longer have the capacity to direct what happens to their assets when they die. That is to say, you cannot direct that which you do not know. The key, obviously, is for someone with a dementia diagnoses to act quickly if they wish to change their will.
It is also important to work with an experienced elder law attorney who is sensitive to these issues and understands the need to document his file in case of a challenge to the will after the person/client dies. Nothing can prevent a family member from challenging a will, but an experienced attorney will know what steps to take to minimize a post-death claim challenging the validly of a will.