# Sub file references main file, but references do not appear when compiling main file

I am trying to write a large document, and for the sake of organized editing, it makes sense to have each chapter as a standalone document. I am using the standalone package to accomplish this. I have references in the main document that need to be used in subdocuments, and I am trying to use the xr package to accomplish this. However, I have run into the following problem.

A minimal working example is as follows. We have a primary file main.tex, and a secondary file sub/sub.tex in a subfolder. The main.tex file reads:

\documentclass[12pt,twoside]{article}

\usepackage[subpreambles]{standalone}
\usepackage{xr}

\begin{document}
\section{Test}\label{test}
\input{sub/sub}

\end{document}

\documentclass[12pt,twoside,class=article, crop=false]{standalone}

\usepackage{xr}
\externaldocument[main-]{../main}

\begin{document}
Referencing the main section: \ref{main-test}
\end{document}

When I compile sub/sub.tex, it works as expected:

However, when I compile main.tex, the reference cannot be found:

How can I get the subfile to reference the main file in such a way that the reference compiles correctly in the main file?