Skip to content

fix(slots): properly warn if slot invoked in setup #12195

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

Merged
merged 7 commits into from
May 2, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: add basic warn case
  • Loading branch information
yangchangtao committed Oct 17, 2024
commit 4b1b14e952fc6a6f3737fc711cea85e87b6b9ae7
20 changes: 20 additions & 0 deletions packages/runtime-core/__tests__/componentSlots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ describe('component: slots', () => {
).not.toHaveBeenWarned()
})

test('basic warn', () => {
const Comp = {
setup(_: any, { slots }: any) {
slots.default && slots.default()
return () => null
},
}

const App = {
setup() {
return () => h(Comp, () => h('div'))
},
}

createApp(App).mount(nodeOps.createElement('div'))
expect(
'Slot "default" invoked outside of the render function',
).toHaveBeenWarned()
})

test('should not warn when render in setup', () => {
const container = {
setup(_: any, { slots }: any) {
Expand Down