This happens in retrospect actually. There is a not-well-understood "temporal code" that orients memories into certain chronologies. It is theorized that this temporal code is linked to the orientation of a neural pathway that encodes the memory. Think of a literal path from neuron X to neuron Y. When that particular path lights up a second time, the memory is reconstructed in the prefrontal cortex, and the temporal entry is added to the context (i.e. this happened shortly after my 12th birthday party). The pathway is thought to not be perfectly the same every time it's hit, allowing tangential memories to get tied to the same pathway, and explaining falsified facts in memory as those pathways touch unrelated ones.
DeJa Vu in particular is thought to be a pseudo random new pathway being formed that just so happens to nearly entirely overlap another memory's pathway with an earlier chronological "entry" in the brain that's fresh enough for you to know something doesn't add up. Instantly, the new memory is written as both "now" and "back then," causing DeJa Vu retroactively. It is unclear whether this erases the old memory, muddles it, or associates it with the new memory in ways that don't necessarily correlate, which might be what a "eureka" moment amounts to.
Now is the part where I admit my source is a long ago article who's title and author have themselves been overwritten in my mind. I am also not a neuroscientist. Just got the tism.