Skip to content

Commit

Permalink
fix(solid-query): Fix Infinite Query SSR payload (#6909)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardeora authored Feb 16, 2024
1 parent 8a2e8a5 commit e23e6f2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/solid-query/src/createBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { CreateBaseQueryOptions } from './types'
import type { Accessor } from 'solid-js'
import type { QueryClient } from './QueryClient'
import type {
InfiniteQueryObserverResult,
Query,
QueryKey,
QueryObserver,
Expand All @@ -47,7 +48,8 @@ function reconcileFn<TData, TError>(
}

type HydratableQueryState<TData, TError> = QueryObserverResult<TData, TError> &
QueryState<TData, TError>
QueryState<TData, TError> &
InfiniteQueryObserverResult<TData, TError>

/**
* Solid's `onHydrated` functionality will silently "fail" (hydrate with an empty object)
Expand All @@ -62,7 +64,7 @@ const hydratableObserverResult = <
>(
query: Query<TQueryFnData, TError, TData, TQueryKey>,
result: QueryObserverResult<TDataHydratable, TError>,
): HydratableQueryState<TDataHydratable, TError> => {
) => {
// Including the extra properties is only relevant on the server
if (!isServer) return result as HydratableQueryState<TDataHydratable, TError>

Expand All @@ -76,6 +78,18 @@ const hydratableObserverResult = <
TError
>['refetch'],

// cast to fetchNextPage function should be safe, since we only remove it on the server,
fetchNextPage: undefined as unknown as HydratableQueryState<
TDataHydratable,
TError
>['fetchNextPage'],

// cast to fetchPreviousPage function should be safe, since we only remove it on the server,
fetchPreviousPage: undefined as unknown as HydratableQueryState<
TDataHydratable,
TError
>['fetchPreviousPage'],

// hydrate() expects a QueryState object, which is similar but not
// quite the same as a QueryObserverResult object. Thus, for now, we're
// copying over the missing properties from state in order to support hydration
Expand All @@ -86,7 +100,7 @@ const hydratableObserverResult = <
// Unsetting these properties on the server since they might not be serializable
fetchFailureReason: null,
fetchMeta: null,
}
} as HydratableQueryState<TDataHydratable, TError>
}

// Base Query Function that is used to create the query.
Expand Down

0 comments on commit e23e6f2

Please sign in to comment.