11import {
22 KIND_TEXT as LEGACY_KIND_TEXT ,
3+ KIND_COMPONENT as LEGACY_KIND_COMPONENT ,
34 KIND_FRAGMENT as LEGACY_KIND_FRAGMENT ,
45 ACTION_MOUNT as LEGACY_ACTION_MOUNT ,
56 ACTION_INSERT_CHILD as LEGACY_ACTION_INSERT_CHILD ,
@@ -16,6 +17,7 @@ import {
1617import {
1718 ROOT_ID ,
1819 NODE_TYPE_TEXT ,
20+ NODE_TYPE_COMMENT ,
1921 NODE_TYPE_ELEMENT ,
2022 MUTATION_TYPE_INSERT_CHILD ,
2123 MUTATION_TYPE_REMOVE_CHILD ,
@@ -26,6 +28,7 @@ import {
2628 type RemoteElementSerialization ,
2729 type RemoteConnection ,
2830 type RemoteNodeSerialization ,
31+ type RemoteCommentSerialization ,
2932} from '@remote-dom/core' ;
3033
3134export interface LegacyRemoteChannelElementMap {
@@ -233,7 +236,7 @@ export function adaptToLegacyRemoteChannel(
233236 records . push ( [
234237 MUTATION_TYPE_INSERT_CHILD ,
235238 id ,
236- adaptLegacyFragmentSerialization ( key , value , options ) ,
239+ adaptLegacyPropFragmentSerialization ( key , value , options ) ,
237240 tree . get ( id ) ?. length ?? 0 ,
238241 ] satisfies RemoteMutationRecord ) ;
239242 } else {
@@ -266,13 +269,26 @@ export function adaptToLegacyRemoteChannel(
266269}
267270
268271function adaptLegacyNodeSerialization (
269- child : LegacyRemoteComponentSerialization | LegacyRemoteTextSerialization ,
272+ child :
273+ | LegacyRemoteComponentSerialization
274+ | LegacyRemoteTextSerialization
275+ | LegacyRemoteFragmentSerialization ,
270276 options ?: LegacyRemoteChannelOptions ,
271- ) : RemoteElementSerialization | RemoteTextSerialization {
272- if ( child . kind === LEGACY_KIND_TEXT ) {
273- return adaptLegacyTextSerialization ( child ) ;
274- } else {
275- return adaptLegacyComponentSerialization ( child , options ) ;
277+ ) :
278+ | RemoteElementSerialization
279+ | RemoteTextSerialization
280+ | RemoteCommentSerialization {
281+ switch ( child . kind ) {
282+ case LEGACY_KIND_TEXT :
283+ return adaptLegacyTextSerialization ( child ) ;
284+ case LEGACY_KIND_COMPONENT :
285+ return adaptLegacyComponentSerialization ( child , options ) ;
286+ default :
287+ return {
288+ id : child . id ,
289+ type : NODE_TYPE_COMMENT ,
290+ data : 'added by remote-ui legacy adaptor to replace a fragment rendered as a child' ,
291+ } ;
276292 }
277293}
278294
@@ -343,11 +359,11 @@ function adaptLegacyFragmentsSerialization(
343359 options ?: LegacyRemoteChannelOptions ,
344360) : RemoteElementSerialization [ ] {
345361 return Object . entries ( fragments ) . map ( ( [ slot , fragment ] ) => {
346- return adaptLegacyFragmentSerialization ( slot , fragment , options ) ;
362+ return adaptLegacyPropFragmentSerialization ( slot , fragment , options ) ;
347363 } ) ;
348364}
349365
350- function adaptLegacyFragmentSerialization (
366+ function adaptLegacyPropFragmentSerialization (
351367 slot : string ,
352368 fragment : LegacyRemoteFragmentSerialization ,
353369 options ?: LegacyRemoteChannelOptions ,
0 commit comments