@@ -259,36 +259,8 @@ const IdeExplorer = ({
259259 } ) ;
260260 } ;
261261
262- const handleModelSort = useCallback (
263- ( sortBy ) => {
264- setModelSortBy ( sortBy ) ;
265- if ( rawTreeDataRef . current . length > 0 ) {
266- const freshData = JSON . parse ( JSON . stringify ( rawTreeDataRef . current ) ) ;
267- freshData . forEach ( ( node ) => {
268- if ( node . title === "models" && node . children ) {
269- node . children . forEach ( ( child ) => {
270- if ( child . title === "no_code" && child . children ) {
271- child . children = sortModels ( child . children , sortBy ) ;
272- applyModelDecorations ( child . children ) ;
273- }
274- } ) ;
275- }
276- } ) ;
277- transformTree ( freshData ) ;
278- setTreeData ( freshData , false ) ;
279- }
280- } ,
281- [ setTreeData ]
282- ) ;
283-
284- const modelSortMenu = useMemo (
285- ( ) => ( {
286- items : MODEL_SORT_ITEMS ,
287- selectedKeys : [ modelSortBy ] ,
288- onClick : ( { key } ) => handleModelSort ( key ) ,
289- } ) ,
290- [ modelSortBy , handleModelSort ]
291- ) ;
262+ // handleModelSort and modelSortMenu are defined after setTreeData (line ~816)
263+ // to avoid temporal dead zone — see sortMenuRef below for the Dropdown binding
292264
293265 // Function to map string icons from API to actual icon components
294266 // depth: 0 = root (Database), 1 = schema, 2 = table, 3 = column
@@ -1099,6 +1071,34 @@ const IdeExplorer = ({
10991071 }
11001072 } ;
11011073
1074+ const handleModelSort = ( sortBy ) => {
1075+ setModelSortBy ( sortBy ) ;
1076+ if ( rawTreeDataRef . current . length > 0 ) {
1077+ const freshData = JSON . parse ( JSON . stringify ( rawTreeDataRef . current ) ) ;
1078+ freshData . forEach ( ( node ) => {
1079+ if ( node . title === "models" && node . children ) {
1080+ node . children . forEach ( ( child ) => {
1081+ if ( child . title === "no_code" && child . children ) {
1082+ child . children = sortModels ( child . children , sortBy ) ;
1083+ applyModelDecorations ( child . children ) ;
1084+ }
1085+ } ) ;
1086+ }
1087+ } ) ;
1088+ transformTree ( freshData ) ;
1089+ setTreeData ( freshData , false ) ;
1090+ }
1091+ } ;
1092+
1093+ const modelSortMenu = useMemo (
1094+ ( ) => ( {
1095+ items : MODEL_SORT_ITEMS ,
1096+ selectedKeys : [ modelSortBy ] ,
1097+ onClick : ( { key } ) => handleModelSort ( key ) ,
1098+ } ) ,
1099+ [ modelSortBy ]
1100+ ) ;
1101+
11021102 useEffect ( ( ) => {
11031103 if ( schemaMenu ) {
11041104 getExplorer ( projectId ) ;
0 commit comments