@@ -257,8 +257,6 @@ export class BaseNode<T> {
257
257
*/
258
258
export class ElementNode < T > extends BaseNode < T > {
259
259
nodeType = 8 ; // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
260
- // TODO: running with assumption that setProps will be called before any other calls to node are made so theoretically
261
- // node will be defined
262
260
private _node : CollectionNode < T > | null ;
263
261
isMutated = true ;
264
262
private _index : number = 0 ;
@@ -335,17 +333,14 @@ export class ElementNode<T> extends BaseNode<T> {
335
333
}
336
334
}
337
335
338
- setProps < E extends Element > ( obj : { [ key : string ] : any } , ref : ForwardedRef < E > , rendered ?: ReactNode , render ?: ( node : Node < T > ) => ReactElement , CollectionNodeClass ?: CollectionNodeClass < any > ) : void {
339
- let node = this . getMutableNode ( ) ;
336
+ setProps < E extends Element > ( obj : { [ key : string ] : any } , ref : ForwardedRef < E > , CollectionNodeClass : CollectionNodeClass < any > , rendered ?: ReactNode , render ?: ( node : Node < T > ) => ReactElement ) : void {
337
+ let node ;
340
338
let { value, textValue, id, ...props } = obj ;
341
-
342
-
343
- // TODO: Flow here is that if this called for first time, aka this.node is undef, call
344
- // this.node = new CollectionNode(type, `react-aria-${++ownerDocument.nodeId}`); but make new TreeNode/MenuNode/etc instead of CollectionNode
345
- // Caveat is this assumes we don't need a node before setProps is called on it
346
- if ( node == null && CollectionNodeClass ) {
347
- node = new CollectionNodeClass ( `react-aria-${ ++ this . ownerDocument . nodeId } ` ) ;
339
+ if ( this . _node == null ) {
340
+ node = new CollectionNodeClass ( id ?? `react-aria-${ ++ this . ownerDocument . nodeId } ` ) ;
348
341
this . node = node ;
342
+ } else {
343
+ node = this . getMutableNode ( ) ;
349
344
}
350
345
351
346
props . ref = ref ;
@@ -355,20 +350,13 @@ export class ElementNode<T> extends BaseNode<T> {
355
350
node . value = value ;
356
351
node . textValue = textValue || ( typeof props . children === 'string' ? props . children : '' ) || obj [ 'aria-label' ] || '' ;
357
352
if ( id != null && id !== node . key ) {
358
- // TODO: still need to use this.hasSetProps so this can run twice (?) instead of setting node.key above
359
- // If we set node.key = id and change this to if (this.node), setting refs fails. If we just check (this.node here), it will fail if the user provides an id
360
- if ( this . hasSetProps ) {
361
- throw new Error ( 'Cannot change the id of an item' ) ;
362
- }
363
- node . key = id ;
353
+ throw new Error ( 'Cannot change the id of an item' ) ;
364
354
}
365
355
366
356
if ( props . colSpan != null ) {
367
357
node . colSpan = props . colSpan ;
368
358
}
369
359
370
- // TODO: still need this, see above comment
371
- this . hasSetProps = true ;
372
360
if ( this . isConnected ) {
373
361
this . ownerDocument . queueUpdate ( ) ;
374
362
}
0 commit comments