You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: TabsOverflow not being properly disposed when List<items> is changed in FluentTabs #3268
I have a component that builds makes a tab for each item in a list. When the user filters the list down to a subset of items the number of tabs is correctly updated in the UI but it leaves behind an orphaned badge of overflow items that previously existed.
If the number of items in the list changed such that there is no longer an overflow, those items should be properly disposed of from TabsOverflow.
😯 Current Behavior
When I change the slider to hide inactive projects, the number of tabs is reduced to the expected amount. If there was an overflow prior to reducing the list of items then the overflow badge remains along with any tab-ids that were in the overflow prior to the item list change.
The overflow is only being updated based on when a resize of the parent element takes place (this is done in JS). I need to see if that can be triggered in a different way as well.
The FluentTabs knows nothing about your Items collection and will not do anything with changes to that collection. Placing Items in the Data parameter is just for creating a storage for that data. Same goes for storing the item in the FluentTabData. The components do nothing with that information
Thanks for the under the hood explanation. I figured it might have to do with window resize events to update it but the badge still remained after. You can trigger the same behavior on the demo site by removing items from the dynamic example until the overflow isn't needed anymore but the list has more than one item left. Trying to remove the final item does get rid of the badge.
Yes, the clicking the close icon on a tab (which is what you do in the example you mention) calls the unregister method on the FluentTabs which then ultimately calls a JS overflow refresh function.
There are be some pretty big changes needed to make this callable in another way as well.
Yeah I was reading the internal methods and saw that is what it was doing. However it appears there is still some unexpected behavior if you don't remove from the end of the list. Even when resizing the page the overflow doesn't go away.
Was looking at that one as well. I think it is cause by the internal tabs collection getting out of sync with the actual DOM tabs collection. No solution found yet...
So I was looking at potential work arounds so I changed my filter function so that instead of changing the collection, I would use the Visible property to hide the filtered items. When I apply the filter to hide all the Inactive Items, if there were any active items in the overflow they are correctly removed from the overflow list and displayed in the correct order in the tabs element. However any Inactive Items that were previously in the overflow remain in the overflow. They remain in the overflow despite the tabs being hidden and unable to be able to be navigated to. That overflow persists past window resizes.
In my testing, removing the January tab corrupts _tabs -- see Watch window in pic (haven't tested other cases). The key for the February tab tab-02 remains correct, but its value is replaced with March. This pattern continues, causing a shift in subsequent tab values.
There may be an underlying Blazor issue .. particularly in how dictionary updates are handled.
Blazor’s UI diffing appears to be causing Dictionary<string, FluentTab> _tabs to behave incorrectly when a tab is removed. Removing an item from TabsDynamic.Items does not remove the FluentTabs._tabs item Key from _tabs. Instead, Blazor shifts Values left while preserving Keys, leading to mismatched Key/Value assignments:
When removing the January tab, it's associated tab-01Key remains but now references February instead of January.
_tabs.Count does not decrease. Instead, it keeps the last tab (tab-12) in its original position.
Converting _tabs to a List<FluentTab> prevents the key-value mismatches.
There also appears to be an issue with passing FluentTab to FluentTabs.UnregisterTabAsync. After the tab is removed from Items in TabsDynamic.CloseTab, the FluentTab parameter shifts reference to the next tab -- February -- instead of retaining its original parameter value -- January in this case..
Added some HashCode logging and verified that Blazor is upadating _tabsin-place and _tabs does not shrink on it's own causing the last tab to persist so explicit removal is required.
If n items are programmatically removed from the Items list then n items will likely need to be removed from the end of the _tabs list.
HashCode Test Results
Before OnTabClose: _tabs instance = 11555583, Count = 12
No, this does not sound way out at all! I was looking at this yesterday and sort of came to the same conclusion. Just did not think to change the Dictionary to a List.
Explicitly remove the last tab becausee _tabs does not shrink automatically
Where/when are you doing that? I tried a couple of your proposed changes but it is still not working as it should. Can you list the updated code here of do a quick PR?
Activity
vnbaaij commentedon Jan 30, 2025
The overflow is only being updated based on when a resize of the parent element takes place (this is done in JS). I need to see if that can be triggered in a different way as well.
The
FluentTabsknows nothing about yourItemscollection and will not do anything with changes to that collection. PlacingItemsin theDataparameter is just for creating a storage for that data. Same goes for storing the item in theFluentTabData. The components do nothing with that informationxeroiv commentedon Jan 30, 2025
Thanks for the under the hood explanation. I figured it might have to do with window resize events to update it but the badge still remained after. You can trigger the same behavior on the demo site by removing items from the dynamic example until the overflow isn't needed anymore but the list has more than one item left. Trying to remove the final item does get rid of the badge.
vnbaaij commentedon Jan 30, 2025
Yes, the clicking the close icon on a tab (which is what you do in the example you mention) calls the unregister method on the
FluentTabswhich then ultimately calls a JS overflow refresh function.There are be some pretty big changes needed to make this callable in another way as well.
xeroiv commentedon Jan 30, 2025
Yeah I was reading the internal methods and saw that is what it was doing. However it appears there is still some unexpected behavior if you don't remove from the end of the list. Even when resizing the page the overflow doesn't go away.
vnbaaij commentedon Jan 30, 2025
Was looking at that one as well. I think it is cause by the internal tabs collection getting out of sync with the actual DOM tabs collection. No solution found yet...
xeroiv commentedon Jan 30, 2025
So I was looking at potential work arounds so I changed my filter function so that instead of changing the collection, I would use the Visible property to hide the filtered items. When I apply the filter to hide all the Inactive Items, if there were any active items in the overflow they are correctly removed from the overflow list and displayed in the correct order in the tabs element. However any Inactive Items that were previously in the overflow remain in the overflow. They remain in the overflow despite the tabs being hidden and unable to be able to be navigated to. That overflow persists past window resizes.
rpodevns commentedon Jan 30, 2025
In my testing, removing the January tab corrupts
_tabs-- see Watch window in pic (haven't tested other cases). The key for the February tabtab-02remains correct, but its value is replaced with March. This pattern continues, causing a shift in subsequent tab values.rpodevns commentedon Jan 30, 2025
I see nothing in the code that would cause this issue with
_tabsand wondering if maybe it's a synchronization or race condition.rpodevns commentedon Jan 31, 2025
There may be an underlying
Blazorissue .. particularly in how dictionary updates are handled.Blazor’s UI diffing appears to be causing
Dictionary<string, FluentTab> _tabsto behave incorrectly when a tab is removed. Removing an item fromTabsDynamic.Itemsdoes not remove theFluentTabs._tabsitemKeyfrom_tabs. Instead, Blazor shiftsValuesleft while preservingKeys, leading to mismatchedKey/Valueassignments:When removing the
Januarytab, it's associatedtab-01Keyremains but now referencesFebruaryinstead ofJanuary._tabs.Countdoes not decrease. Instead, it keeps the last tab (tab-12) in its original position.Converting
_tabsto aList<FluentTab> prevents the key-value mismatches.There also appears to be an issue with passing
FluentTabtoFluentTabs.UnregisterTabAsync. After the tab is removed fromItemsinTabsDynamic.CloseTab, theFluentTabparameter shifts reference to the next tab --February-- instead of retaining its original parameter value --Januaryin this case..Added some
HashCodelogging and verified that Blazor is upadating_tabsin-place and_tabsdoes not shrink on it's own causing the last tab to persist so explicit removal is required.If
nitems are programmatically removed from theItemslist thennitems will likely need to be removed from the end of the_tabslist.HashCode Test Results
Before
OnTabClose: _tabs instance = 11555583, Count = 12After
OnTabClose: _tabs instance = 11555583, Count = 12INFO: tab-01 is removed from
_tabswhen removed from ItemsThis is what works for me:
_tabsfrom aDictionary<string, FluentTab>to aList<FluentTab>string idtoUnregisterTabAsyncinstead ofFluentTabto avoid reference issues.tabsdoes not shrink automaticallyLet me know if the sounds way out in left field.
vnbaaij commentedon Jan 31, 2025
No, this does not sound way out at all! I was looking at this yesterday and sort of came to the same conclusion. Just did not think to change the Dictionary to a List.
Where/when are you doing that? I tried a couple of your proposed changes but it is still not working as it should. Can you list the updated code here of do a quick PR?
rpodevns commentedon Jan 31, 2025
FluentTabs.razor.csis attached. Most changes are for theDictionarytoListconversion.3268 - FluentTabs.razor.txt
Replace Dictionary with a List and fix overflow keeping closed items. F…
vnbaaij commentedon Feb 1, 2025
Fixed with PR mentioned
[Tabs] Fix Overflow getting out of sync with tab collection (#3284)