Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/vue-apollo-composable/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,21 @@ export function useQueryImpl<
query: currentDocument,
variables: currentVariables ?? {} as TVariables,
...currentOptions.value,
...(isServer && currentOptions.value?.fetchPolicy !== 'no-cache')
? {
fetchPolicy: 'network-only',
}
: {},
})

startQuerySubscription()

// Make the cache data available to the component immediately
// This prevents SSR hydration mismatches
if (!isServer && (firstStart || !currentOptions.value?.keepPreviousResult) && (currentOptions.value?.fetchPolicy !== 'no-cache' || currentOptions.value.notifyOnNetworkStatusChange)) {
if ((firstStart || !currentOptions.value?.keepPreviousResult) && (currentOptions.value?.fetchPolicy !== 'no-cache' || currentOptions.value.notifyOnNetworkStatusChange)) {
const currentResult = query.value.getCurrentResult(false)

if (!currentResult.loading || currentResult.partial || currentOptions.value?.notifyOnNetworkStatusChange) {
// SSR: Allow reusing cached results
// CSR: Allow showing cached results immediately, but also show loading state if the query is currently loading and not showing partial data
const ssrCheck = isServer && currentOptions.value?.prefetch !== false && !currentResult.loading
const csrCheck = !isServer && (!currentResult.loading || currentResult.partial || currentOptions.value?.notifyOnNetworkStatusChange)

if (ssrCheck || csrCheck) {
onNextResult(currentResult)
ignoreNextResult = !currentResult.loading
}
Expand Down
4 changes: 0 additions & 4 deletions packages/vue-apollo-option/src/smart-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export default class SmartQuery extends SmartApollo {
})
}

if (isServer) {
this.options.fetchPolicy = 'network-only'
}

if (!options.manual) {
this.hasDataField = Object.prototype.hasOwnProperty.call(this.vm.$data, key)
if (this.hasDataField) {
Expand Down
Loading