Skip to content

feat: refactor useCustomFetch to use createUseFetch#207

Open
maximepvrt wants to merge 1 commit intonuxt:mainfrom
maximepvrt:update-custom-fetch
Open

feat: refactor useCustomFetch to use createUseFetch#207
maximepvrt wants to merge 1 commit intonuxt:mainfrom
maximepvrt:update-custom-fetch

Conversation

@maximepvrt
Copy link
Copy Markdown
Contributor

@maximepvrt maximepvrt commented Apr 22, 2026

use the new createUseFetch

🔗 Linked issue

📚 Description

@maximepvrt maximepvrt requested a review from danielroe as a code owner April 22, 2026 21:20
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2026

@maximepvrt is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

The pull request refactors a custom fetch composable from an explicit function declaration to a factory-based approach using createUseFetch, with the custom $fetch implementation now injected via callback. Additionally, Nuxt-related framework dependencies are upgraded to version 4.4.2 in the root resolutions block, and @nuxt/ui is bumped to 4.6.1 in the shared package configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description provides a clear title 'use the new createUseFetch' that directly relates to the changeset, which updates the custom fetch composable to use createUseFetch.
Title check ✅ Passed The title accurately reflects the main change: refactoring useCustomFetch to use createUseFetch, which is the primary modification across the composable files and dependency updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

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

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@examples/advanced/use-custom-fetch-composable/composables/useCustomFetch.ts`:
- Around line 1-4: The factory callback in useCustomFetch currently spreads
callerOptions into the returned object which allows a caller-provided $fetch to
override the intended useNuxtApp().$customFetch; update the callback for
createUseFetch (in useCustomFetch) to return only $fetch:
useNuxtApp().$customFetch (and any other fixed defaults) and remove the
...callerOptions spread so $customFetch is enforced via the callback override
mechanism (keep callerOptions passed to createUseFetch as-is but do not merge it
into the factory return), ensuring plugins/customFetch.ts auth/401 handling
remains in effect.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9f8f0b69-f8b7-46d2-8e88-d970edb0031c

📥 Commits

Reviewing files that changed from the base of the PR and between 891eedf and 1d24122.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • examples/advanced/use-custom-fetch-composable/composables/useCustomFetch.ts
  • package.json
  • shared/package.json

Comment on lines +1 to +4
export const useCustomFetch = createUseFetch(callerOptions => ({
$fetch: useNuxtApp().$customFetch as typeof $fetch,
...callerOptions,
})) No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Inspect the installed/resolved Nuxt version's createUseFetch implementation.
# Expected: callback/factory options are applied after caller opts, so factory-returned `$fetch` overrides caller `$fetch`.

set -euo pipefail

version="$(jq -r '
  [
    .dependencies.nuxt?,
    .devDependencies.nuxt?,
    .resolutions.nuxt?,
    .overrides.nuxt?
  ] | map(select(. != null)) | first // empty
' package.json | sed 's/^[^0-9]*//')"

if [ -z "$version" ]; then
  echo "No Nuxt version found in root package.json"
  exit 1
fi

curl -fsSL "https://raw.githubusercontent.com/nuxt/nuxt/v${version}/packages/nuxt/src/app/composables/fetch.ts" \
  | rg -n -C 6 'Merge factory options|typeof options === .function|factoryOptions'

Repository: nuxt/examples

Length of output: 2081


Keep $customFetch as the enforced fetch implementation.

Spreading callerOptions after $fetch in the factory callback allows a caller-provided $fetch to override $customFetch, bypassing auth header and 401 handling from plugins/customFetch.ts.

In Nuxt's callback mode (function option to createUseFetch), the factory-returned object merges after user options (applying as overrides). By spreading callerOptions inside the return, you're including the user's options in factoryOptions, which means if the user passed $fetch, it ends up in both places—with the later spread in factoryOptions retaining the user's value rather than the intended $customFetch.

Remove the callerOptions spread so the factory return enforces $customFetch via the callback override mechanism:

Proposed fix
-export const useCustomFetch = createUseFetch(callerOptions => ({
+export const useCustomFetch = createUseFetch(() => ({
   $fetch: useNuxtApp().$customFetch as typeof $fetch,
-  ...callerOptions,
 }))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/advanced/use-custom-fetch-composable/composables/useCustomFetch.ts`
around lines 1 - 4, The factory callback in useCustomFetch currently spreads
callerOptions into the returned object which allows a caller-provided $fetch to
override the intended useNuxtApp().$customFetch; update the callback for
createUseFetch (in useCustomFetch) to return only $fetch:
useNuxtApp().$customFetch (and any other fixed defaults) and remove the
...callerOptions spread so $customFetch is enforced via the callback override
mechanism (keep callerOptions passed to createUseFetch as-is but do not merge it
into the factory return), ensuring plugins/customFetch.ts auth/401 handling
remains in effect.

@maximepvrt maximepvrt changed the title udpate custom fetch feat: refactor useCustomFetch to use createUseFetch Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant