@@ -24,7 +24,7 @@ export function useProjectAttachments({
24
24
projectId : string
25
25
projectMeta : WithActionHash < ProjectMeta >
26
26
} ) {
27
- // ✅ Call hooks unconditionally at the top level
27
+ // Call hooks unconditionally at the top level
28
28
const [ attachmentWALs , setAttachmentWALs ] = useState < WAL [ ] | null > ( null )
29
29
const [ attachmentsInfo , setAttachmentsInfo ] = useState < ProjectAssetMeta [ ] > ( [ ] )
30
30
const [ error , setError ] = useState ( null )
@@ -43,9 +43,10 @@ export function useProjectAttachments({
43
43
// Ensure cleanup if subscription exists from a previous valid run
44
44
if (
45
45
subscriptionRef . current &&
46
- typeof subscriptionRef . current . unsubscribe === 'function'
46
+ typeof subscriptionRef . current === 'function'
47
47
) {
48
- subscriptionRef . current . unsubscribe ( )
48
+ const unsubscribe = subscriptionRef . current ;
49
+ unsubscribe ( )
49
50
}
50
51
subscriptionRef . current = null
51
52
return // Exit effect early
@@ -66,14 +67,15 @@ export function useProjectAttachments({
66
67
// Clean up any existing subscription before creating a new one
67
68
if (
68
69
subscriptionRef . current &&
69
- typeof subscriptionRef . current . unsubscribe === 'function'
70
+ typeof subscriptionRef . current === 'function'
70
71
) {
71
- subscriptionRef . current . unsubscribe ( )
72
+ const unsubscribe = subscriptionRef . current ;
73
+ unsubscribe ( )
72
74
}
73
75
subscriptionRef . current = null
74
76
75
77
try {
76
- const subscription = weaveClient . assets
78
+ const unsubscribe = weaveClient . assets
77
79
. assetStore ( wal )
78
80
. subscribe ( async ( store ) => {
79
81
if ( store . status === 'complete' ) {
@@ -102,7 +104,7 @@ export function useProjectAttachments({
102
104
} )
103
105
104
106
// Store the subscription object properly
105
- subscriptionRef . current = subscription
107
+ subscriptionRef . current = unsubscribe
106
108
} catch ( err ) {
107
109
setError ( err )
108
110
}
@@ -114,9 +116,10 @@ export function useProjectAttachments({
114
116
return ( ) => {
115
117
if (
116
118
subscriptionRef . current &&
117
- typeof subscriptionRef . current . unsubscribe === 'function'
119
+ typeof subscriptionRef . current === 'function'
118
120
) {
119
- subscriptionRef . current . unsubscribe ( )
121
+ const unsubscribe = subscriptionRef . current ;
122
+ unsubscribe ( ) ;
120
123
}
121
124
subscriptionRef . current = null
122
125
}
0 commit comments