Skip to content

Commit e794b81

Browse files
committed
memorize server snapshot
1 parent bea16ac commit e794b81

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/use-swr.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export const useSWRHandler = <Data = any, Error = any>(
164164
// unnecessary re-renders, we keep the previous snapshot and use deep
165165
// comparison to check if we need to return a new one.
166166
let memorizedSnapshot = getSelectedCache(getCache())
167+
const memorizedInitialSnapshot = getSelectedCache(getInitialCache())
167168

168169
return [
169170
() => {
@@ -172,7 +173,7 @@ export const useSWRHandler = <Data = any, Error = any>(
172173
? memorizedSnapshot
173174
: (memorizedSnapshot = newSnapshot)
174175
},
175-
() => getSelectedCache(getInitialCache())
176+
() => memorizedInitialSnapshot
176177
]
177178
// eslint-disable-next-line react-hooks/exhaustive-deps
178179
}, [cache, key])

0 commit comments

Comments
 (0)