nhn / tui.grid

🍞🔡 The Powerful Component to Display and Edit Data. Experience the Ultimate Data Transformer!
http://ui.toast.com/tui-grid/
MIT License
2.42k stars 394 forks source link

refreshRowHeight 메소드 관련 간헐적 에러 발생 #1949

Open hamelmoon opened 1 year ago

hamelmoon commented 1 year ago

Describe the bug Grid 생성 시, rowHeight를 'auto' 로 리액트컴포넌트로 생성하여 TUI 그리드를 다이얼로그 상에서 사용. refreshRowHeight 가 BodyCellComp.prototype.calculateRowHeight 에서 Window.setTimeout 으로 호출됨. 해당 다이얼로그가 클로즈 되어 Virtual Dom 상에서 dispose 되는 시점에 setTimeout 통해 function 이 호출되게 되면서 undefined 엑세스 관련 에러 발생

function refreshRowHeight(store, rowIndex, rowHeight) {
    var data = store.data, rowCoords = store.rowCoords, renderState = store.renderState;
    var cellHeightMap = renderState.cellHeightMap;
    var cellHeights = cellHeightMap[rowIndex];
    if (common_1.isUndefined(cellHeights)) {
        return;
    }

    var highestHeight = Object.keys(cellHeights).reduce(function (acc, columnName) { return Math.max(acc, cellHeights[columnName]); }, -1);
    if (rowHeight !== highestHeight) {
        data.rawData[rowIndex]._attributes.height = highestHeight; //<--- 해당 부분의 data.rawData 는 undefined 이고 data.rawData[rowIndex] 는 undefined 가 됨. 따라서 undefined 에서 _attributes 에 대한 Unhandled Runtime Error 가 발생.
        rowCoords.heights[rowIndex] = highestHeight;
        observable_1.notify(rowCoords, 'heights');
    }
}

Expected behavior cellHeights 처럼 data.rawData[rowIndex]._attributes.height 에 대한 undefined 체크 로직 필요

//expected
function refreshRowHeight(store, rowIndex, rowHeight) {
    var data = store.data, rowCoords = store.rowCoords, renderState = store.renderState;
    var cellHeightMap = renderState.cellHeightMap;
    var cellHeights = cellHeightMap[rowIndex];
    if (common_1.isUndefined(cellHeights)) {
        return;
    }
    var rowData= data.rawData[rowIndex];
    if (common_1.isUndefined(rowData)) {
        return;
    }

    var highestHeight = Object.keys(cellHeights).reduce(function (acc, columnName) { return Math.max(acc, cellHeights[columnName]); }, -1);
    if (rowHeight !== highestHeight) {
        data.rawData[rowIndex]._attributes.height = highestHeight;
        rowCoords.heights[rowIndex] = highestHeight;
        observable_1.notify(rowCoords, 'heights');
    }
}
VFZONE commented 1 year ago

저도 똑같이 발생하는 에러인데 알려주신대로 하니 에러 안나네요. 수정해주시면 감사드리겠습니다.