Different behavior of matrix with node defined explicitly with delimeters versus matrix of nodes

While I was trying to answer another question I found out that matrix of nodes gives the error: ! TeX capacity exceeded, sorry [grouping levels=255]. when the nodes have delimiters.

It doesn't happen whit a matrix with nodes defined explicitly:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\tikzset{
mynode/.style={
left delimiter=(,
right delimiter=),
text width=1cm
}
}
\begin{document}
Why this works:

\begin{tikzpicture}
\matrix{
\node[mynode] {long text 1};&
\node[mynode] {long text 2};\\
};
\end{tikzpicture}

whereas this one gives \texttt{! TeX capacity exceeded, sorry [grouping levels=255].}:

\begin{tikzpicture}
\matrix[matrix of nodes, nodes={mynode}]{
long text 1 &
long text 2 \\
};
\end{tikzpicture}

?
\end{document}

Please note that I would like the second matrix of my example gives the same result as the first, with the delimiters around every cell, not around the whole matrix.

The problem is that in general you can't add left delimiter or right right delimiter in every node style because internally the delimiters add a node, so this create an infinite loop. You can check this in this simple example that throws also ! TeX capacity exceeded, sorry [grouping levels=255].

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[every node/.style={left delimiter=(}]
\node {Some text here};
\end{tikzpicture}
\end{document}

To overcome this you can hack the (or submit a bug request) \tikz@delimiter by resetting every node style before the internal node creation, like this :

\def\tikz@delimiter#1#2#3#4#5#6#7#8{%
\bgroup
\pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name\tikzset{every node/.style={}}}% <-- added reset every node style
node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3]
{%
{\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}%
$\left#6\vcenter{\hrule height .5#8 depth .5#8 width0pt}\right#7$%
}
\pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}%
\egroup%
}

So there is no more error in my first code :

\def\tikz@delimiter#1#2#3#4#5#6#7#8{%
\bgroup
\pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name\tikzset{every node/.style={}}}% <-- added reset every node style
node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3]
{%
{\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}%
$\left#6\vcenter{\hrule height .5#8 depth .5#8 width0pt}\right#7$%
}
\pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}%
\egroup%
}
\makeatother
\begin{document}
\begin{tikzpicture}[every node/.style={left delimiter=(}]
\node {Some text here};
\end{tikzpicture}
\end{document}

And so your code works too.

%
\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{matrix}
\makeatletter
\def\tikz@delimiter#1#2#3#4#5#6#7#8{%
\bgroup
\pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name\tikzset{every node/.style={}}}% <-- added reset every node style
node[outer sep=0pt,inner sep=0pt,draw=none,fill=none,anchor=#1,at=(\tikz@last@fig@name.#2),#3]
{%
{\nullfont\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@last@fig@name}{#4}}{\pgfpointanchor{\tikz@last@fig@name}{#5}}}}%
$\left#6\vcenter{\hrule height .5#8 depth .5#8 width0pt}\right#7$%
}
\pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}%
\egroup%
}
\makeatother

\tikzset{
mynode/.style={
left delimiter=(,
right delimiter=),
text width=1cm
}
}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes, nodes={mynode}]{
long text 1 &
long text 2 \\
};
\end{tikzpicture}
\end{document}