-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(nuxt): support reactive keys in useLazyAsyncData
#32092
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
Conversation
|
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.
Pull Request Overview
Syncs the valid key check in useLazyAsyncData
with useAsyncData
to support reactive keys and function-overload signatures.
- Expanded the conditional to recognize object keys and handler-only signatures.
- Updated argument unshifting to align with
useAsyncData
’s behavior.
@@ -472,7 +472,7 @@ export function useLazyAsyncData< | |||
DefaultT = undefined, | |||
> (...args: any[]): AsyncData<PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined> { | |||
const autoKey = typeof args[args.length - 1] === 'string' ? args.pop() : undefined | |||
if (typeof args[0] !== 'string') { args.unshift(autoKey) } | |||
if (typeof args[0] !== 'string' && typeof args[0] !== 'object' && !(typeof args[0] === 'function' && typeof args[1] === 'function')) { args.unshift(autoKey) } |
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 typeof args[0] !== 'object'
will treat null
(where typeof null === 'object'
) as a valid key, which may lead to unintended behavior. Consider explicitly checking for args[0] != null
before accepting object keys.
if (typeof args[0] !== 'string' && typeof args[0] !== 'object' && !(typeof args[0] === 'function' && typeof args[1] === 'function')) { args.unshift(autoKey) } | |
if (args[0] != null && typeof args[0] !== 'string' && typeof args[0] !== 'object' && !(typeof args[0] === 'function' && typeof args[1] === 'function')) { args.unshift(autoKey) } |
Copilot uses AI. Check for mistakes.
@@ -472,7 +472,7 @@ export function useLazyAsyncData< | |||
DefaultT = undefined, | |||
> (...args: any[]): AsyncData<PickFrom<DataT, PickKeys>, (NuxtErrorDataT extends Error | NuxtError ? NuxtErrorDataT : NuxtError<NuxtErrorDataT>) | undefined> { | |||
const autoKey = typeof args[args.length - 1] === 'string' ? args.pop() : undefined | |||
if (typeof args[0] !== 'string') { args.unshift(autoKey) } | |||
if (typeof args[0] !== 'string' && typeof args[0] !== 'object' && !(typeof args[0] === 'function' && typeof args[1] === 'function')) { args.unshift(autoKey) } |
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.
[nitpick] The combined type-check condition is quite dense and may hinder readability. Consider extracting each predicate into clearly named boolean variables (e.g., isStringKey
, isReactiveKey
, isHandlerOnlySignature
) or a helper function to improve clarity.
if (typeof args[0] !== 'string' && typeof args[0] !== 'object' && !(typeof args[0] === 'function' && typeof args[1] === 'function')) { args.unshift(autoKey) } | |
const isStringKey = typeof args[0] === 'string' | |
const isReactiveKey = typeof args[0] === 'object' | |
const isHandlerOnlySignature = typeof args[0] === 'function' && typeof args[1] === 'function' | |
if (!isStringKey && !isReactiveKey && !isHandlerOnlySignature) { | |
args.unshift(autoKey) | |
} |
Copilot uses AI. Check for mistakes.
WalkthroughThe update refactors the logic that determines whether to prepend an automatically extracted key ( Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@nuxt/kit
nuxt
@nuxt/schema
@nuxt/rspack-builder
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #32092 will not alter performanceComparing Summary
|
🔗 Linked issue
resolves #32091
📚 Description
when implementing support for reactive keys in #31373 we didn't update the check for a valid key in
useLazyAsyncData
. This syncs it withuseAsyncData
.