TikZ spy and Beamer \pause, \onslide, ... do not seem to work well together. This has been observed in several previous, albeit older questions (in particular, 1 and 2 ), but the workarounds shown there do not work for me.
M(N)WE:
\documentclass[tikz]{beamer}
\usepackage{tikz}
\usetikzlibrary{spy}
% following https://tex.stackexchange.com/questions/88251/tikz-spy-and-beamer-uncover and https://tex.stackexchange.com/questions/438218/beamer-uncover-magnification-using-tikz-spy-library:
\tikzset{
invisible/.style={opacity=0,text opacity=0},
visible on/.style={alt={#1{}{invisible}}},
connect on/.style={alt={#1{connect spies}{}}},
alt/.code args={<#1>#2#3}{%
\alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}
},
}
\begin{document}
\begin{frame}
\frametitle{test}
\begin{tikzpicture}[spy using outlines={magnification=4, size=2cm, connect spies}]
\node (first) {Initial text};
% simple approach fails:
\onslide <2->
\spy on (first) in node at (2,-2);
% this fails as well: https://tex.stackexchange.com/questions/88251/tikz-spy-and-beamer-uncover
% \only<2->{
% \spy[overlay] on (first) in node at (2,-2);
% }
% approach inspired by https://tex.stackexchange.com/questions/438218/beamer-uncover-magnification-using-tikz-spy-library
% fails as well
% \spy[visible on=<2->] on (first) in node at (2,-2);
% rewording as fails:
% \spy[connect on=<2->] on (first) in node[visible on=<2->] at (2,-2);
% spy does not seem to be overlay-aware, e.g. the following does not work
% \spy<2-> on (first) in node at (2,-2);
\onslide<3->
\node at (0,-4) (third) {Third text};
\onslide<4->
\node at (0,-6) (fourth) {Fourth text};
\end{tikzpicture}
\end{frame}
\end{document}
My expectation is to have the spy show up on the second slide, but it always only shows up on the last slide. MWE comprises the workarounds from the links above, but I do not see any difference in behaviour and cannot reproduce these solutions.
Any hints?
