Skip to content

Conversation

@harlan-zw
Copy link
Contributor

🔗 Linked issue

📚 Description

Was trying to use the docs to figure out usage on reactive query with useFetch and had some issues, ended up in some github issues, so a good opportunity to send a PR :)

@bolt-new-by-stackblitz
Copy link

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

@github-actions github-actions bot added the 4.x label Sep 25, 2025
@harlan-zw harlan-zw changed the title doc: useFetch reactivity doc: missing useFetch option reactivity Sep 25, 2025
@harlan-zw harlan-zw changed the title doc: missing useFetch option reactivity doc: missing useFetch option reactivity Sep 25, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 25, 2025

Walkthrough

Documentation updates in two markdown files. The Getting Started guide notes that reactive fetch options are automatically watched to trigger refetches, shows an opt-out via watch: false, adds a TypeScript usage example, and clarifies computed/reactive URL scenarios. The useFetch API docs change several option types in the UseFetchOptions<DataT> example to MaybeRefOrGetter for method, query, params, body, headers, and baseURL, add a reactive timeout?: MaybeRefOrGetter<number>, and update the $fetch/options documentation (including a reference to a Nuxt guide). No runtime code or exported public entities were modified.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately reflects the main purpose of the changeset by indicating that the documentation for useFetch options lacked reactivity support and this PR addresses that gap. It is specific to the changes made without unnecessary detail or noise.
Description Check ✅ Passed The pull request description explains the context for updating the documentation by describing the author’s experience with reactive query usage in useFetch and referencing related issues, making it directly relevant to the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch doc/use-fetch-reactivity

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@harlan-zw harlan-zw changed the title doc: missing useFetch option reactivity docs: missing useFetch option reactivity Sep 25, 2025
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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1451432 and 4554aa0.

📒 Files selected for processing (2)
  • docs/1.getting-started/10.data-fetching.md (1 hunks)
  • docs/3.api/2.composables/use-fetch.md (5 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
docs/3.api/2.composables/use-fetch.md

103-103: Trailing spaces
Expected: 0 or 2; Actual: 1

(MD009, no-trailing-spaces)

🪛 GitHub Actions: docs
docs/3.api/2.composables/use-fetch.md

[error] 103-103: markdownlint: MD009/no-trailing-spaces Trailing spaces in docs/3.api/2.composables/use-fetch.md:103:146. Trailing spaces [Expected: 0 or 2; Actual: 1] (Command: 'pnpm lint:docs')

🔇 Additional comments (1)
docs/1.getting-started/10.data-fetching.md (1)

484-497: Clarifies auto-watched fetch options well

Thanks for spelling out the new default behaviour and showing the opt-out path with watch: false; this will save folks a lot of head-scratching when queries suddenly refetch.

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/3.api/2.composables/use-fetch.md (1)

196-224: Docs drift: UseFetchOptions type doesn’t expose MaybeRefOrGetter/$fetch/reactive timeout.

The public UseFetchOptions type in packages/nuxt/src/app/composables/fetch.ts still declares key, method, query, params, body, headers, baseURL, and timeout as plain values and doesn’t include a $fetch field. This update shows MaybeRefOrGetter<…> wrappers, adds $fetch, and documents reactive timeout, which will mislead readers and break typed consumers relying on the published definition. Please revert these type changes (or update the actual implementation/types accordingly) so the docs stay in sync with the code.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4554aa0 and ebfff34.

📒 Files selected for processing (1)
  • docs/3.api/2.composables/use-fetch.md (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lint-docs

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebfff34 and 0921cf8.

📒 Files selected for processing (2)
  • docs/1.getting-started/10.data-fetching.md (1 hunks)
  • docs/3.api/2.composables/use-fetch.md (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/1.getting-started/10.data-fetching.md
🔇 Additional comments (1)
docs/3.api/2.composables/use-fetch.md (1)

103-112: Reactive example still misrepresents current behaviour

useFetch only re-fetches automatically when the entire option value is reactive (ref/computed/getter) or explicitly added to watch. Passing a plain object with a nested ref, as in this example, will not trigger a refetch today. Please adjust the explanation and snippet to show either a computed getter for the whole query object or an explicit watch entry, e.g.:

-const { data } = await useFetch('/api/search', {
-  query: { q: searchQuery }
-})
+const { data } = await useFetch('/api/search', {
+  query: computed(() => ({ q: searchQuery.value }))
+})

Alternatively, document using watch: [searchQuery].

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0921cf8 and 11e86f6.

📒 Files selected for processing (1)
  • docs/3.api/2.composables/use-fetch.md (5 hunks)

Comment on lines +101 to +113
### Reactive Fetch Options

Fetch options can be provided as reactive, supporting `computed`, `ref` and [computed getters](https://vuejs.org/guide/essentials/computed.html). When a reactive fetch option is updated it will trigger a refetch using the updated resolved reactive value.

```ts
const searchQuery = ref('initial')
const { data } = await useFetch('/api/search', {
query: { q: searchQuery }
})
// triggers a refetch: /api/search?q=new%20search
searchQuery.value = 'new search'
```

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Doc claim about automatic refetching from nested refs is wrong

useFetch still only re-runs when the request source or explicit watch sources change. Dropping a ref inside a plain options object like query: { q: searchQuery } does not currently trigger a refetch—searchQuery is never tracked. Please correct the wording/example (e.g. wrap the whole query in a computed/ref or show watch: [searchQuery]) to match runtime behaviour.

🤖 Prompt for AI Agents
In docs/3.api/2.composables/use-fetch.md around lines 101 to 113, the docs
incorrectly state that nested refs inside plain option objects (e.g. query: { q:
searchQuery }) will trigger automatic refetches; in reality useFetch only
watches the request source or explicit watch sources and does not track refs
nested inside plain objects. Update the wording and example to reflect runtime
behavior: remove the claim that nested refs are tracked, show a correct pattern
such as wrapping the entire options object in a computed/ref or adding watch:
[searchQuery] to trigger refetches, and update the explanatory text to instruct
users to use computed/ref or explicit watch for reactive query params.

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@danielroe danielroe merged commit 83c774d into main Sep 25, 2025
8 of 9 checks passed
@danielroe danielroe deleted the doc/use-fetch-reactivity branch September 25, 2025 11:17
@github-actions github-actions bot mentioned this pull request Sep 25, 2025
@github-actions github-actions bot mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants