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: handleTinyGridColumnsSlots方法中node.props.columns不是数组时造成页面无法加载问题 #1163

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/canvas/DesignCanvas/src/api/useCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const rootSchema = ref([
])

const handleTinyGridColumnsSlots = (node) => {
for (const columnItem of node.props?.columns || []) {
let columns = node.props?.columns && Array.isArray(node.props?.columns) ? node.props.columns : []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样是不是就好了?
let columns = Array.isArray(node.props?.columns) ? node.props.columns : []

for (const columnItem of columns) {
Comment on lines +77 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Good defensive programming to fix loading issue.

The addition of the Array.isArray check is a solid fix for the bug described in the PR. This prevents runtime errors when node.props.columns exists but isn't an array (e.g., if it's an object or primitive value), which would cause the page to fail to load when attempting to iterate over a non-iterable value.

This solution properly handles edge cases while maintaining the original functionality.

if (!columnItem?.slots) {
continue
}
Expand Down