In Hartshorne p. 109 he defines a sheaf $\mathcal{F}$ of $O\_X$-modules to be locally free if there is an open cover of $X$, s.t. on each $U$, $\mathcal{F}|\_U$ is a free $O\_X|\_U$ module of rank $I$. Then if $X$ is connected, rank $I$ is globally well-defined. Here $(X,O\_X)$ is any ringed topological space (e.g. not necessarily the structure sheaf of a ring). A similar definition is here: [Locally free sheaf - Encyclopedia of Mathematics](https://encyclopediaofmath.org/wiki/Locally_free_sheaf).


However, it didn't seem obvious to me that if $V$ is a smaller open set included in $U$ (say $U$ connected), then the number of copies $J$ of $(O\_X|\_V)^J=\mathcal{F}|\_V$ would remain the same, because in general the restriction map of the sheaf $O\_X$ or $\mathcal{F}$ from $U$ to $V$ need be neither subjective nor injective, why would the index $J$ stay the same as $I$?



Why is the rank of a locally free sheaf well-defined?
Actually, there are two different restriction maps:


1. The first one (the one you correctly say is neither surjective nor injective in general) is that on **sections**: for $\mathcal{F}$ a sheaf on a scheme $X$ and two open subsets $V \subseteq U$, there is a map $\mathcal{F}(U) \to \mathcal{F}(V)$.
2. On the other hand, the inclusion map $i\_{VU}: V \to U$ induces a functor $i\_{VU}^{-1}$ from the category of sheaves on $U$ to the category of sheaves on $V$. This is called restriction of **sheaves**. By functoriality, $W \subseteq V \subseteq U$ yields $i\_{WV}^{-1}\circ i\_{VU}^{-1} = i\_{WU}^{-1}$, so the notation is usually shortened to just $ -|\_{W}$.


The second one is the one that you want to look at: the statement is then that $\mathcal{F}|\_{U} \cong \mathcal{O}\_X^{\oplus I}|\_{U}$ implies $\mathcal{F}|\_{V} \cong \mathcal{O}\_X^{\oplus I}|\_{V}$ for $V \subseteq U$.


