1
1
import { useQuery , useApolloClient } from '@apollo/client'
2
2
import { SSR } from '../lib/constants'
3
- import { GET_NEW_COMMENTS , COMMENT_WITH_NEW } from '../fragments/comments'
3
+ import { GET_NEW_COMMENTS , COMMENT_WITH_NEW , COMMENT_WITH_NEW_LIMITED } from '../fragments/comments'
4
4
import { ITEM_FULL } from '../fragments/items'
5
5
import { useEffect , useRef , useState } from 'react'
6
6
@@ -60,7 +60,7 @@ export function itemUpdateQuery (client, id, sort, fn) {
60
60
61
61
// update the newComments field of a nested comment fragment
62
62
export function commentUpdateFragment ( client , id , fn ) {
63
- const result = client . cache . updateFragment ( {
63
+ let result = client . cache . updateFragment ( {
64
64
id : `Item:${ id } ` ,
65
65
fragment : COMMENT_WITH_NEW ,
66
66
fragmentName : 'CommentWithNew'
@@ -69,6 +69,19 @@ export function commentUpdateFragment (client, id, fn) {
69
69
return fn ( data )
70
70
} )
71
71
72
+ // sometimes comments can reach their depth limit, and lack adherence to the CommentsRecursive fragment
73
+ // for this reason, we update the fragment with a limited version that only includes the CommentFields fragment
74
+ if ( ! result ) {
75
+ result = client . cache . updateFragment ( {
76
+ id : `Item:${ id } ` ,
77
+ fragment : COMMENT_WITH_NEW_LIMITED ,
78
+ fragmentName : 'CommentWithNewLimited'
79
+ } , ( data ) => {
80
+ if ( ! data ) return data
81
+ return fn ( data )
82
+ } )
83
+ }
84
+
72
85
return result
73
86
}
74
87
0 commit comments