dx(runtime-core): fix warning message for useSlots, useAttrs invocation with missing instance (#13647)
ci / test (push) Waiting to run Details
ci / continuous-release (push) Waiting to run Details
size data / upload (push) Waiting to run Details

This commit is contained in:
Alex Snezhko 2025-07-22 20:42:50 -04:00 committed by GitHub
parent 8cfc10a80b
commit 7343f7c95f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -382,17 +382,17 @@ export function withDefaults<
} }
export function useSlots(): SetupContext['slots'] { export function useSlots(): SetupContext['slots'] {
return getContext().slots return getContext('useSlots').slots
} }
export function useAttrs(): SetupContext['attrs'] { export function useAttrs(): SetupContext['attrs'] {
return getContext().attrs return getContext('useAttrs').attrs
} }
function getContext(): SetupContext { function getContext(calledFunctionName: string): SetupContext {
const i = getCurrentInstance()! const i = getCurrentInstance()!
if (__DEV__ && !i) { if (__DEV__ && !i) {
warn(`useContext() called without active instance.`) warn(`${calledFunctionName}() called without active instance.`)
} }
return i.setupContext || (i.setupContext = createSetupContext(i)) return i.setupContext || (i.setupContext = createSetupContext(i))
} }