Can locally "a.e. constant" function on a connected subset $U$ of $\mathbb{R}^n$ be constant a.e. in $U$?

Consider a non-empty connected open subset $U$ of $\mathbb{R}^n$. Suppose a measurable function $u:U\to\mathbb{R}$ is locally constant on $U$, then it must be constant on $U$ according to this question.

Here is my question:

What if one changes "locally constant" to "locally a.e. constant"? More precisely, assume that for every $x\in U$ there is an open neighborhood $V$ of $x$ in $U$ such that $u$ is constant a.e. in $V$. Can one conclude that $u$ is constant on $U$ a.e.?


[Motivation] This question is mostly for a rigorous last step in the proof of this problem.


$\mathbb{R}^n$ is second countable, therefore all of its subspaces are also second countable, and thus Lindelöf spaces. By assumption, we can cover $U$ with open sets such that $u$ is a.e. constant on each of these sets. Let $\{ V_n : n \in \mathbb{N}\}$ be a countable subcover, and for $n \in \mathbb{N}$ let $N_n$ be a null set such that $u$ is constant on $V_n \setminus N_n$. Let $N = \bigcup_{n\in\mathbb{N}} N_n$. Then $N$ is a null set, and $u$ is constant on $U \setminus N$. To see the latter, let $c_n$ be the value $u$ takes on $V_n \setminus N_n$. If $V_n \cap V_k \neq \varnothing$, then $(V_n \setminus N_n) \cap (V_k \setminus N_k) \neq \varnothing$ (it has positive measure), whence $c_k = c_n$. Let

$$W_m = \bigcup \{ V_n : c_n = c_m\}.$$

Then each $W_m$ is open, and either $W_m = W_k$ or $W_m \cap W_k = \varnothing$. By the connectedness of $U$, it follows that $W_{43} = U$.