Skip to content

Commit e9ef86b

Browse files
committed
fix(FR-1509): fix sidebar menu sorting inconsistency across browsers (#4329)
Resolves #4328 ([FR-1509](https://lablup.atlassian.net/browse/FR-1509)) ## Summary Fixes a browser-specific bug where non-group menu items appear at the end of the sidebar menu in Firefox, while they display correctly at the beginning in Chrome and Safari. ## Root Cause Different JavaScript engines (V8 in Chrome, SpiderMonkey in Firefox, JavaScriptCore in Safari) may pass items to the sort callback in different orders. The original sorting logic didn't properly handle non-group items that weren't in the predefined order array, causing inconsistent comparison results depending on the callback order. ## Changes - Implement explicit weight-based sorting for both group and non-group items - Assign negative weight (-1) to non-group items to ensure they always appear first - Properly handle group items not in the predefined order by assigning them maximum weight - Ensure consistent sorting results regardless of JavaScript engine implementation - Remove TypeScript ignore comments and improve type safety ## Testing - Verified menu ordering is consistent across Firefox, Chrome, and Safari - Non-group items now properly appear at the beginning of the menu in all browsers - Group items maintain correct predefined order This fix ensures consistent menu ordering across all browsers by making the sorting logic deterministic and independent of the JavaScript engine's sort implementation details. [FR-1509]: https://lablup.atlassian.net/browse/FR-1509?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent c6915f4 commit e9ef86b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

react/src/components/MainLayout/WebUISider.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
408408
children: items,
409409
};
410410
})
411+
.flatten()
411412
.sort((a, b) => {
412-
const order: Array<GroupName> = [
413+
const groupOrder: Array<GroupName | undefined> = [
414+
undefined,
413415
'none',
414416
'storage',
415417
'workload',
@@ -418,15 +420,17 @@ const WebUISider: React.FC<WebUISiderProps> = (props) => {
418420
'mlops',
419421
'metrics',
420422
];
421-
// @ts-ignore
422-
// If a.name is not in order array, push it to the end.
423-
if (!_.includes(order, a.name)) {
424-
return 1;
425-
}
426-
// @ts-ignore
427-
return order.indexOf(a.name) - order.indexOf(b.name);
423+
424+
// if item is not group type, place it at the beginning
425+
// if item is group type but not in the groupOrder, place it at the end
426+
const getWeight = (item: any) => {
427+
if (item?.type !== 'group') return -1; // non-group items first
428+
const idx = groupOrder.indexOf(item.name as GroupName | undefined);
429+
return idx === -1 ? Number.MAX_SAFE_INTEGER : idx;
430+
};
431+
432+
return getWeight(a) - getWeight(b);
428433
})
429-
.flatten()
430434
.value();
431435

432436
return (

0 commit comments

Comments
 (0)