Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
There have been instances of the following error occurring on CellResizer.ts and TableResizer.ts:
Error Message: Uncaught TypeError: Cannot read properties of undefined (reading 'height')
The specific property call happens on these lines:
CellResizer.ts:
td.style.height = cmTable.rows[anchorRow].height + 'px';
TableResizer.ts:
td.style.height = cmTable.rows[row].height + 'px';
The error is caused after the call to normalizeTable, as the same height property is accessed before normalisation while throwing no issues. In some cases, if a table has never been normalised it is possible for it to lose rows after normalisation, so an error like this one could happen. This happens when an HTML Table contains any row which all its cells have the property rowspan greater than 1, causing a "hidden" row.
Fix
The call to normalise the whole table is unnecessary, because the onDragging methods are only intended to modify the cell's properties width and height. So the call to normalise was replaced with a single step to guarantee the new row height, and column width, is not less than the minimum allowed.
As an abundance of caution, a check to verify that
cmTable.rows[anchorRow]
is not undefined was added in CellResizer.ts.Cases tested:
<table style="border-collapse: collapse; border-spacing: 0px; box-sizing: border-box;"><tbody><tr><td rowspan="2"><div >a</div></td><td rowspan="2" ><div >b</div></td><td rowspan="2" ><div >c</div></td></tr><tr></tr><tr><td ><div >a</div></td><td ><div >b</div></td><td ><div >c</div></td></tr><tr><td rowspan="2" colspan="3" ><div >a</div></td></tr><tr></tr></tbody></table>
Before: Error message is thrown
After: No error message
Warnings and implications