@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.js CHANGED
@@ -436,6 +436,11 @@ var CloudStorageAdapter = class {
436
436
  }
437
437
  /* ─── StorageAdapter v2 ───────────────────────────────────────────── */
438
438
  async load(_namespace) {
439
+ if (!this.cachedToken || this.isExpired(this.cachedToken)) {
440
+ const fresh = this.readStoredToken();
441
+ if (!fresh || this.isExpired(fresh)) return [];
442
+ this.cachedToken = fresh;
443
+ }
439
444
  const out = [];
440
445
  let cursor = null;
441
446
  do {
@@ -3153,6 +3158,14 @@ var Vizu = class {
3153
3158
  this.selfHealedThisSession = /* @__PURE__ */ new Set();
3154
3159
  this.actions = [];
3155
3160
  this.user = null;
3161
+ /**
3162
+ * Flipped true once the initial loadComments() at construction has
3163
+ * settled (success or failure). The cloud onAuthChanged callback uses
3164
+ * this to decide whether a subsequent auth change should trigger a
3165
+ * re-load: skipped for the initial fire (the explicit loadComments
3166
+ * below handles it), fired for every later token acquisition.
3167
+ */
3168
+ this.hasLoadedComments = false;
3156
3169
  this.enabled = false;
3157
3170
  this.rafScheduled = false;
3158
3171
  this.bus = new EventBus();
@@ -3228,6 +3241,9 @@ var Vizu = class {
3228
3241
  _defaultStorage,
3229
3242
  (info) => {
3230
3243
  if (info.user) this.setUser(info.user);
3244
+ if (this.hasLoadedComments) {
3245
+ void this.loadComments();
3246
+ }
3231
3247
  }
3232
3248
  );
3233
3249
  if (options.actions) this.actions = [...options.actions];
@@ -3235,7 +3251,11 @@ var Vizu = class {
3235
3251
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
3236
3252
  if (typeof window !== "undefined") {
3237
3253
  window.addEventListener("keydown", this.onKeyDown);
3238
- void this.loadComments().then(() => this.subscribeStorage());
3254
+ void this.loadComments().catch(() => {
3255
+ }).finally(() => {
3256
+ this.hasLoadedComments = true;
3257
+ this.subscribeStorage();
3258
+ });
3239
3259
  if (options.startEnabled) this.deferred(() => this.enable());
3240
3260
  }
3241
3261
  }