-
Notifications
You must be signed in to change notification settings - Fork 40
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(table): add colLength judge #479
The head ref may contain hidden characters: "478-demo\u8868\u683C\u62D6\u52A8\u5BBD\u5EA6-\u6837\u5F0Fbug"
Conversation
WalkthroughThe pull request introduces a patch for the Changes
Possibly related PRs
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/table-module/src/module/parse-elem-html.ts (1)
133-137
: Handle missing or invalidwidth
attributes for<col>
elements
If the<col>
tag is missing thewidth
attribute,parseInt
can returnNaN
. You may want to validate or default these values.} else if (colgroupElments && colgroupElments.length === colLength) { tableELement.columnWidths = Array.from(colgroupElments).map((col: any) => { - return parseInt(col.getAttribute('width'), 10) + const colWidth = parseInt(col.getAttribute('width') || '90', 10) + return Number.isNaN(colWidth) ? 90 : colWidth }) }.changeset/perfect-years-tap.md (1)
1-6
: Enrich the changeset message
The commit message “fix(table): add colLength judge” is functional but could be more descriptive about the scenario or user benefit (e.g., clarifying why colLength is needed). This helps maintainers quickly understand the purpose when browsing history.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/perfect-years-tap.md
(1 hunks)packages/table-module/src/module/parse-elem-html.ts
(1 hunks)
🔇 Additional comments (1)
packages/table-module/src/module/parse-elem-html.ts (1)
142-142
: Consider fallback for parseInt
when width
style is non-numeric
When the style-based width
or HTML td
width attribute is not numeric, parseInt
can return NaN
. Provide a safe fallback.
// @ts-ignore | ||
const colLength = children[children.length - 1].children.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check bounds before accessing children[children.length - 1]
If children
is an empty array, this could cause an out-of-bounds error. Consider adding a length check before referencing children[children.length - 1]
.
+ if (children.length === 0) {
+ // Handle case when there are no table-row children
+ tableELement.columnWidths = []
+ } else {
// @ts-ignore
- const colLength = children[children.length - 1].children.length
+ const colLength = children[children.length - 1].children?.length ?? 0
+ }
Committable suggestion skipped: line range outside the PR's diff.
Changes Overview
Implementation Approach
Testing Done
Verification Steps
Additional Notes
Checklist
Related Issues
Summary by CodeRabbit
Bug Fixes
Packages Updated
@wangeditor-next/table-module
@wangeditor-next/editor