| 150 | } |
| 151 | |
| 152 | const suspense = () => { |
| 153 | return new Promise<QueryObserverResult<TData, TError>>( |
| 154 | (resolve, reject) => { |
| 155 | let stopWatch = () => { |
| 156 | // noop |
| 157 | } |
| 158 | const run = () => { |
| 159 | if (defaultedOptions.value.enabled !== false) { |
| 160 | // fix #6133 |
| 161 | observer.setOptions(defaultedOptions.value) |
| 162 | const optimisticResult = observer.getOptimisticResult( |
| 163 | defaultedOptions.value, |
| 164 | ) |
| 165 | if (optimisticResult.isStale) { |
| 166 | stopWatch() |
| 167 | observer |
| 168 | .fetchOptimistic(defaultedOptions.value) |
| 169 | .then(resolve, (error: TError) => { |
| 170 | if ( |
| 171 | shouldThrowError(defaultedOptions.value.throwOnError, [ |
| 172 | error, |
| 173 | observer.getCurrentQuery(), |
| 174 | ]) |
| 175 | ) { |
| 176 | reject(error) |
| 177 | } else { |
| 178 | resolve(observer.getCurrentResult()) |
| 179 | } |
| 180 | }) |
| 181 | } else { |
| 182 | stopWatch() |
| 183 | resolve(optimisticResult) |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | run() |
| 189 | |
| 190 | stopWatch = watch(defaultedOptions, run) |
| 191 | }, |
| 192 | ) |
| 193 | } |
| 194 | |
| 195 | // Handle error boundary |
| 196 | watch( |