@@ -74,7 +74,17 @@ class OnyxConnectionManager {
74
74
private lastCallbackID : number ;
75
75
76
76
/**
77
- * Stores the last generated session ID for the connection manager.
77
+ * Stores the last generated session ID for the connection manager. The current session ID
78
+ * is appended to the connection IDs and it's used to create new different connections for the same key
79
+ * when `refreshSessionID()` is called.
80
+ *
81
+ * When calling `Onyx.clear()` after a logout operation some connections might remain active as they
82
+ * aren't tied to the React's lifecycle e.g. `Onyx.connect()` usage, causing infinite loading state issues to new `useOnyx()` subscribers
83
+ * that are connecting to the same key as we didn't populate the cache again because we are still reusing such connections.
84
+ *
85
+ * To elimitate this problem, the session ID must be refreshed during the `Onyx.clear()` call (by using `refreshSessionID()`)
86
+ * in order to create fresh connections when new subscribers connect to the same keys again, allowing them
87
+ * to use the cache system correctly and avoid the mentioned issues in `useOnyx()`.
78
88
*/
79
89
private sessionID : string ;
80
90
@@ -97,7 +107,7 @@ class OnyxConnectionManager {
97
107
const { key, initWithStoredValues, reuseConnection, waitForCollectionCallback} = connectOptions ;
98
108
99
109
// The current session ID is appended to the connection ID so we can have different connections
100
- // after an Onyx.clear() operation.
110
+ // after an ` Onyx.clear()` operation.
101
111
let suffix = `,sessionID=${ this . sessionID } ` ;
102
112
103
113
// We will generate a unique ID in any of the following situations:
@@ -239,9 +249,7 @@ class OnyxConnectionManager {
239
249
}
240
250
241
251
/**
242
- * Refreshes the connection manager's session ID. Used in Onyx.clear() in order to
243
- * create new connections after Onyx is cleared, instead of reusing existing connections
244
- * that can produce unexpected behavior in Onyx subscribers.
252
+ * Refreshes the connection manager's session ID.
245
253
*/
246
254
refreshSessionID ( ) : void {
247
255
this . sessionID = Str . guid ( ) ;
0 commit comments