Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Problem with Cloning Header Element in resize.ts #189

Open
nsrau opened this issue Nov 22, 2024 · 0 comments
Open

Potential Problem with Cloning Header Element in resize.ts #189

nsrau opened this issue Nov 22, 2024 · 0 comments

Comments

@nsrau
Copy link

nsrau commented Nov 22, 2024

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant