Skip to content

Instantly share code, notes, and snippets.

@damsleth
Last active October 11, 2023 11:56
Show Gist options
  • Save damsleth/fba9b67318c1a966fdca67d32f0a7543 to your computer and use it in GitHub Desktop.
Save damsleth/fba9b67318c1a966fdca67d32f0a7543 to your computer and use it in GitHub Desktop.
Patch for SharePoint Server Subscription Edition 23H2 CU, sp-pages-assembly
<#
.SYNOPSIS
This script patches a recursion bug in the file 'sp-pages-assembly.js', in the 23H2 release of SharePoint Subscription Edition.
.COMPONENT
SharePoint Server Subscription Edition 23H2
.NOTES
This script is provided as-is, without any warranty or support what so ever.
It is not supported by Microsoft, and is provided as a courtesy to the community.
Use at your own risk.
.DESCRIPTION
This patch fixes a recursion bug in the spLoadTheme and createTheme functions in sp-pages-assembly.js,
a file found in C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\TEMPLATE\LAYOUTS\Next\spclient\[locale]\
This bug causes cross site navigation on sites with themes applied to trigger a Maximum Call Stack Size Exceeded error,
making cross site navigation extremely slow.
RUN THIS SCRIPT ON ALL WEB FRONT ENDS IN YOUR FARM, AFTER INSTALLING THE 23H2 UPDATE.
C:\PS> Patch-SpPagesAssembly.ps1 -DryRun:$false
Bug reported by @havardberg on 30.09.2023.
Patch by @damsleth on 04.10.2023
STEPS THIS SCRIPT PERFORMS:
cd to C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\TEMPLATE\LAYOUTS\Next\spclient\
finds all js-files with name sp-pages-assembly in all subfolders, e.g. \nb-no, \en-us, \default
foreach file,
backs up the sp-pages-assembly file to a file with the same name but with .bak appended
replaces the following text:
'!!e.disableGlobalClassNames}'
with the following (these are default values also found elsewhere in sp-pages-assembly.js)
'!!e.disableGlobalClassNames, effects:e.effects || {
elevation4:"005px0rgba(0,0,0,.4)",
elevation8:"005px0rgba(0,0,0,.4)",
elevation16:"005px0rgba(0,0,0,.4)",
elevation64:"005px0rgba(0,0,0,.4)",
roundedCorner2:"0px"
},
spacing:e.spacing || {l1:"20px",l2:"32px",m:"16px",s1:"8px",s2:"4px"}}'.
If the file was patched and -DryRun is $false, the file is saved.
THIS PATCH IS NOT SUPPORTED BY MICROSOFT, AND IS PROVIDED AS-IS, WITHOUT ANY WARRANTY OR SUPPORT WHAT SO EVER.
DO NOT RUN POWERSHELL SCRIPTS ON YOUR PRODUCTION SYSTEMS WITHOUT TESTING THEM FIRST.
.PARAMETER DryRun
Whether to actually patch the files or just list the files that would be patched
.EXAMPLE
C:\PS> .\Patch-SpPagesAssembly.ps1 -DryRun:$false
.NOTES
Author: Carl Joakim Damsleth (github.com/damsleth)
Date: October 4, 2023
.LINK
Bug reports: https://learn.microsoft.com/en-us/answers/questions/1373533/sharepoint-server-subscription-changing-look-and-f
This gist: https://gist.github.com/damsleth/fba9b67318c1a966fdca67d32f0a7543
#>
Param(
[Parameter(Mandatory = $false, HelpMessage = "Whether to actually patch the files or just list the files that would be patched")]
[boolean]$dryrun = $true
)
$searchTxt = '!!e.disableGlobalClassNames}'
$replaceTxt = '!!e.disableGlobalClassNames,effects:e.effects||{elevation4:"005px0rgba(0,0,0,.4)",elevation8:"005px0rgba(0,0,0,.4)",elevation16:"005px0rgba(0,0,0,.4)",elevation64:"005px0rgba(0,0,0,.4)",roundedCorner2:"0px"},spacing:e.spacing||{l1:"20px",l2:"32px",m:"16px",s1:"8px",s2:"4px"}}'
$spClientFolder = "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\TEMPLATE\LAYOUTS\Next\spclient"
if ($(Get-Location).Path -ne $spClientFolder) {
Write-Warning "`nChanging directory to`n$spClientFolder"
Set-Location -Path $spClientFolder
}
$files = Get-ChildItem -Path .\*\sp-pages-assembly.js -Recurse
$i = $fixed = 0
if ($dryrun) { Write-Warning "`nDry run only, not patching anything.`nRerun with -dryrun `$false to patch files`n`n" }
$files | ForEach-Object {
$i++
Write-Host "`n$i/$($files.count) Processing '$($_.Directory.Name+"\"+$_.Name)'"
$file = Get-Content $_.FullName
if ([regex]::Match($file, $searchTxt).Success) {
Write-Host "File is unpatched"
if (!$dryrun) {
Write-Host "Backing up '$($_.Directory.Name+"\"+$_.Name)' to '$($_.Directory.Name+"\"+$_.Name).bak'"
Copy-Item $_.FullName "$($_.FullName).bak"
Write-Host "Patching $($_.FullName)"
$file -replace $searchTxt, $replaceTxt | Set-Content $_.FullName
}
else {
Write-Host "Dryrun only, not backing up or patching '$($_.Directory.Name+"\"+$_.Name)'"
}
$fixed++
}
else {
Write-Host "File '$($_.Directory.Name+"\"+$_.Name)' looks like it's already patched, skipping"
}
}
if ($dryrun) { Write-Host "`n`nDry run finished, $fixed of $i sp-pages-assembly.js files found would have been patched" }
else { Write-Host "`nDone patching $fixed of $i sp-pages-assembly.js files" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment