-
Notifications
You must be signed in to change notification settings - Fork 404
Fix Tabs component package inheritance for tabs without packages #5929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ajpallares
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great investigation for this! 🙌
This is certainly a tricky scenario to solve. I think we're very close, but I have one doubt about a specific case and I also think that the current implementation is not propagating down the selected packages into the tab without packages.
But we're getting there!
| // Requirements: | ||
| // 1. Tabs WITH packages: use their own package context, propagate to parent for purchase button | ||
| // 2. Tabs WITHOUT packages: inherit from parent's selected package | ||
| // 3. Tabs WITHOUT packages should NOT be affected when tabs WITH packages propagate their package | ||
| // 4. Tabs WITHOUT packages SHOULD update when user selects a different parent package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this I wonder what happens in this scenario, same example structure:
- Initially, Package A is the default.
- Select Tab 1, and then select Package C in that tab --> "propagate to parent for purchase button".
- Select Tab 2.
What package is shown in Tab 2?
According to the explanation below
This context will be kept in sync with parent changes via
onChangeOfin the body, which filters out propagations from tabs with packages.
This means that Tab 1 would always show the latest Parent package selected (A or B) even when Package C could be the latest package selected (from tab 2).
Is that what we want? That's what I gather from
Tabs WITHOUT packages should NOT be affected when tabs WITH packages propagate their package
But in the scenario above, what package is shown in Tab 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a video of the behavior:
Uploading Simulator Screen Recording - iPhone 16 Pro - 2025-12-12 at 10.38.25.mov…
For Tab2, the "active" package will be first the default in the parent scope, or the latest selected one.
| let packageContext = PackageContext( | ||
| package: parentPackageContext.package, | ||
| variableContext: parentPackageContext.variableContext | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're creating a new instance of PackageContext, which means that the onChangeOf won't really work because the @Published package of the new PackageContext won't change when the parent's package changes. In other words, this requirement
Tabs WITHOUT packages SHOULD update when user selects a different parent package
would not work right now.
I'm not 100% sure about this, but, if the Tab component doesn't have any package itself at this point (tabViewModel.packages.isEmpty), I think you could just do
return (key, parentPackageContext)
But we'd need to test it thoroughly, as I'm not sure that this behavior would match the desired behavior (mostly about not propagating the selected package inside Tab 1 to Tab 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this works because:
self.packageContext(line 73) is the parent's@EnvironmentObjectonChangeOf(self.packageContext.package)watches THIS parent context- When parent changes,
syncParentPackageToTabsWithoutPackagesupdates the separate tier contexts
Motivation
Description
Problem
When a Tabs component contained:
Several issues occurred:
Solution
The fix has three parts:
1. Direct reference sharing for tabs without packages
PackageContextinstanceparentPackageContextdirectly (same reference)2. Tab switching logic
When switching to a tab:
parentOwnedPackage(the user's last selection in parent scope)3. Parent selection tracking
Track
parentOwnedPackageto distinguish user selections from tab propagations:This ensures that when switching back to a package-less tab, we restore the user's actual selection, not a package that was propagated from another tab.