@@ -48,6 +48,7 @@ type Props = {
48
48
type Instance = { |
49
49
type : string ,
50
50
id : number ,
51
+ parent : number ,
51
52
children : Array < Instance | TextInstance > ,
52
53
text : string | null ,
53
54
prop : any ,
@@ -57,6 +58,7 @@ type Instance = {|
57
58
type TextInstance = { |
58
59
text : string ,
59
60
id : number ,
61
+ parent : number ,
60
62
hidden : boolean ,
61
63
context : HostContext ,
62
64
| } ;
@@ -80,6 +82,11 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
80
82
parentInstance : Container | Instance ,
81
83
child : Instance | TextInstance ,
82
84
) : void {
85
+ const prevParent = child . parent ;
86
+ if ( prevParent !== - 1 && prevParent !== parentInstance . id ) {
87
+ throw new Error ( 'Reparenting is not allowed' ) ;
88
+ }
89
+ child . parent = parentInstance . id ;
83
90
const index = parentInstance . children . indexOf ( child ) ;
84
91
if ( index !== - 1 ) {
85
92
parentInstance . children . splice ( index , 1 ) ;
@@ -211,6 +218,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
211
218
const clone = {
212
219
id : instance . id ,
213
220
type : type ,
221
+ parent : instance . parent ,
214
222
children : keepChildren ? instance . children : [ ] ,
215
223
text : shouldSetTextContent ( type , newProps )
216
224
? computeText ( ( newProps . children : any ) + '' , instance . context )
@@ -223,6 +231,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
223
231
value : clone . id ,
224
232
enumerable : false ,
225
233
} ) ;
234
+ Object . defineProperty ( clone , 'parent' , {
235
+ value : clone . parent ,
236
+ enumerable : false ,
237
+ } ) ;
226
238
Object . defineProperty ( clone , 'text' , {
227
239
value : clone . text ,
228
240
enumerable : false ,
@@ -285,6 +297,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
285
297
id : instanceCounter ++ ,
286
298
type : type ,
287
299
children : [ ] ,
300
+ parent : - 1 ,
288
301
text : shouldSetTextContent ( type , props )
289
302
? computeText ( ( props . children : any ) + '' , hostContext )
290
303
: null ,
@@ -294,6 +307,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
294
307
} ;
295
308
// Hide from unit tests
296
309
Object . defineProperty ( inst , 'id' , { value : inst . id , enumerable : false } ) ;
310
+ Object . defineProperty ( inst , 'parent' , {
311
+ value : inst . parent ,
312
+ enumerable : false ,
313
+ } ) ;
297
314
Object . defineProperty ( inst , 'text' , {
298
315
value : inst . text ,
299
316
enumerable : false ,
@@ -313,6 +330,11 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
313
330
parentInstance : Instance ,
314
331
child : Instance | TextInstance ,
315
332
) : void {
333
+ const prevParent = child . parent ;
334
+ if ( prevParent !== - 1 && prevParent !== parentInstance . id ) {
335
+ throw new Error ( 'Reparenting is not allowed' ) ;
336
+ }
337
+ child . parent = parentInstance . id ;
316
338
parentInstance . children . push ( child ) ;
317
339
} ,
318
340
@@ -357,11 +379,16 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
357
379
const inst = {
358
380
text : text ,
359
381
id : instanceCounter ++ ,
382
+ parent : - 1 ,
360
383
hidden : false ,
361
384
context : hostContext ,
362
385
} ;
363
386
// Hide from unit tests
364
387
Object . defineProperty ( inst , 'id' , { value : inst . id , enumerable : false } ) ;
388
+ Object . defineProperty ( inst , 'parent' , {
389
+ value : inst . parent ,
390
+ enumerable : false ,
391
+ } ) ;
365
392
Object . defineProperty ( inst , 'context' , {
366
393
value : inst . context ,
367
394
enumerable : false ,
@@ -682,6 +709,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
682
709
const offscreenTextInstance : TextInstance = {
683
710
text : instance . text ,
684
711
id : instanceCounter ++ ,
712
+ parent : instance . parent ,
685
713
hidden : hideNearestNode || instance . hidden ,
686
714
context : instance . context ,
687
715
} ;
@@ -690,6 +718,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
690
718
value : offscreenTextInstance . id ,
691
719
enumerable : false ,
692
720
} ) ;
721
+ Object . defineProperty ( offscreenTextInstance , 'parent' , {
722
+ value : offscreenTextInstance . parent ,
723
+ enumerable : false ,
724
+ } ) ;
693
725
Object . defineProperty ( offscreenTextInstance , 'context' , {
694
726
value : offscreenTextInstance . context ,
695
727
enumerable : false ,
@@ -725,6 +757,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
725
757
const clone : Instance = {
726
758
id : instance . id ,
727
759
type : instance . type ,
760
+ parent : instance . parent ,
728
761
children : clonedChildren ,
729
762
text : instance . text ,
730
763
prop : instance . prop ,
@@ -735,6 +768,10 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
735
768
value : clone . id ,
736
769
enumerable : false ,
737
770
} ) ;
771
+ Object . defineProperty ( clone , 'parent' , {
772
+ value : clone . parent ,
773
+ enumerable : false ,
774
+ } ) ;
738
775
Object . defineProperty ( clone , 'text' , {
739
776
value : clone . text ,
740
777
enumerable : false ,
@@ -754,13 +791,18 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
754
791
const clone = {
755
792
text : textInstance . text ,
756
793
id : textInstance . id ,
794
+ parent : textInstance . parent ,
757
795
hidden : textInstance . hidden || hideNearestNode ,
758
796
context : textInstance . context ,
759
797
} ;
760
798
Object . defineProperty ( clone , 'id' , {
761
799
value : clone . id ,
762
800
enumerable : false ,
763
801
} ) ;
802
+ Object . defineProperty ( clone , 'parent' , {
803
+ value : clone . parent ,
804
+ enumerable : false ,
805
+ } ) ;
764
806
Object . defineProperty ( clone , 'context' , {
765
807
value : clone . context ,
766
808
enumerable : false ,
0 commit comments