@@ -21,10 +21,15 @@ export function useAposWidget(props) {
2121 } ;
2222
2323 async function renderContent ( ) {
24- rendered . value = await _renderContent ( props ) ;
25- nextTick ( ( ) => {
26- _emitWidgetRendered ( { aposLivePreview : props . aposLivePreview } ) ;
27- } ) ;
24+ const result = await _renderContent ( props ) ;
25+ if ( Object . hasOwn ( result , 'data' ) ) {
26+ rendered . value = result . data ;
27+ }
28+ if ( ! result . error ) {
29+ nextTick ( ( ) => {
30+ _emitWidgetRendered ( props . modelValue . aposLivePreview ) ;
31+ } ) ;
32+ }
2833 }
2934} ;
3035
@@ -56,31 +61,37 @@ export async function _renderContent(props) {
5661 } ;
5762 try {
5863 if ( props . rendering && ( isEqual ( props . rendering . parameters , parameters ) ) ) {
59- return props . rendering . html ;
64+ return { data : props . rendering . html } ;
6065 }
6166 // Don't use a placeholder here, it causes flickering in live preview
6267 // mode. It is better to display the old until we display the new, we
6368 // have "busy" for clarity
64- const result = await apos . http . post ( `${ apos . area . action } /render-widget?aposEdit=1&aposMode=${ props . mode } ` , {
65- busy : ! aposLivePreview ,
66- body : {
67- ...parameters ,
68- livePreview : aposLivePreview
69- }
70- } ) ;
69+ const result = await apos . http . post (
70+ `${ apos . area . action } /render-widget?aposEdit=1&aposMode=${ props . mode } ` ,
71+ {
72+ busy : ! aposLivePreview ,
73+ body : {
74+ ...parameters ,
75+ livePreview : aposLivePreview
76+ }
77+ } ) ;
7178 if ( result !== 'aposLivePreviewSchemaNotYetValid' ) {
72- return result ;
79+ return { data : result } ;
7380 }
81+ return { } ;
7482 } catch ( e ) {
7583 // eslint-disable-next-line no-console
7684 console . error ( 'Unable to render widget. Possibly the schema has been changed and the existing widget does not pass validation.' , e ) ;
77- return '<p>Unable to render this widget.</p>' ;
85+ return {
86+ data : '<p>Unable to render this widget.</p>' ,
87+ error : true
88+ } ;
7889 }
7990}
8091
8192// Wait for reactivity to render v-html so that markup is
8293// in the DOM before hinting that it might be time to prepare
8394// sub-area editors and run players (done in mixin and composable)
84- export function _emitWidgetRendered ( { aposLivePreview } ) {
95+ export function _emitWidgetRendered ( aposLivePreview ) {
8596 apos . bus . $emit ( 'widget-rendered' , { edit : ! aposLivePreview } ) ;
8697}
0 commit comments