diff --git a/implement/Pine.Core/ReusedInstances.cs b/implement/Pine.Core/ReusedInstances.cs index d729596c..607c5b37 100644 --- a/implement/Pine.Core/ReusedInstances.cs +++ b/implement/Pine.Core/ReusedInstances.cs @@ -343,9 +343,15 @@ [.. elmRecord.Fields.Select(kvp => (kvp.FieldName, reusedInstances[kvp.Value]))] { var encodedDict = new Dictionary(); - foreach (var item in ElmValues) + var elmValuesSorted = + ElmValues + .OrderBy(ev => ev.ContainedNodesCount) + .ToList(); + + foreach (var item in elmValuesSorted) { - encodedDict[item] = ElmInteractive.ElmValueEncoding.ElmValueAsPineValue(item); + encodedDict[item] = + ElmInteractive.ElmValueEncoding.ElmValueAsPineValue(item, encodedDict); } ElmValueEncoding =