Skip to content

Commit f8f71d1

Browse files
committed
Skip persisted queries in profile enrichment to prevent cache corruption
Persisted queries (like pinnedFeedInfos) survive across app restarts. Mutating their shape is catastrophic since corrupted data gets loaded from disk on every launch. Skip any query whose key starts with PERSISTED_QUERY_ROOT when applying enrichment mutations.
1 parent ed722d2 commit f8f71d1

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/state/queries/profile-enrichment.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {useEffect, useRef} from 'react'
22
import {type QueryClient, useQueryClient} from '@tanstack/react-query'
33

4+
import {PERSISTED_QUERY_ROOT} from '#/state/queries'
45
import {fetchRecordViaSlingshot} from './microcosm-fallback'
56

67
/**
@@ -113,6 +114,12 @@ function applyEnrichment(
113114
const data = query.state.data
114115
if (!data) continue
115116

117+
// Never mutate persisted queries -- corrupting their shape is catastrophic
118+
// since persisted data survives across app restarts.
119+
const queryKey = query.queryKey
120+
if (Array.isArray(queryKey) && queryKey[0] === PERSISTED_QUERY_ROOT)
121+
continue
122+
116123
const mutated = mutateProfilesInData(
117124
data,
118125
did,
@@ -122,10 +129,9 @@ function applyEnrichment(
122129
)
123130
if (mutated) {
124131
// Suppress our own subscriber from re-scanning this update.
125-
// Must preserve data type: arrays stay arrays, objects stay objects.
126132
isApplyingEnrichment = true
127133
queryClient.setQueryData(
128-
query.queryKey,
134+
queryKey,
129135
Array.isArray(data) ? [...data] : {...(data as any)},
130136
)
131137
isApplyingEnrichment = false

0 commit comments

Comments
 (0)