( query: Query<TQueryFnData, TError, TData, TQueryKey>, result: QueryObserverResult<TDataHydratable, TError>, )
| 77 | * dehydrated state attached as `hydrationData`. On the client, the result as is. |
| 78 | */ |
| 79 | const hydratableObserverResult = < |
| 80 | TQueryFnData, |
| 81 | TError, |
| 82 | TData, |
| 83 | TQueryKey extends QueryKey, |
| 84 | TDataHydratable, |
| 85 | >( |
| 86 | query: Query<TQueryFnData, TError, TData, TQueryKey>, |
| 87 | result: QueryObserverResult<TDataHydratable, TError>, |
| 88 | ) => { |
| 89 | if (!isServer) return result |
| 90 | const obj: any = { |
| 91 | ...unwrap(result), |
| 92 | // During SSR, functions cannot be serialized, so we need to remove them |
| 93 | // This is safe because we will add these functions back when the query is hydrated |
| 94 | refetch: undefined, |
| 95 | } |
| 96 | |
| 97 | // If the query is an infinite query, we need to remove additional properties |
| 98 | if ('fetchNextPage' in result) { |
| 99 | obj.fetchNextPage = undefined |
| 100 | obj.fetchPreviousPage = undefined |
| 101 | } |
| 102 | |
| 103 | // We will also attach the dehydrated state of the query to the result |
| 104 | // This will be removed on client after hydration |
| 105 | obj.hydrationData = { |
| 106 | state: query.state, |
| 107 | queryKey: query.queryKey, |
| 108 | queryHash: query.queryHash, |
| 109 | ...(query.meta && { meta: query.meta }), |
| 110 | } |
| 111 | |
| 112 | return obj |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Base Query Function that is used to create the query. |
no test coverage detected