@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/index.cjs CHANGED
@@ -472,6 +472,11 @@ var CloudStorageAdapter = class {
472
472
  }
473
473
  /* ─── StorageAdapter v2 ───────────────────────────────────────────── */
474
474
  async load(_namespace) {
475
+ if (!this.cachedToken || this.isExpired(this.cachedToken)) {
476
+ const fresh = this.readStoredToken();
477
+ if (!fresh || this.isExpired(fresh)) return [];
478
+ this.cachedToken = fresh;
479
+ }
475
480
  const out = [];
476
481
  let cursor = null;
477
482
  do {
@@ -3189,6 +3194,14 @@ var Vizu = class {
3189
3194
  this.selfHealedThisSession = /* @__PURE__ */ new Set();
3190
3195
  this.actions = [];
3191
3196
  this.user = null;
3197
+ /**
3198
+ * Flipped true once the initial loadComments() at construction has
3199
+ * settled (success or failure). The cloud onAuthChanged callback uses
3200
+ * this to decide whether a subsequent auth change should trigger a
3201
+ * re-load: skipped for the initial fire (the explicit loadComments
3202
+ * below handles it), fired for every later token acquisition.
3203
+ */
3204
+ this.hasLoadedComments = false;
3192
3205
  this.enabled = false;
3193
3206
  this.rafScheduled = false;
3194
3207
  this.bus = new EventBus();
@@ -3264,6 +3277,9 @@ var Vizu = class {
3264
3277
  _defaultStorage,
3265
3278
  (info) => {
3266
3279
  if (info.user) this.setUser(info.user);
3280
+ if (this.hasLoadedComments) {
3281
+ void this.loadComments();
3282
+ }
3267
3283
  }
3268
3284
  );
3269
3285
  if (options.actions) this.actions = [...options.actions];
@@ -3271,7 +3287,11 @@ var Vizu = class {
3271
3287
  if (options.onCommentRemoved) this.bus.on("comment:removed", (p) => options.onCommentRemoved(p.id));
3272
3288
  if (typeof window !== "undefined") {
3273
3289
  window.addEventListener("keydown", this.onKeyDown);
3274
- void this.loadComments().then(() => this.subscribeStorage());
3290
+ void this.loadComments().catch(() => {
3291
+ }).finally(() => {
3292
+ this.hasLoadedComments = true;
3293
+ this.subscribeStorage();
3294
+ });
3275
3295
  if (options.startEnabled) this.deferred(() => this.enable());
3276
3296
  }
3277
3297
  }