@unhingged/vizu-core 0.1.8 → 0.1.9

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/auto.cjs CHANGED
@@ -462,6 +462,11 @@ var CloudStorageAdapter = class {
462
462
  }
463
463
  /* ─── StorageAdapter v2 ───────────────────────────────────────────── */
464
464
  async load(_namespace) {
465
+ if (!this.cachedToken || this.isExpired(this.cachedToken)) {
466
+ const fresh = this.readStoredToken();
467
+ if (!fresh || this.isExpired(fresh)) return [];
468
+ this.cachedToken = fresh;
469
+ }
465
470
  const out = [];
466
471
  let cursor = null;
467
472
  do {
@@ -3179,6 +3184,14 @@ var Vizu = class {
3179
3184
  this.selfHealedThisSession = /* @__PURE__ */ new Set();
3180
3185
  this.actions = [];
3181
3186
  this.user = null;
3187
+ /**
3188
+ * Flipped true once the initial loadComments() at construction has
3189
+ * settled (success or failure). The cloud onAuthChanged callback uses
3190
+ * this to decide whether a subsequent auth change should trigger a
3191
+ * re-load: skipped for the initial fire (the explicit loadComments
3192
+ * below handles it), fired for every later token acquisition.
3193
+ */
3194
+ this.hasLoadedComments = false;
3182
3195
  this.enabled = false;
3183
3196
  this.rafScheduled = false;
3184
3197
  this.bus = new EventBus();
@@ -3254,6 +3267,9 @@ var Vizu = class {
3254
3267
  _defaultStorage,
3255
3268
  (info) => {
3256
3269
  if (info.user) this.setUser(info.user);
3270
+ if (this.hasLoadedComments) {
3271
+ void this.loadComments();
3272
+ }
3257
3273
  }
3258
3274
  );
3259
3275
  if (options.actions) this.actions = [...options.actions];
@@ -3261,7 +3277,11 @@ var Vizu = class {
3261
3277
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
3262
3278
  if (typeof window !== "undefined") {
3263
3279
  window.addEventListener("keydown", this.onKeyDown);
3264
- void this.loadComments().then(() => this.subscribeStorage());
3280
+ void this.loadComments().catch(() => {
3281
+ }).finally(() => {
3282
+ this.hasLoadedComments = true;
3283
+ this.subscribeStorage();
3284
+ });
3265
3285
  if (options.startEnabled) this.deferred(() => this.enable());
3266
3286
  }
3267
3287
  }