@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.
@@ -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 even when offline
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
- // Add a fallback timeout to ensure the callback fires even if the DurableStore
187
- // ready event doesn't properly trigger when offline
188
- if (wrappedCallback && !shareSync._socketIsOpen) {
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] Socket offline - forcing onReadyCallback after timeout');
194
+ console.warn('[ShareSync] DurableStore ready timeout - forcing callback after 5s');
192
195
  wrappedCallback();
193
196
  }
194
- }, 100); // Small delay to allow normal initialization first
197
+ }, 5000); // 5 second safety timeout
195
198
  }
196
199
  return connection;
197
200
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"