Skip to content

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

Merged
merged 3 commits into from
Jul 2, 2025
Merged

docs: update fetch type #32522

merged 3 commits into from
Jul 2, 2025

Conversation

xjccc
Copy link
Contributor

@xjccc xjccc commented Jul 2, 2025

🔗 Linked issue

📚 Description

Update type of useFetch & useAsyncData

@xjccc xjccc requested a review from danielroe as a code owner July 2, 2025 02:45
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Jul 2, 2025

Walkthrough

The changes update the type signatures and documentation for the useAsyncData and useFetch composables. The key parameter now accepts a MaybeRefOrGetter<string> instead of just a string or ref. The watch option type is broadened to MultiWatchSources | false. The AsyncData return type replaces null with undefined for the data and error refs. For useFetch, an optional $fetch property is added to the options, allowing custom fetch implementations. Documentation tables and descriptions are revised to reflect these updates.

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 new MaybeRefOrGetter<string> key type

The 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 shape

The 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 with MultiWatchSources (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 widened watch type need explicit explanation

The signature block adds $fetch?: typeof globalThis.$fetch and widens watch to MultiWatchSources | false, but the option table below (lines 154-175) only contains terse one-liners. Users unfamiliar with overriding $fetch or with Vue’s MultiWatchSources may miss the intent.

Consider:

  1. Adding one sentence after the table that $fetch enables per-call injection of a custom fetch implementation (e.g. authenticated ofetch instance).
  2. Linking MultiWatchSources to the Vue docs or briefly explaining that arrays, refs, getters and objects are supported.

156-176: Inconsistent ordering & duplication in options table

The rows for key, watch, and $fetch were inserted but the order now differs from the type signature ($fetch is declared before watch, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 50f9b53 and 4fa77d0.

📒 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

Comment on lines 197 to 203
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>
Copy link

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 nullundefined, 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.

Copy link

@coderabbitai coderabbitai bot left a 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: Clarify pending bullet and fix punctuation/link syntax

Minor 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 new pending state

The paragraph now talks about data/error being undefined, but it never mentions how pending 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa77d0 and 6b497ec.

📒 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 new MultiWatchSources type

watch now accepts the broader MultiWatchSources union, not only an array. Consider expanding the earlier bullet (“watch reactive sources to auto-refresh”) with an example of passing a single ref 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>
Copy link
Collaborator

@OrbisK OrbisK Jul 2, 2025

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)

Copy link
Contributor Author

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.❤

Copy link

@coderabbitai coderabbitai bot left a 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 the undefined detail for error

The note now correctly states that data stays undefined, but the “Return Values” list at lines 147-157 still describes error in generic terms without clarifying it is a Ref<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 mention false is allowed

watch now accepts MultiWatchSources | false, but the options list at line 100 still just says “watch reactive sources to auto-refresh”. Adding a quick note that false 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6b497ec and 4768d3a.

📒 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 prose

Switching key to MaybeRefOrGetter<string> aligns the signature with the “Reactive Keys” section above. No further action required.


196-203: Return-type rows correctly migrated from nullundefined

The AsyncData type now uses Ref<DataT | undefined> / Ref<ErrorT | undefined>, matching the runtime behaviour.

@danielroe danielroe merged commit 9805392 into nuxt:main Jul 2, 2025
7 of 8 checks passed
@github-actions github-actions bot mentioned this pull request Jul 2, 2025
@xjccc xjccc deleted the docs/fetch-type branch July 2, 2025 08:41
danielroe pushed a commit that referenced this pull request Jul 3, 2025
@github-actions github-actions bot mentioned this pull request Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy