Skip to content

Commit

Permalink
fix: check for null layoutItems/layoutItem and break out of foreach o…
Browse files Browse the repository at this point in the history
…nce a valid item has been found
  • Loading branch information
kevin9092 committed Sep 26, 2024
1 parent 48cc161 commit ff8ed7e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ public async Task<string> RenderGridBlock(
List<string>? layoutItems = blockData?.Layout?.FirstOrDefault().Value.Select(layout => layout.ToString()).ToList();
BlockGridLayoutItem? layoutItem = null;

foreach (var layoutItemJson in layoutItems)
if (layoutItems != null)
{
layoutItem = JsonConvert.DeserializeObject<BlockGridLayoutItem>(layoutItemJson);
if (layoutItem != null)
foreach (var layoutItemJson in layoutItems)
{
layoutItem = JsonConvert.DeserializeObject<BlockGridLayoutItem>(layoutItemJson);
if (layoutItem == null) continue;

if (layoutItem.ContentUdi == blockInstance.ContentUdi)
{
blockInstance.RowSpan = layoutItem.RowSpan!.Value;
Expand All @@ -127,6 +129,7 @@ public async Task<string> RenderGridBlock(
if (item.ContentUdi != blockInstance.ContentUdi) continue;
blockInstance.RowSpan = item.RowSpan!.Value;
blockInstance.ColumnSpan = item.ColumnSpan!.Value;
break;
}
}
}
Expand Down

0 comments on commit ff8ed7e

Please sign in to comment.