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

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.1 kB 34.4 kB
vue.global.prod.js 158 kB 58.3 kB 51.9 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.4 kB 18.2 kB 16.6 kB
createApp 54.4 kB 21.2 kB 19.4 kB
createSSRApp 58.6 kB 22.9 kB 20.9 kB
defineCustomElement 59.2 kB 22.7 kB 20.7 kB
overall 68.5 kB 26.4 kB 24 kB

Copy link

pkg-pr-new bot commented Oct 17, 2024

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@12195

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@12195

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@12195

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@12195

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@12195

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@12195

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@12195

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@12195

@vue/shared

npm i https://pkg.pr.new/@vue/shared@12195

vue

npm i https://pkg.pr.new/vue@12195

@vue/compat

npm i https://pkg.pr.new/@vue/compat@12195

commit: 1591ac6

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
@bee1an
Copy link

bee1an commented Jan 7, 2025

Keep track of the problem

@edison1105 edison1105 added 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. and removed 🔩 p2-edge-case labels Jan 7, 2025
@edison1105
Copy link
Member

/ecosystem-ci run

@vue-bot
Copy link
Contributor

vue-bot commented Apr 10, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
router success success
nuxt success success
radix-vue success success
pinia success success
language-tools success success
test-utils success success
vueuse success success
vitepress success success
vue-macros success success
primevue success success
vite-plugin-vue success success
quasar success success
vant success success
vue-i18n success success
vue-simple-compiler success success
vuetify success success

@yyx990803 yyx990803 merged commit 9196222 into vuejs:main May 2, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged.
Projects
None yet
5 participants