Skip to content

Commit 416175f

Browse files
authored
Merge pull request Expensify#65425 from callstack-internal/Accounting-Loading-icon-and-sync-status-messages-are-not-displayed
Accounting-Loading icon and sync status messages are not displayed
2 parents 08515a5 + a846e7b commit 416175f

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/libs/Pusher/index.native.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,39 @@ function getChannel(channelName: string): PusherChannel | undefined {
8888
return socket.getChannel(channelName);
8989
}
9090

91+
/**
92+
* Parses JSON data that may be single or double-encoded
93+
* This handles cases where the backend sometimes sends double-encoded JSON
94+
* Reference issue: https://github.com/Expensify/App/issues/60332
95+
*/
96+
function parseEventData<EventName extends PusherEventName>(eventData: EventData<EventName>): EventData<EventName> | null {
97+
if (isObject(eventData)) {
98+
return eventData;
99+
}
100+
101+
if (typeof eventData !== 'string') {
102+
Log.alert('[Pusher] Event data is neither object nor string', {eventData});
103+
return null;
104+
}
105+
106+
try {
107+
const firstParse = JSON.parse(eventData) as EventData<EventName> | string;
108+
109+
// If result is still a string, it was double-encoded - parse again
110+
if (typeof firstParse === 'string') {
111+
return JSON.parse(firstParse) as EventData<EventName>;
112+
}
113+
114+
return firstParse;
115+
} catch (error) {
116+
Log.alert('[Pusher] Failed to parse event data', {
117+
error: error instanceof Error ? error.message : 'Unknown error',
118+
eventData,
119+
});
120+
return null;
121+
}
122+
}
123+
91124
/**
92125
* Binds an event callback to a channel + eventName
93126
*/
@@ -103,11 +136,9 @@ function bindEventToChannel<EventName extends PusherEventName>(channel: string,
103136
return;
104137
}
105138

106-
let data: EventData<EventName>;
107-
try {
108-
data = isObject(eventData) ? eventData : (JSON.parse(eventData) as EventData<EventName>);
109-
} catch (err) {
110-
Log.alert('[Pusher] Unable to parse single JSON event data from Pusher', {error: err, eventData});
139+
const data = parseEventData(eventData);
140+
if (!data) {
141+
// Error already logged in parseEventData
111142
return;
112143
}
113144
if (data.id === undefined || data.chunk === undefined || data.final === undefined) {

0 commit comments

Comments
 (0)