-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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(slots): properly warn if slot invoked in setup #12195
base: main
Are you sure you want to change the base?
Conversation
Size ReportBundles
Usages
|
@vue/compiler-dom
@vue/compiler-core
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
const normalized = withCtx((...args: any[]) => { | ||
if ( | ||
__DEV__ && | ||
currentInstance && | ||
(!ctx || ctx.root === currentInstance.root) | ||
(!hasOwn(rawSlots, '_ctx') || (ctx && ctx.root === currentInstance.root)) |
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.
The condition will cause the following warning to never trigger. Removing the condition || (ctx && ctx.root === currentInstance.root)
will also prevent the warning from triggering in
'Slot "default" invoked outside of the render function', |
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.
I don't see anything wrong with it .
added a basic warn case
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.
core/packages/runtime-core/src/vnode.ts
Line 853 in cb34b28
children = { default: children, _ctx: currentRenderingInstance } |
if the slot value is a function the rawSlots
always has the _ctx
key.
so all test cases pass using the following conditions
if (
__DEV__ &&
currentInstance &&
(ctx && ctx.root === currentInstance.root)
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.
I've added a few test cases, are they correct?
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.
All test cases are correct.
the proper condition should be:
if (
__DEV__ &&
currentInstance &&
!(ctx === null && currentRenderingInstance) &&
!(ctx && ctx.root !== currentInstance.root)
)
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.
cool!!!
fix #12194