There are people who do not go quietly into the night and just fade away when they die but become more lucid near the end, according to The New York Times in "The Gentler Symptoms of Dying."
Sometimes people who have not been communicative for a long time, will suddenly appear to be well again. Dementia patients can even have a period of lucidity where they are able to communicate with loved ones like they could before they became ill. This normally occurs within a week of the person passing away and often on the same day.
This phenomenon is known as terminal lucidity and records of it go all the way back to Hippocrates.
Understanding what people go through when they pass away and why some people have terminal lucidity could be helpful for elderly people. This knowledge could possibly be used to give doctors a way to make passing away more comfortable.
Reference: New York Times (July 11, 2017) "The Gentler Symptoms of Dying."