Closed samreid closed 1 year ago
Apply this pattern to ComboBoxItem
does sound like the right thing to do. Thanks for taking the lead.
Progress so far:
I'd like to work on https://github.com/phetsims/sun/issues/798 first, going on hold until then.
Today I implicated myself in this issue. @samreid is likely going to be converting Carousel to use GroupItemOptions, and we may want to do this work as part of that work and/or BLL which uses combo box. This would be especially nice if we felt like PhET-iO api would change, but @samreid and I don't really think that it would.
Addressed in https://github.com/phetsims/sun/issues/814.
UPDATE: I thought this was a carousel issue. No progress on this committed yet.
I'm taking a stab at continuing this from our momentum in Carousel. I have a good local copy and I'm interested in keeping backwards compatibility with item.node on master so we can phase out the old pattern instead of doing things all in one commit. It only took 2 lines of code to make that happen, and now I'm running pixel comparisons to ensure regressionless behavior. I'll keep you posted!
Pixel comparison yielded no related changes except in the PDOM, the node trail IDs changed because the createNode pattern changing the order in which nodes are created in some cases. I also directly compared the visuals in a few sims and things look identical.
In general, I think this is a pretty safe change. There are a couple of usages dependent on the Node before we construct the combo box. I'd like to think about those cases with @samreid (marked by TODOs).
Here is an easy patch for testing comboBox disposal via frictions state wrapper in the localization preferences:
tandem
parameter everywhere. It feels unhelpful and like clutter until it is needed.Here is a nice way to find the remaining usages:
Subject: [PATCH] Add support for GroupItemOptions in ComboBox, https://github.com/phetsims/sun/issues/797
---
Index: js/ComboBox.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/ComboBox.ts b/js/ComboBox.ts
--- a/js/ComboBox.ts (revision bd5a093e76c581dd7f8097b85a26f069cfefca12)
+++ b/js/ComboBox.ts (date 1673553492658)
@@ -185,6 +185,10 @@
`ComboBoxItem tandemName must end with '${ComboBox.ITEM_TANDEM_NAME_SUFFIX}': ${item.tandemName}` );
} );
+ if ( items[ 0 ].node ) {
+ throw new Error();
+ }
+
// See https://github.com/phetsims/sun/issues/542
assert && assert( listParent.maxWidth === null,
'ComboBox is responsible for scaling listBox. Setting maxWidth for listParent may result in buggy behavior.' );
Today, while discussing https://github.com/phetsims/greenhouse-effect/issues/256 with @jbphet, he mentioned that he was confused about why the unused tandem
parameter was part of the new createNode closure. I agree! I will go ahead remove those when I see them to clean things up.
Removing unused tandem parameters made me realize that there is a bit of weirdness about how createNode provided a tandem. In many cases, the tandemName is used by a container of the createNode Node, and shouldn't be used. For example in https://github.com/phetsims/calculus-grapher/blob/b4483f1d83e27508b50bec00cf802d759a31019f/js/common/view/PredictModeRadioButtonGroup.ts#L55-L56. This makes things weird! Let's talk more.
Fixed an area-model case. It's not using ComboBox, and something was still looking for .node
Tagging for https://github.com/phetsims/phet-io/issues/1914 and self-unassigning.
I think of this issue as higher priority that a backlog. Currently both ways to support group items are in ComboBox. We should take steps to make sure that this is in a good medium-term state before unassigning.
This issue has had no work since Jan 17, and my subteam does not anticipate time to work on it in the coming week. How about scheduling it for the iteration beginning on March 9?
Using this patch, I am not seeing any memory leak in combo box, but I am going to stop disposing nodes if we don't own them (due to the old, deprecated strategy).
Good progress here, I was able to get all of the node
usages out of comboBox, and remove the workaround code in ComboBox. I'll check back on CT in a couple hours.
Oops, I had stashed the ESP changes for a snapshot comparison, here they are now.
CT is looking mighty clean today. @samreid will you please take a look at the usages of group item options in ComboBox, and the commits in CarouselComboBox, as well as spot checking some of the usages. I can't think of much else here.
I reviewed the code in ComboBox and CarouselComboBox, and checked some usages. I tested dispose
in BLL and it worked ok. I also saw this commented out assertion, I'm guessing you will want to bring it back until we have better TypeScript coverage? Or were you testing that in local aqua?
// assert && assert( !item.hasOwnProperty( 'node' ), 'we use createNode now' );
Ahh yes thanks. This is redundant to https://github.com/phetsims/sun/blob/cb5784eaf0e86d0039aa83e722dd92a24fbe818a/js/GroupItemOptions.ts#L31.
Closing
After working on https://github.com/phetsims/sun/issues/787, I'm thinking we should apply the same pattern (createNode + tandemName) for ComboBoxItems. @pixelzoom does that sound good to you? If so, please assign to me and I can take the lead.