skttl / umbraco-block-type-custom-view-previewer

Who knows?
MIT License
7 stars 6 forks source link

Can't update preview on block update #1

Open skttl opened 4 years ago

skttl commented 4 years ago

Getting

angular.js?cdv=4:15635 TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'ChildScope'
    |     property '$$childTail' -> object with constructor 'Scope'
    --- property '$parent' closes the circle
    at JSON.stringify (<anonymous>)
    at ChildScope.$scope.setPreview (BlockTypeGridViewPreviewController.js?cdv=4:38)
    at BlockTypeGridViewPreviewController.js?cdv=4:54
    at Scope.$digest (angular.js?cdv=4:19208)
    at ChildScope.$apply (angular.js?cdv=4:19568)
    at HTMLButtonElement.<anonymous> (angular.js?cdv=4:29023)
    at HTMLButtonElement.dispatch (jquery.min.js?cdv=4:2)
    at HTMLButtonElement.v.handle (jquery.min.js?cdv=4:2)

when updating an existing block.

It comes from this line https://github.com/skttl/umbraco-block-type-custom-view-previewer/blob/master/src/Our.Umbraco.BlockTypeGridViewPreview/App_Plugins/Our.Umbraco.BlockTypeGridViewPreview/BlockTypeGridViewPreviewController.js#L38 where I try to send the block data to the backend controller responsible for rendering the preview.

Don't know how to fix - any help appreciated :)

gerbenvd commented 3 years ago

We actually got this working, and didn't encounter this error at all. It just works :-) Perhaps you can provide some more information about your block ( data / settings) configuration (e..g specific data types) so we will able to reproduce.

skttl commented 3 years ago

Ah yes, I can see it works with "simple" blocks.

I have a block list inside my block, and it must be that one that makes the circular error :)

gerbenvd commented 3 years ago

Yes, that must be it! Good to know this is a known limitation. Nested block lists might be a common scenario.

ault commented 2 years ago

Triple nesting in our case. (Layout areas, sections, content blocks)

enkelmedia commented 2 years ago

Figured I'll share some insights here. We have been using this in a project that we're working on. I've made some major changes to both the C# code and the controller - thank you very much for the inspiration @skttl

I ran into this particular issue when using a block editor inside on of the "blocks".

Turns out that "angular.copy" will strip all "angularjs"-stuff from the object (variables starting with $).

Something like:

var valueCopy = angular.copy(value);
var reqModel = {
  ....
  value: JSON.stringify(valueCopy)
}

I'm more than happy to share our "stuff" if someone wants to look at it, not sure if a PR is the way to go but please let me know.

skttl commented 2 years ago

I'm more than happy to share our "stuff" if someone wants to look at it, not sure if a PR is the way to go but please let me know.

Forking would be better!