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

Fix cell resizer normalisation #2678

Merged
merged 7 commits into from
Jun 4, 2024

Conversation

Andres-CT98
Copy link
Contributor

@Andres-CT98 Andres-CT98 commented May 31, 2024

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:

  1. Open Inspect in browser
  2. Using the demo site, restore the following snapshot: <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>
  3. Attempt to resize the whole table or just the last row
  4. Observe the console

Before: Error message is thrown

After: No error message

Warnings and implications

  • A similar error is unlikely to occur on operations involving columns, because the in case of "hidden" columns, a resize will not be applied or will be applied to the previous "real" column.

@Andres-CT98 Andres-CT98 marked this pull request as ready for review May 31, 2024 20:57
@Andres-CT98 Andres-CT98 marked this pull request as draft May 31, 2024 21:44
@Andres-CT98 Andres-CT98 marked this pull request as ready for review June 4, 2024 18:53
@Andres-CT98 Andres-CT98 merged commit 68bfc33 into master Jun 4, 2024
7 checks passed
@Andres-CT98 Andres-CT98 deleted the u/acampostams/fix-cell-resizer-undefined branch June 4, 2024 21:56
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

Successfully merging this pull request may close these issues.

2 participants