@@ -794,26 +794,77 @@ const ReactBabylonJSHostConfig: HostConfig<
794
794
}
795
795
} ,
796
796
797
+ /* uploadPayload is removed from commitUpdate in new version
798
+ https://www.npmjs.com/package/react-reconciler
799
+ but type definitions doesn't seem to be updated. */
800
+ // @ts -expect-error types are not updated
797
801
commitUpdate (
798
802
instance : HostCreatedInstance < any > ,
799
- updatePayload : UpdatePayload ,
800
- type : string /* old, new props and instance handle are extra ignored params */
803
+ type : string ,
804
+ prevProps : Record < string , any > ,
805
+ nextProps : Record < string , any >
801
806
) {
802
- if ( updatePayload !== null && ! ! type ) {
803
- if ( Array . isArray ( updatePayload ) ) {
804
- updatePayload . forEach ( ( update : PropertyUpdate ) => {
805
- if ( instance && update ) {
806
- applyUpdateToInstance ( instance , update )
807
- } else {
808
- // console.warn("skipped applying update to missing instance...", update, type);
809
- }
810
- } )
811
- } else {
812
- if ( instance ) {
813
- applyUpdateToInstance ( instance , updatePayload )
807
+ const updatePayload : PropertyUpdate [ ] = [ ]
808
+
809
+ const allKeys : string [ ] = [ ]
810
+ const keyMap : Record < string , boolean > = { }
811
+
812
+ for ( const key in prevProps ) {
813
+ if ( ! keyMap [ key ] ) {
814
+ allKeys . push ( key )
815
+ keyMap [ key ] = true
816
+ }
817
+ }
818
+
819
+ for ( const key in nextProps ) {
820
+ if ( ! keyMap [ key ] ) {
821
+ allKeys . push ( key )
822
+ keyMap [ key ] = true
823
+ }
824
+ }
825
+
826
+ for ( const key of allKeys ) {
827
+ // Skip internal React properties (starts with '__')
828
+ if ( key . startsWith ( '__' ) ) continue
829
+
830
+ const prevValue = prevProps [ key ]
831
+ const nextValue = nextProps [ key ]
832
+
833
+ if ( prevValue !== nextValue ) {
834
+ let changeType : PropChangeType
835
+
836
+ if (
837
+ typeof nextValue === 'number' ||
838
+ typeof nextValue === 'string' ||
839
+ typeof nextValue === 'boolean' ||
840
+ nextValue === null ||
841
+ nextValue === undefined
842
+ ) {
843
+ changeType = PropChangeType . Primitive
844
+ } else if ( Array . isArray ( nextValue ) && nextValue . every ( ( v ) => typeof v === 'number' ) ) {
845
+ changeType = PropChangeType . NumericArray
846
+ } else {
847
+ changeType = PropChangeType . Primitive
814
848
}
849
+
850
+ updatePayload . push ( {
851
+ propertyName : key ,
852
+ value : nextValue ,
853
+ changeType,
854
+ isSetAccessor : false ,
855
+ target : undefined ,
856
+ } )
815
857
}
816
858
}
859
+
860
+ // Apply updates using your existing logic
861
+ if ( updatePayload . length > 0 && ! ! type ) {
862
+ updatePayload . forEach ( ( update : PropertyUpdate ) => {
863
+ if ( instance && update ) {
864
+ applyUpdateToInstance ( instance , update )
865
+ }
866
+ } )
867
+ }
817
868
} ,
818
869
819
870
removeChildFromContainer : ( container : Container , child : HostCreatedInstance < any > ) => {
0 commit comments