-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
docs: update fetch type #32522
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
docs: update fetch type #32522
Conversation
|
WalkthroughThe changes update the type signatures and documentation for the ✨ Finishing Touches🧪 Generate Unit Tests
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 (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (4)
docs/3.api/2.composables/use-async-data.md (2)
173-176
: Update surrounding docs to reflect newMaybeRefOrGetter<string>
key typeThe signature section has been updated correctly, but earlier paragraphs still refer to “computed ref, plain ref or a getter function” (lines 58-66) without naming
MaybeRefOrGetter
. Consider adding the new alias there (or linking to its definition) to keep wording and type info aligned.
187-188
:watch
option type broadened — examples still show the old shapeThe type is now
MultiWatchSources | false
, but the “Watch Params” example (lines 40-52) uses a simple array literal and may mis-lead users into thinking only arrays are accepted. A concise example withMultiWatchSources
(e.g. mixed refs & getters) would illustrate the change better.docs/3.api/2.composables/use-fetch.md (2)
106-124
: New$fetch
option and widenedwatch
type need explicit explanationThe signature block adds
$fetch?: typeof globalThis.$fetch
and widenswatch
toMultiWatchSources | false
, but the option table below (lines 154-175) only contains terse one-liners. Users unfamiliar with overriding$fetch
or with Vue’sMultiWatchSources
may miss the intent.Consider:
- Adding one sentence after the table that
$fetch
enables per-call injection of a custom fetch implementation (e.g. authenticated ofetch instance).- Linking
MultiWatchSources
to the Vue docs or briefly explaining that arrays, refs, getters and objects are supported.
156-176
: Inconsistent ordering & duplication in options tableThe rows for
key
,watch
, and$fetch
were inserted but the order now differs from the type signature ($fetch
is declared beforewatch
, but appears after in the table). Keeping identical ordering eases cross-checking and avoids accidental omissions when fields are added in the future.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/3.api/2.composables/use-async-data.md
(3 hunks)docs/3.api/2.composables/use-fetch.md
(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint-docs
data: Ref<DataT | undefined> | ||
pending: Ref<boolean> | ||
refresh: (opts?: AsyncDataExecuteOptions) => Promise<void> | ||
execute: (opts?: AsyncDataExecuteOptions) => Promise<void> | ||
clear: () => void | ||
error: Ref<ErrorT | null> | ||
error: Ref<ErrorT | undefined> | ||
status: Ref<AsyncDataRequestStatus> |
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.
🛠️ Refactor suggestion
Return-value section is now out of sync with the type definition
pending
was added and data
/error
changed from null
→ undefined
, but the prose list at lines 145-158 and the note at line 162 still talk about null
and do not mention pending
. This will confuse consumers relying on strict typing.
-`data`: the result of the asynchronous function that is passed in.
+`data`: the result of the asynchronous function (`Ref<DataT | undefined>`).
+`pending`: a `Ref<boolean>` that is `true` while the request is running.
...
-If you have not fetched data on the server … `data` will remain `null` …
+If you have not fetched data on the server … `data` will remain `undefined` …
Please update all affected bullet points and notes.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In docs/3.api/2.composables/use-async-data.md around lines 145 to 162, update
the return-value section to reflect the current type definitions by replacing
all mentions of `null` with `undefined` for `data` and `error`, and add a new
bullet point describing the `pending` property as a Ref<boolean>. Also, revise
the note at line 162 to mention `undefined` instead of `null` and include
information about the `pending` state to keep the documentation consistent with
the code.
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
docs/3.api/2.composables/use-async-data.md (2)
147-150
: Clarifypending
bullet and fix punctuation/link syntaxMinor wording + formatting tweaks improve readability and silence the LanguageTool warning.
-- `pending`: a boolean ref that indicates whether the request is in progress.[For specific explanations](https://nuxt.com/docs/getting-started/upgrade#alignment-of-pending-value-in-useasyncdata-and-usefetch) +- `pending`: a `Ref<boolean>` that is *true* while the request is running. + See the [upgrade guide](https://nuxt.com/docs/getting-started/upgrade#alignment-of-pending-value-in-useasyncdata-and-usefetch) for more details.
162-164
: Note still omits the newpending
stateThe paragraph now talks about
data
/error
beingundefined
, but it never mentions howpending
behaves during hydration. A quick addition keeps the prose aligned with the type signature.- … `data` will remain `undefined` within `<script setup>`. + … `data` and `error` remain `undefined`, and `pending` is `false`, within `<script setup>`.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/3.api/2.composables/use-async-data.md
(5 hunks)docs/3.api/2.composables/use-fetch.md
(6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/3.api/2.composables/use-fetch.md
🧰 Additional context used
🧠 Learnings (1)
docs/3.api/2.composables/use-async-data.md (1)
Learnt from: Tofandel
PR: nuxt/nuxt#0
File: :0-0
Timestamp: 2024-11-11T12:34:22.648Z
Learning: Ensure that AI-generated summaries accurately reflect the key changes in the PR, focusing on notable changes such as the removal of unused imports and variables starting with underscores.
🪛 LanguageTool
docs/3.api/2.composables/use-async-data.md
[uncategorized] ~148-~148: Loose punctuation mark.
Context: ... function that is passed in. - pending
: a boolean ref that indicates whether th...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~163-~163: Loose punctuation mark.
Context: ...in undefined
within <script setup>
. :: ## Type ```ts [Signature] function u...
(UNLIKELY_OPENING_PUNCTUATION)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint-docs
🔇 Additional comments (1)
docs/3.api/2.composables/use-async-data.md (1)
186-189
: Update option description to match newMultiWatchSources
type
watch
now accepts the broaderMultiWatchSources
union, not only an array. Consider expanding the earlier bullet (“watch reactive sources to auto-refresh”) with an example of passing a singleref
or a tuple, so docs and types stay in sync.
@@ -194,11 +195,12 @@ type AsyncDataRequestContext = { | |||
} | |||
|
|||
type AsyncData<DataT, ErrorT> = { | |||
data: Ref<DataT | null> | |||
data: Ref<DataT | undefined> | |||
pending: Ref<boolean> |
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 think we soft deprecated pending. (IMO thats why it is missing)
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.
Thank you for your explanation.❤
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
docs/3.api/2.composables/use-async-data.md (2)
161-163
: Good consistency update, but the bullet list above still omits theundefined
detail forerror
The note now correctly states that
data
staysundefined
, but the “Return Values” list at lines 147-157 still describeserror
in generic terms without clarifying it is aRef<ErrorT | undefined>
. For absolute consistency with the updated type signature, consider amending that bullet:-`error`: an error object if the data fetching failed. +`error`: a `Ref<ErrorT | undefined>` that becomes populated when the request fails.
187-189
: Update option description to mentionfalse
is allowed
watch
now acceptsMultiWatchSources | false
, but the options list at line 100 still just says “watch reactive sources to auto-refresh”. Adding a quick note thatfalse
disables watching would avoid confusion.-`watch`: watch reactive sources to auto-refresh +`watch`: reactive sources to auto-refresh, or `false` to disable watching entirely
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/3.api/2.composables/use-async-data.md
(4 hunks)docs/3.api/2.composables/use-fetch.md
(6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- docs/3.api/2.composables/use-fetch.md
🧰 Additional context used
🧠 Learnings (1)
docs/3.api/2.composables/use-async-data.md (1)
Learnt from: Tofandel
PR: nuxt/nuxt#0
File: :0-0
Timestamp: 2024-11-11T12:34:22.648Z
Learning: Ensure that AI-generated summaries accurately reflect the key changes in the PR, focusing on notable changes such as the removal of unused imports and variables starting with underscores.
🪛 LanguageTool
docs/3.api/2.composables/use-async-data.md
[uncategorized] ~162-~162: Loose punctuation mark.
Context: ...in undefined
within <script setup>
. :: ## Type ```ts [Signature] function u...
(UNLIKELY_OPENING_PUNCTUATION)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint-docs
🔇 Additional comments (2)
docs/3.api/2.composables/use-async-data.md (2)
173-176
: Type parameter change looks correct and matches earlier proseSwitching
key
toMaybeRefOrGetter<string>
aligns the signature with the “Reactive Keys” section above. No further action required.
196-203
: Return-type rows correctly migrated fromnull
→undefined
The
AsyncData
type now usesRef<DataT | undefined>
/Ref<ErrorT | undefined>
, matching the runtime behaviour.
🔗 Linked issue
📚 Description
Update type of
useFetch
&useAsyncData