Skip to content

Commit ceff5db

Browse files
authored
Merge pull request #155 from danybeltran/fix-cancel-ssrsuspense
fix(cancel, SSRSuspense):
2 parents 6456c0b + a11a071 commit ceff5db

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-react",
3-
"version": "2.9.7",
3+
"version": "2.9.8",
44
"description": "React hooks for data fetching",
55
"main": "dist/index.js",
66
"scripts": {

src/components/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { FetchContextType } from '../types'
1515

1616
import { isDefined, serialize } from '../utils/shared'
1717

18-
let isServer: boolean
18+
let isServer: boolean = true
1919
/**
2020
* This is a wrapper around `Suspense`. It will render `fallback` during the first render and then leave the rendering to `Suspense`. If you are not using SSR, you should continue using the `Suspense` component.
2121
*/
@@ -26,13 +26,11 @@ export function SSRSuspense({
2626
fallback?: React.ReactNode
2727
children?: React.ReactNode
2828
}) {
29-
const [ssr, setSSR] = useState(isDefined(isServer) ? isServer : true)
29+
const [ssr, setSSR] = useState(isServer)
3030

3131
useEffect(() => {
32-
if (!isDefined(isServer)) {
33-
setSSR(false)
34-
isServer = false
35-
}
32+
setSSR(false)
33+
isServer = false
3634
}, [])
3735

3836
// This will render the fallback in the server

src/hooks/use-fetch.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,14 @@ export function useFetch<FetchDataType = any, BodyType = any>(
11781178
suspenseInitialized[resolvedKey] = true
11791179
}
11801180
}
1181+
useEffect(() => {
1182+
if (url !== '') {
1183+
if (!jsonCompare(previousProps[resolvedKey], optionsConfig)) {
1184+
abortControllers[resolvedKey]?.abort()
1185+
queue(initializeRevalidation)
1186+
}
1187+
}
1188+
}, [serialize(optionsConfig)])
11811189

11821190
if (suspense) {
11831191
if (auto) {

0 commit comments

Comments
 (0)