Skip to content

Commit

Permalink
fix(space): vnode reuse problem caused by filtering out comment vnode…
Browse files Browse the repository at this point in the history
…s of slot, closes #5136 (#5192)

Co-authored-by: 07akioni <07akioni2@gmail.com>
  • Loading branch information
jizai1125 and 07akioni authored Dec 18, 2023
1 parent dda96f3 commit c6667d0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## NEXT_VERSION

### Fixes

- Fix n-space vnode reuse problem caused by filtering out comment nodes of slot, closes [#5136](https://github.com/tusen-ai/naive-ui/issues/5136).

### Features

- `n-space` adds `reverse` prop.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## NEXT_VERSION

### Fixes

- 修复 `n-space` 插槽过滤了注释节点导致节点复用问题,关闭 [#5136](https://github.com/tusen-ai/naive-ui/issues/5136)

### Features

- `n-space` 新增 `reverse` 属性
- `n-input` 新增 `clear` 方法,关闭[#5423](https://github.com/tusen-ai/naive-ui/issues/5423)

Expand Down
3 changes: 2 additions & 1 deletion src/_utils/vue/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export function flatten (
flatten(vNode.children, filterCommentNode, result)
}
// rawSlot
} else if (vNode.type !== Comment) {
} else {
if (vNode.type === Comment && filterCommentNode) return
result.push(vNode)
}
})
Expand Down
77 changes: 42 additions & 35 deletions src/space/src/Space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
h,
defineComponent,
computed,
Comment,

Check failure on line 5 in src/space/src/Space.tsx

View workflow job for this annotation

GitHub Actions / lint (18)

'Comment' is defined but never used
type PropType,
type CSSProperties
} from 'vue'
Expand Down Expand Up @@ -127,7 +128,7 @@ export default defineComponent({
wrapItem,
internalUseGap
} = this
const children = flatten(getSlot(this))
const children = flatten(getSlot(this), false)
if (!children.length) return null
const horizontalMargin = `${margin.horizontal}px`
const semiHorizontalMargin = `${margin.horizontal / 2}px`
Expand Down Expand Up @@ -179,42 +180,48 @@ export default defineComponent({
}
: rtlEnabled
? {
marginLeft: isJustifySpace
? justify === 'space-between' && index === lastIndex
? ''
: semiHorizontalMargin
: index !== lastIndex
? horizontalMargin
: '',
marginRight: isJustifySpace
? justify === 'space-between' && index === 0
? ''
: semiHorizontalMargin
: '',
paddingTop: semiVerticalMargin,
paddingBottom: semiVerticalMargin
marginBottom:
index !== lastIndex ? verticalMargin : ''
}
: {
marginRight: isJustifySpace
? justify === 'space-between' && index === lastIndex
? ''
: semiHorizontalMargin
: index !== lastIndex
? horizontalMargin
: rtlEnabled
? {
marginLeft: isJustifySpace
? justify === 'space-between' && index === lastIndex
? ''
: semiHorizontalMargin
: index !== lastIndex
? horizontalMargin
: '',
marginRight: isJustifySpace
? justify === 'space-between' && index === 0
? ''
: semiHorizontalMargin
: '',
marginLeft: isJustifySpace
? justify === 'space-between' && index === 0
? ''
: semiHorizontalMargin
: '',
paddingTop: semiVerticalMargin,
paddingBottom: semiVerticalMargin
}
]}
>
{child}
</div>
))}
paddingTop: semiVerticalMargin,
paddingBottom: semiVerticalMargin
}
: {
marginRight: isJustifySpace
? justify === 'space-between' && index === lastIndex
? ''
: semiHorizontalMargin
: index !== lastIndex
? horizontalMargin
: '',
marginLeft: isJustifySpace
? justify === 'space-between' && index === 0
? ''
: semiHorizontalMargin
: '',
paddingTop: semiVerticalMargin,
paddingBottom: semiVerticalMargin
}
]}

Check failure on line 219 in src/space/src/Space.tsx

View workflow job for this annotation

GitHub Actions / lint (18)

Expected indentation of 16 spaces but found 18
>
{child}
</div>
)

Check failure on line 223 in src/space/src/Space.tsx

View workflow job for this annotation

GitHub Actions / lint (18)

Expected indentation of 10 spaces but found 12
)}
</div>
)
}
Expand Down

0 comments on commit c6667d0

Please sign in to comment.