This is exercise 7.13 from Chapter 6 of Aluffi's Algebra: Chapter 0 textbook. It says that if $R$ is an integral domain, $A \in M_{n}(R)$ is diagonalizable with distinct eigenvalues and $AB = BA$ (where $B$ is a square matrix of the same size as $A$), then $B$ is diagonalizable with respect to a basis of eigenvectors of $A$.
This question has been asked and answered several times in this site for the case of matrices with entries in $\mathbb{R}$ and the usual argument of showing that an eigenvector of $A$ is an eigenvector of $B$ works for matrices with entries in any field, so I could work with the field of fractions $K$ of $R$ and I could certainly show that $B$ is diagonalizable (w.r.t. to a basis of eigenvectors of $A$) as a matrix with entries in $K$. That is, given an eigenvector $v$ of $A$, one can prove that there exists $k \in K$ such that $Bv = kv$, but we'd like to obtain $r \in R$ such that $Bv = rv$ and I don't see how we could conclude this.
My issue basically comes from the fact that the eigenspaces $E_{\lambda_1}, \ldots E_{\lambda_n}$ of $A$ have rank 1, but if $\{ v_1, \ldots , v_n \}$ is a basis of $R^n$ of eigenvectors of $A$, with $v_i \in E_{\lambda_i}$, then I'm not sure whether $\{ v_i \}$ is a basis (over $R$) of the corresponding eigenspace $E_{\lambda_i}$. It's certainly a maximal linearly independent subset, but for free $R$-modules this doesn't imply that this set is a basis and, for example, $\{ 2 \}$ is a maximal linearly independent subset of the free $\mathbb{Z}$-module $\mathbb{Z}$ which is not a basis for $\mathbb{Z}$ as a $\mathbb{Z}$-module. On the other hand, if I start by taking a basis $\{ w_i \}$ for each eigenspace $E_{\lambda_i}$, I'm not sure if $\{ w_1, \ldots , w_n \}$ will form a basis of $R^n$ (again, it would be a maximal linearly independent subset of $R^n$, but I'm not sure if it will generate this $R$-module).
All of this arguments would work fine in a field instead of an integral domain, so, as I said, we could work with the field of fractions of $R$ and I don't know if this is what the author might have meant without saying it or if I'm missing something and B is actually diagonalizable (w.r.t. to a basis of eigenvectors of $A$) as a matrix with entries in $R$?
Any help or insights on this problem would be greatly appreciated.