@shaxpir/duiduidui-models 1.9.1 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/repo/ShareSync.js +10 -7
- package/package.json +1 -1
package/dist/repo/ShareSync.js
CHANGED
|
@@ -157,12 +157,14 @@ class ShareSync {
|
|
|
157
157
|
}
|
|
158
158
|
createConnectionWithDurableStore(socket, options) {
|
|
159
159
|
const shareSync = this;
|
|
160
|
-
// Create a wrapper callback that ensures it's called
|
|
160
|
+
// Create a wrapper callback that ensures it's called exactly once
|
|
161
|
+
// The callback should fire when DurableStore is ready, regardless of socket state
|
|
162
|
+
// This enables offline-first operation where local data is available immediately
|
|
161
163
|
let readyCallbackInvoked = false;
|
|
162
164
|
const wrappedCallback = options.onReadyCallback ? function () {
|
|
163
165
|
if (!readyCallbackInvoked) {
|
|
164
166
|
readyCallbackInvoked = true;
|
|
165
|
-
shareSync._debug && console.log('[ShareSync] DurableStore ready, invoking onReadyCallback');
|
|
167
|
+
shareSync._debug && console.log('[ShareSync] DurableStore ready, invoking onReadyCallback (socket open:', shareSync._socketIsOpen, ')');
|
|
166
168
|
options.onReadyCallback();
|
|
167
169
|
}
|
|
168
170
|
} : undefined;
|
|
@@ -183,15 +185,16 @@ class ShareSync {
|
|
|
183
185
|
onReadyCallback: wrappedCallback
|
|
184
186
|
}
|
|
185
187
|
});
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
|
|
188
|
+
// The DurableStore's 'ready' event fires when local storage initialization completes.
|
|
189
|
+
// This happens regardless of socket/network state, enabling offline-first operation.
|
|
190
|
+
// Add a safety timeout in case storage initialization hangs (should never happen).
|
|
191
|
+
if (wrappedCallback) {
|
|
189
192
|
setTimeout(function () {
|
|
190
193
|
if (!readyCallbackInvoked) {
|
|
191
|
-
console.warn('[ShareSync]
|
|
194
|
+
console.warn('[ShareSync] DurableStore ready timeout - forcing callback after 5s');
|
|
192
195
|
wrappedCallback();
|
|
193
196
|
}
|
|
194
|
-
},
|
|
197
|
+
}, 5000); // 5 second safety timeout
|
|
195
198
|
}
|
|
196
199
|
return connection;
|
|
197
200
|
}
|