Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mario 80 posts 568 karma points c-trib
    Mar 22, 2019 @ 05:49
    Mario
    0

    Error previewing Stacked Content

    I have this data property in an entity used by Fluidity that is saved as Json in the database. The Json comes from a Stacked Content editor that I have configured for that data property. When I add my content to the stacked content, the previews work fine, but when I save and reload the entity (in Fluidity), the previews fail with:

    {
        "message": "An error has occurred.",
        "exceptionMessage": "Value cannot be null.\r\nParameter name: content",
        "exceptionType": "System.ArgumentNullException",
        "stackTrace": "   at Umbraco.Core.Mandate.That[TException](Boolean condition, Func`1 defer)\r\n   at Umbraco.Core.Mandate.ParameterNotNull[T](T value, String paramName)\r\n   at Our.Umbraco.StackedContent.Models.UnpublishedContent..ctor(IContent content, ServiceContext serviceContext)\r\n   at Our.Umbraco.StackedContent.Web.Controllers.StackedContentApiController.GetPreviewMarkup(JObject item, Int32 pageId)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    }
    

    If I disable the preview option everything works fine and all the data in the stacked content objects is populated correctly.

    Any idea what might be wrong with those previews?

    thank you.

  • Lee Kelleher 3866 posts 14527 karma points MVP 9x admin c-trib
    Mar 25, 2019 @ 10:52
    Lee Kelleher
    0

    Hi Mario,

    The error is throw because the preview mechanism was designed to work on content pages/nodes. The PreviewModel we use has a properties for both the current Page (whether published or unpublished) and the Item which is the Stacked Content block itself.

    The reason for this is to support scenarios with rendering RTEs and Macros, they rely on the current page object/value.

    I'm sure a tweak could be made in the preview's controller to detect whether the request is coming from the content section or not, (and that you don't need to render RTEs or Macros).

    Looking at the call to the GetPreviewMarkup method, the pageId must be being populated with a positive value. I'm not sure what Fluidity is setting for the editorState.current.id. (Side note, Fluidity is Matt's project, I haven't coded on it, not sure about the inner workings).

    Key points in code to look at, (if you - or anyone else - is interested in coding it?), are here...

    https://github.com/umco/umbraco-stacked-content/blob/develop/src/Our.Umbraco.StackedContent/Web/UI/App_Plugins/StackedContent/js/stackedcontent.js#L103

    https://github.com/umco/umbraco-stacked-content/blob/develop/src/Our.Umbraco.StackedContent/Web/Controllers/StackedContentApiController.cs#L31

    Cheers,
    - Lee

  • Mario 80 posts 568 karma points c-trib
    Mar 25, 2019 @ 22:30
    Mario
    100

    Hi Lee,

    Thanks for all this information. It looks like Fluidity uses some fake ids like 1,2,3, ... and that's being passed as pageId to SC.

    We have ended up 'hacking' the stacked content javascript service to override getPreviewMarkup. The code is actually a copy of Fluidity code with a bit of tweaking, but it works :)

    (function () {
        'use strict';
        // Umbraco resource overrides
        function formBuilderStackedContentResourceOverrides($provide) {
    
            $provide.decorator('Our.Umbraco.StackedContent.Resources.StackedContentResources', function ($delegate) {
    
                var isFluidity = window.location.href.indexOf('!') > 0;
    
                var oldGetPreviewMarkup = $delegate.getPreviewMarkup;
                $delegate.getPreviewMarkup = function () {
                    if (arguments.length >= 2 && isFluidity) { // '!' signifies a fluidity composite id
                        arguments[1] = -1;
                    }
                    return oldGetPreviewMarkup.apply($delegate, arguments);
                };
    
                return $delegate;
    
            });
    
        }
        angular.module("umbraco.resources").config(['$provide', formBuilderStackedContentResourceOverrides]);
    
    })();
    
Please Sign in or register to post replies

Write your reply to:

Draft