You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to decide the best approach to introduce Front-end-as-a-Service (FEaaS) support into the SDK.
JSS leverages a React library called @sitecore-feaas/clientside/react. We need to decide whether to leverage the same library ourselves directly in the front-end or if we want to introduce our own middleware that has the same functionality included?
From my point of view, it is completely fine that the components are rendered clientside.
We have an initial version running, but there are some dependencies to how we are creating our frontend bundles and it we had to do a few weird serialization handling that is at least not the most pretty code I have written 😄
Component model to get values from layout response:
[ViewComponent(Name=ViewComponentName)]publicclassFEaaSWrapperViewComponent(IViewModelBinderbinder):ViewComponent{// This rendering is part of Foundation/Headless Services, so we have to stick with the namepublicconststringViewComponentName="FEaaSWrapper";privatestaticreadonlyJsonSerializerOptions_options=CreateOptions();publicasyncTask<IViewComponentResult>InvokeAsync(CancellationTokencancellationToken){varrenderingContext=HttpContext?.GetSitecoreRenderingContext();varmodel=awaitbinder.Bind<FEaaSComponentModel>(ViewContext).ConfigureAwait(false);if(renderingContext?.Component?.Fields?.Count>0){varcastedDictionary=renderingContext.Component.Fields.ToDictionary(x =>x.Key, x =>(JsonSerializedField)x.Value);vardataSource=awaitJsonSerializerWrapper.SerializeToStringAsync<IDictionary<string,JsonSerializedField>>(castedDictionary,_options,cancellationToken);model.DataSource=JsonDocument.Parse(dataSource);}returnView(model);}privatestaticJsonSerializerOptionsCreateOptions(){varoptions=newJsonSerializerOptions{DefaultIgnoreCondition=JsonIgnoreCondition.WhenWritingDefault,PropertyNamingPolicy=JsonNamingPolicy.CamelCase,};options.Converters.Add(newSerializedJsonFieldConverter());returnoptions;}publicclassSerializedJsonFieldConverter:JsonConverter<JsonSerializedField>{publicoverrideboolCanConvert(TypetypeToConvert)=>base.CanConvert(typeToConvert);publicoverrideJsonSerializedField?Read(refUtf8JsonReaderreader,TypetypeToConvert,JsonSerializerOptionsoptions)=>thrownewNotImplementedException();publicoverridevoidWrite(Utf8JsonWriterwriter,JsonSerializedFieldvalue,JsonSerializerOptionsoptions)=>writer.WriteRawValue(GetInnerValue(value.GetRawValue()));privatestringGetInnerValue(stringjson){conststringneedle1="{\"value\":";conststringneedle2="}";if(string.IsNullOrWhiteSpace(json)||!json.StartsWith(needle1)||!json.EndsWith(needle2)){returnjson;}returnjson.Substring(needle1.Length,json.Length-needle1.Length-needle2.Length);}}}
We have an implementation to render the model as json in a specific script tag and some javascript to instantiate a React component with those data as props.
We are lazy loading the bundle with the @sitecore-feaas/clientside bundle as it is quite significant so in our main bundle we have:
The SDK and xm-starter doesn't have any way to handle client-side code, and I actually like that, but I guess we can barely achieve this without something. Maybe just an example or skeleton on how to activate it and some recommended markup.
However, would this be enough to support XM Components? It seems to work, but it might be that there are functionality that we are not aware of (yet) that is missing.
Activity
jballe commentedon Oct 11, 2025
From my point of view, it is completely fine that the components are rendered clientside.
We have an initial version running, but there are some dependencies to how we are creating our frontend bundles and it we had to do a few weird serialization handling that is at least not the most pretty code I have written 😄
Component model to get values from layout response:
The View Component and deserialization
Our view:
We have an implementation to render the model as json in a specific script tag and some javascript to instantiate a React component with those data as props.
We are lazy loading the bundle with the
@sitecore-feaas/clientsidebundle as it is quite significant so in our main bundle we have:The SDK and xm-starter doesn't have any way to handle client-side code, and I actually like that, but I guess we can barely achieve this without something. Maybe just an example or skeleton on how to activate it and some recommended markup.
However, would this be enough to support XM Components? It seems to work, but it might be that there are functionality that we are not aware of (yet) that is missing.