Skip to content

Commit 4ae96c0

Browse files
committed
refactor(filen-mobile): optimize thumbnail effect lifecycle
Use generateRef in the trigger effect with empty deps to avoid re-triggering generation on callback identity changes. Merge the cleanup effect into the generation trigger effect.
1 parent bea674f commit 4ae96c0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

packages/filen-mobile/src/components/drive/item/thumbnail.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const Thumbnail = memo(
4949
[item.data.uuid],
5050
() => {
5151
abortControllerRef.current?.abort()
52+
5253
abortControllerRef.current = null
5354
errorRetryCountRef.current = 0
5455
}
@@ -140,9 +141,15 @@ const Thumbnail = memo(
140141
errorRetryCountRef.current = 0
141142

142143
if (!localPathRef.current) {
143-
generate()
144+
generateRef.current?.()
144145
}
145-
}, [generate])
146+
147+
return () => {
148+
abortControllerRef.current?.abort()
149+
150+
abortControllerRef.current = null
151+
}
152+
}, [])
146153

147154
const source = useMemo(
148155
() => ({
@@ -159,14 +166,6 @@ const Thumbnail = memo(
159166
[size.thumbnail]
160167
)
161168

162-
useEffect(() => {
163-
return () => {
164-
abortControllerRef.current?.abort()
165-
166-
abortControllerRef.current = null
167-
}
168-
}, [])
169-
170169
useEffect(() => {
171170
if (!isVideo) {
172171
return

0 commit comments

Comments
 (0)