mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix: useFetch with customized $fetch losing original event during ssr.
This commit is contained in:
parent
74e847bd90
commit
b8e36828aa
@ -1,12 +1,12 @@
|
|||||||
import type { FetchError, FetchOptions } from 'ofetch'
|
|
||||||
import type { NitroFetchRequest, TypedInternalResponse, AvailableRouterMethod as _AvailableRouterMethod } from 'nitro/types'
|
import type { NitroFetchRequest, TypedInternalResponse, AvailableRouterMethod as _AvailableRouterMethod } from 'nitro/types'
|
||||||
|
import type { FetchError, FetchOptions } from 'ofetch'
|
||||||
|
import { hash } from 'ohash'
|
||||||
import type { MaybeRef, Ref } from 'vue'
|
import type { MaybeRef, Ref } from 'vue'
|
||||||
import { computed, reactive, toValue } from 'vue'
|
import { computed, reactive, toValue } from 'vue'
|
||||||
import { hash } from 'ohash'
|
|
||||||
|
|
||||||
import { useRequestFetch } from './ssr'
|
|
||||||
import type { AsyncData, AsyncDataOptions, KeysOf, MultiWatchSources, PickFrom } from './asyncData'
|
import type { AsyncData, AsyncDataOptions, KeysOf, MultiWatchSources, PickFrom } from './asyncData'
|
||||||
import { useAsyncData } from './asyncData'
|
import { useAsyncData } from './asyncData'
|
||||||
|
import { useRequestFetch } from './ssr'
|
||||||
|
|
||||||
// @ts-expect-error virtual file
|
// @ts-expect-error virtual file
|
||||||
import { fetchDefaults } from '#build/nuxt.config.mjs'
|
import { fetchDefaults } from '#build/nuxt.config.mjs'
|
||||||
@ -170,7 +170,7 @@ export function useFetch<
|
|||||||
let _$fetch = opts.$fetch || globalThis.$fetch
|
let _$fetch = opts.$fetch || globalThis.$fetch
|
||||||
|
|
||||||
// Use fetch with request context and headers for server direct API calls
|
// Use fetch with request context and headers for server direct API calls
|
||||||
if (import.meta.server && !opts.$fetch) {
|
if (import.meta.server) {
|
||||||
const isLocalFetch = typeof _request.value === 'string' && _request.value[0] === '/' && (!toValue(opts.baseURL) || toValue(opts.baseURL)![0] === '/')
|
const isLocalFetch = typeof _request.value === 'string' && _request.value[0] === '/' && (!toValue(opts.baseURL) || toValue(opts.baseURL)![0] === '/')
|
||||||
if (isLocalFetch) {
|
if (isLocalFetch) {
|
||||||
_$fetch = useRequestFetch()
|
_$fetch = useRequestFetch()
|
||||||
|
Loading…
Reference in New Issue
Block a user