Suppose that $f: [0,1]\to \mathbb{Q}$ is a function such that: for any sequence $x_1,x_2,\ldots,\in [0,1]$ such that $f(x_1)=f(x_2)=\ldots$ and $\lim x_n=x\in [0,1]$ then $f(x)=f(x_1)$. Prove that there exists a non-empty open interval $I$ of $[0,1]$ such that $f$ is constant on that interval.
So far, by the property of $f$, I have proved that for any $r\in \mathbb{Q}$ then the preimage $f^{-1}(r)$ is compact in $[0,1]$. But I don't know how to proceed from there. Any suggestion?