@@ -2096,6 +2096,7 @@ function renderModelDestructive(
2096
2096
if ( typeof value === 'object' ) {
2097
2097
switch ( ( value : any ) . $$typeof ) {
2098
2098
case REACT_ELEMENT_TYPE : {
2099
+ let elementReference = null ;
2099
2100
const writtenObjects = request . writtenObjects ;
2100
2101
if ( task . keyPath !== null || task . implicitSlot ) {
2101
2102
// If we're in some kind of context we can't reuse the result of this render or
@@ -2124,10 +2125,8 @@ function renderModelDestructive(
2124
2125
if ( parentReference !== undefined ) {
2125
2126
// If the parent has a reference, we can refer to this object indirectly
2126
2127
// through the property name inside that parent.
2127
- writtenObjects . set (
2128
- value ,
2129
- parentReference + ':' + parentPropertyName ,
2130
- ) ;
2128
+ elementReference = parentReference + ':' + parentPropertyName ;
2129
+ writtenObjects . set ( value , elementReference ) ;
2131
2130
}
2132
2131
}
2133
2132
}
@@ -2162,7 +2161,7 @@ function renderModelDestructive(
2162
2161
}
2163
2162
2164
2163
// Attempt to render the Server Component.
2165
- return renderElement (
2164
+ const newChild = renderElement (
2166
2165
request ,
2167
2166
task ,
2168
2167
element . type ,
@@ -2178,6 +2177,18 @@ function renderModelDestructive(
2178
2177
: null ,
2179
2178
__DEV__ && enableOwnerStacks ? element . _store . validated : 0 ,
2180
2179
) ;
2180
+ if (
2181
+ typeof newChild === 'object' &&
2182
+ newChild !== null &&
2183
+ elementReference !== null
2184
+ ) {
2185
+ // If this element renders another object, we can now refer to that object through
2186
+ // the same location as this element.
2187
+ if ( ! writtenObjects . has ( newChild ) ) {
2188
+ writtenObjects . set ( newChild , elementReference ) ;
2189
+ }
2190
+ }
2191
+ return newChild ;
2181
2192
}
2182
2193
case REACT_LAZY_TYPE : {
2183
2194
// Reset the task's thenable state before continuing. If there was one, it was
0 commit comments