Open
Description
Description
The code snippet in the resize.ts file clones the parent element of a header cell in the grid using the following line:
const headerTextClone: Element = (<HTMLElement>headerTable.querySelector('[e-mappinguid="' + uid + '"]').parentElement.cloneNode(true));
If the parentElement is null or the selector does not match any element, this could result in a runtime error.
Uncaught TypeError: Cannot read properties of null (reading 'parentElement')
at Resize2.resizeColumn (resize.js:115:87)
at Resize2.findColumn (resize.js:242:22)
at Resize2.autoFitColumns (resize.js:68:14)
at Resize2.autoFit (resize.js:80:18)
at Observer2.notify (observer.js:102:29)
at Component2.notify (component.js:338:32)
at content-renderer.js:78:30
at util.js:63:13
Expected Behavior
The cloning operation should be efficient, safe, and handle edge cases (e.g., when parentElement is null).
Suggested Fix
Add a null-check for parentElement before attempting to clone it
const headerCell = headerTable.querySelector('[e-mappinguid="' + uid + '"]');
const parentElement = headerCell ? headerCell.parentElement : null;
if (parentElement) {
const headerTextClone: Element = parentElement.cloneNode(true);
}