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(slots): properly warn if slot invoked in setup #12195

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

yangxiuxiu1115
Copy link
Contributor

fix #12194

@yangxiuxiu1115 yangxiuxiu1115 changed the title fix: update fix(slots): avoiding slot warnings when calling render manually Oct 17, 2024
Copy link

github-actions bot commented Oct 17, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB 38 kB 34.2 kB
vue.global.prod.js 159 kB 57.9 kB 51.4 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.9 kB 18.3 kB 16.7 kB
createApp 55 kB 21.3 kB 19.4 kB
createSSRApp 59 kB 23 kB 20.9 kB
defineCustomElement 59.8 kB 22.8 kB 20.8 kB
overall 68.7 kB 26.3 kB 24 kB

Copy link

pkg-pr-new bot commented Oct 17, 2024

Open in Stackblitz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@12195

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@12195

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@12195

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@12195

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@12195

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@12195

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@12195

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@12195

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@12195

vue

pnpm add https://pkg.pr.new/vue@12195

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@12195

commit: af6d2f6

const normalized = withCtx((...args: any[]) => {
if (
__DEV__ &&
currentInstance &&
(!ctx || ctx.root === currentInstance.root)
(!hasOwn(rawSlots, '_ctx') || (ctx && ctx.root === currentInstance.root))
Copy link
Member

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',
. I think a test case needs to be added to verify the warning will trigger.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

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)

Copy link
Contributor Author

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?

Copy link
Member

@edison1105 edison1105 Oct 18, 2024

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)
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool!!!

@edison1105 edison1105 added ready to merge The PR is ready to be merged. and removed wait changes labels Oct 18, 2024
@edison1105 edison1105 changed the title fix(slots): avoiding slot warnings when calling render manually fix(slots): properly warn if slot invoked in setup Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔩 p2-edge-case ready to merge The PR is ready to be merged.
Projects
None yet
2 participants