@@ -387,13 +387,12 @@ export function isScrollProp<T extends UnPackedPageProps>(
387387 * Reads from the "metadata" key produced by AdonisJS transformers
388388 * rather than inspecting the raw paginator instance.
389389 */
390- function resolveScrollMetadata ( serialized : any , pageName : string , wrapper : string ) : ScrollMetadata {
390+ function resolveScrollMetadata ( serialized : any , pageName : string ) : ScrollMetadata {
391391 const meta = serialized ?. metadata ?? { }
392392 const currentPage : number | null = meta . currentPage ?? null
393393 const lastPage : number | null = meta . lastPage ?? null
394394 return {
395395 pageName,
396- wrapper,
397396 currentPage,
398397 nextPage :
399398 currentPage !== null && lastPage !== null && currentPage < lastPage ? currentPage + 1 : null ,
@@ -441,13 +440,16 @@ async function unpackPropValue(
441440 */
442441export async function buildStandardVisitProps (
443442 pageProps : PageProps ,
444- containerResolver : ContainerResolver < any >
443+ containerResolver : ContainerResolver < any > ,
444+ scrollMergeIntent ?: string
445445) {
446446 const mergeProps : string [ ] = [ ]
447447 const deepMergeProps : string [ ] = [ ]
448448 const newProps : ComponentProps = { }
449449 const deferredProps : { [ group : string ] : string [ ] } = { }
450+ const prependProps : string [ ] = [ ]
450451 const scrollProps : { [ key : string ] : ScrollMetadata } = { }
452+ const scrollResolvers = new Map < string , ( jsonValue : any ) => void > ( )
451453 const unpackedValues : Array < {
452454 key : string
453455 value : UnPackedPageProps | ( ( ) => AsyncOrSync < UnPackedPageProps > )
@@ -485,6 +487,16 @@ export async function buildStandardVisitProps(
485487 * so that scrollProps metadata can be derived after serialization.
486488 */
487489 if ( isScrollProp ( value ) ) {
490+ const scrollPath = `${ key } .${ value . wrapper } `
491+
492+ if ( scrollMergeIntent === 'prepend' ) {
493+ prependProps . push ( scrollPath )
494+ } else if ( scrollMergeIntent === 'append' ) {
495+ mergeProps . push ( scrollPath )
496+ }
497+ scrollResolvers . set ( key , ( jsonValue ) => {
498+ scrollProps [ key ] = resolveScrollMetadata ( jsonValue , value . pageName )
499+ } )
488500 unpackedValues . push ( { key, value : value . value } )
489501 continue
490502 }
@@ -551,27 +563,28 @@ export async function buildStandardVisitProps(
551563 . then ( ( r ) => unpackPropValue ( r , containerResolver ) )
552564 . then ( ( jsonValue ) => {
553565 newProps [ key ] = jsonValue
566+ if ( scrollResolvers . has ( key ) ) {
567+ scrollResolvers . get ( key ) ! ( jsonValue )
568+ }
554569 } )
555570 } else {
556571 return unpackPropValue ( value , containerResolver ) . then ( ( jsonValue ) => {
557572 newProps [ key ] = jsonValue
573+ if ( scrollResolvers . has ( key ) ) {
574+ scrollResolvers . get ( key ) ! ( jsonValue )
575+ }
558576 } )
559577 }
560578 } )
561579 )
562580
563- for ( const [ key , value ] of Object . entries ( pageProps ) ) {
564- if ( isObject ( value ) && isScrollProp ( value ) ) {
565- scrollProps [ key ] = resolveScrollMetadata ( newProps [ key ] , value . pageName , value . wrapper )
566- }
567- }
568-
569581 return {
570582 props : newProps ,
571583 mergeProps,
572584 deepMergeProps,
573585 deferredProps,
574586 scrollProps,
587+ prependProps,
575588 }
576589}
577590
@@ -602,11 +615,14 @@ export async function buildStandardVisitProps(
602615export async function buildPartialRequestProps (
603616 pageProps : PageProps ,
604617 cherryPickProps : string [ ] ,
605- containerResolver : ContainerResolver < any >
618+ containerResolver : ContainerResolver < any > ,
619+ scrollMergeIntent ?: string
606620) {
607621 const mergeProps : string [ ] = [ ]
608622 const deepMergeProps : string [ ] = [ ]
623+ const prependProps : string [ ] = [ ]
609624 const scrollProps : { [ key : string ] : ScrollMetadata } = { }
625+ const scrollResolvers = new Map < string , ( jsonValue : any ) => void > ( )
610626 const newProps : ComponentProps = { }
611627 const unpackedValues : Array < {
612628 key : string
@@ -651,6 +667,16 @@ export async function buildPartialRequestProps(
651667 * Unpack scroll prop value and track pageName for metadata derivation
652668 */
653669 if ( isScrollProp ( value ) ) {
670+ const scrollPath = `${ key } .${ value . wrapper } `
671+
672+ if ( scrollMergeIntent === 'prepend' ) {
673+ prependProps . push ( scrollPath )
674+ } else if ( scrollMergeIntent === 'append' ) {
675+ mergeProps . push ( scrollPath )
676+ }
677+ scrollResolvers . set ( key , ( jsonValue ) => {
678+ scrollProps [ key ] = resolveScrollMetadata ( jsonValue , value . pageName )
679+ } )
654680 unpackedValues . push ( { key, value : value . value } )
655681 continue
656682 }
@@ -708,26 +734,27 @@ export async function buildPartialRequestProps(
708734 . then ( ( r ) => unpackPropValue ( r , containerResolver ) )
709735 . then ( ( jsonValue ) => {
710736 newProps [ key ] = jsonValue
737+ if ( scrollResolvers . has ( key ) ) {
738+ scrollResolvers . get ( key ) ! ( jsonValue )
739+ }
711740 } )
712741 } else {
713742 return unpackPropValue ( value , containerResolver ) . then ( ( jsonValue ) => {
714743 newProps [ key ] = jsonValue
744+ if ( scrollResolvers . has ( key ) ) {
745+ scrollResolvers . get ( key ) ! ( jsonValue )
746+ }
715747 } )
716748 }
717749 } )
718750 )
719751
720- for ( const [ key , value ] of Object . entries ( pageProps ) ) {
721- if ( isObject ( value ) && isScrollProp ( value ) ) {
722- scrollProps [ key ] = resolveScrollMetadata ( newProps [ key ] , value . pageName , value . wrapper )
723- }
724- }
725-
726752 return {
727753 props : newProps ,
728754 mergeProps,
729755 deepMergeProps,
730756 deferredProps : { } ,
731757 scrollProps,
758+ prependProps,
732759 }
733760}
0 commit comments