Skip to content

Fix: section type detection for vertical sections with non-standard c…#1757

Open
nicolaor wants to merge 1 commit into
pnp:devfrom
MondayCoffee:1756_Pages_VerticalSectionTypeDetection
Open

Fix: section type detection for vertical sections with non-standard c…#1757
nicolaor wants to merge 1 commit into
pnp:devfrom
MondayCoffee:1756_Pages_VerticalSectionTypeDetection

Conversation

@nicolaor
Copy link
Copy Markdown
Contributor

Fix: Pages — Vertical section type detection uses wrong column for ColumnFactor check #1756

Summary

Fixes a bug where pages with vertical section layouts (TwoColumnRightVerticalSection, TwoColumnLeftVerticalSection, TwoColumnVerticalSection) are misclassified as OneColumn during page loading. This causes ArgumentOutOfRangeException during PnP provisioning when controls reference columns that don't exist in the incorrectly-typed section.

Problem

In Page.cs, the section type detection for 3-column sections with a vertical section column uses section.Columns[0].ColumnFactor to determine the layout type. However, the Columns list order is determined by HTML parsing of the page content, and the vertical section column (layoutIndex=2, columnFactor=12) can appear at index 0 if its controls are rendered first in the HTML.

When Columns[0] is the vertical column (columnFactor=12), all the if/else if checks for factors 6, 4, and 8 fail, leaving the section type at the default OneColumn.

Fix

Changed the detection to filter out the vertical section column (layoutIndex=2) before checking ColumnFactor:

 else if (section.Columns.Count == 3)
 {
-    if (section.Columns[0].ColumnFactor == 6)
+    // Use the first non-vertical-section column for type detection,
+    // as the vertical column (layoutIndex=2) may appear first in the list
+    var firstMainColumn = section.Columns
+        .Where(c => c.LayoutIndex != 2)
+        .OrderBy(c => c.Order)
+        .FirstOrDefault();
+    var mainColumnFactor = firstMainColumn?.ColumnFactor ?? 0;
+
+    if (mainColumnFactor == 6)
     {
         section.Type = CanvasSectionTemplate.TwoColumnVerticalSection;
     }
-    else if (section.Columns[0].ColumnFactor == 4)
+    else if (mainColumnFactor == 4)
     {
         section.Type = CanvasSectionTemplate.TwoColumnRightVerticalSection;
     }
-    else if (section.Columns[0].ColumnFactor == 8)
+    else if (mainColumnFactor == 8)
     {
         section.Type = CanvasSectionTemplate.TwoColumnLeftVerticalSection;
     }
 }

File changed

  • src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs — Section type detection in the page loading logic (around line 1488)

Testing

  • Verified with the Employee-onboarding-team-home.aspx page from the standard SharePoint Employee onboarding team site template, which uses a TwoColumnRightVerticalSection layout
  • Before fix: Section exported as Type="OneColumn", provisioning crashed with ArgumentOutOfRangeException
  • After fix: Section correctly exported as Type="TwoColumnRightVerticalSection", provisioning succeeds

Related

  • There is a companion fix in pnp/pnpframework for the column index mapping of vertical section controls during template export

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.25%. Comparing base (63545f3) to head (4037a54).
⚠️ Report is 2907 commits behind head on dev.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1757      +/-   ##
==========================================
- Coverage   82.42%   81.25%   -1.17%     
==========================================
  Files         416      637     +221     
  Lines       28590    45388   +16798     
  Branches        0     4778    +4778     
==========================================
+ Hits        23565    36880   +13315     
- Misses       5025     7099    +2074     
- Partials        0     1409    +1409     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Adam-it
Copy link
Copy Markdown
Member

Adam-it commented Apr 16, 2026

Thanks for opening a PR. We will try to process it ASAP 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pages: Section type detection fails for vertical section layouts (TwoColumnRightVerticalSection detected as OneColumn)

4 participants