Skip to content

Commit bb2a9f9

Browse files
<sc-editingscripts /> nullreference (#56)
<!-- Provide a general summary of your changes in the Title above --> <!-- Apply the label "bug" or "enhancement" as applicable. --> ## Description / Motivation <!-- Describe your changes in detail --> + Removed throwing an error and rendering nothing instead for <sc-editingscripts /> when no ISitecoreRenderingContext is available <!-- Why is this change required? What problem does it solve? --> In case of Experience Edge unavailability the ISitecoreRenderingContext might be empty, there is no reason to throw an exception and crash the page from rendering. This tag is often used in a main layout (like it was on MVP Website) which is also used when rendering error pages without a Sitecore context. Having this tag helper on the page causes issues in such case while it's perfectly acceptable to have an empty result. <!-- If it fixes an open issue, please link to the issue here. --> ## Testing - [X] The Unit & Intergration tests are passing. - [X] I have added the necessary tests to cover my changes. ## Terms <!-- Place an X in the [] to check. --> <!-- The Code of Conduct helps create a safe space for everyone. We require that everyone agrees to it. --> - [X] I agree to follow this project's [Code of Conduct](CODE_OF_CONDUCT.md). --------- Co-authored-by: Ivan Lieckens <ivanlieckens@hotmail.com>
1 parent 4270bbf commit bb2a9f9

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/Sitecore.AspNetCore.SDK.Pages/TagHelpers/EditingScriptsTagHelper.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ public class EditingScriptsTagHelper : TagHelper
2525
/// <inheritdoc />
2626
public override void Process(TagHelperContext context, TagHelperOutput output)
2727
{
28-
ISitecoreRenderingContext renderingContext = ViewContext?.HttpContext.GetSitecoreRenderingContext() ??
29-
throw new NullReferenceException(Resources.Exception_EditingScriptsTagHelperSitecoreRenderingContextNull);
28+
ISitecoreRenderingContext? renderingContext = ViewContext?.HttpContext.GetSitecoreRenderingContext();
3029

3130
output.TagName = string.Empty;
3231
string html = string.Empty;
3332

34-
if (renderingContext.Response?.Content?.Sitecore?.Context?.IsEditing ?? false)
33+
if (renderingContext?.Response?.Content?.Sitecore?.Context?.IsEditing ?? false)
3534
{
3635
EditingContext? editingContext = JsonSerializer.Deserialize<EditingContext>(renderingContext.Response?.Content.ContextRawData ?? string.Empty);
3736
if (editingContext == null)

tests/Sitecore.AspNetCore.SDK.Pages.Tests/TagHelpers/EditingScriptsTagHelperFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void Ctor_InvalidArgs_Throws(GuardClauseAssertion guard)
5454

5555
[Theory]
5656
[AutoNSubstituteData]
57-
public async Task ProcessAsync_NoSitecoreContenxt_ExceptionIsThrown(EditingScriptsTagHelper sut, TagHelperContext tagHelperContext, TagHelperOutput tagHelperOutput)
57+
public async Task ProcessAsync_NoSitecoreContext_EmptyResult(EditingScriptsTagHelper sut, TagHelperContext tagHelperContext, TagHelperOutput tagHelperOutput)
5858
{
5959
// Arrange
6060
ViewContext viewContext = new()
@@ -66,10 +66,10 @@ public async Task ProcessAsync_NoSitecoreContenxt_ExceptionIsThrown(EditingScrip
6666
sut.ViewContext = viewContext;
6767

6868
// Act
69-
Func<Task> act = async () => await sut.ProcessAsync(tagHelperContext, tagHelperOutput);
69+
await sut.ProcessAsync(tagHelperContext, tagHelperOutput);
7070

7171
// Assert
72-
await act.Should().ThrowAsync<NullReferenceException>();
72+
tagHelperOutput.Content.GetContent().Should().BeEmpty();
7373
}
7474

7575
[Theory]

0 commit comments

Comments
 (0)