@fohte/storybook-addon 0.1.6 → 0.1.7

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.
@@ -71,18 +71,23 @@ const PENDING_FETCH_TIMEOUT_MS = 2000;
71
71
  // every other check.
72
72
  export async function waitForPendingApiRequests() {
73
73
  const { pendingFetches } = globalState();
74
- const deadline = Date.now() + PENDING_FETCH_TIMEOUT_MS;
74
+ // performance.now(), not Date.now(): a consuming app's test setup may call
75
+ // vi.setSystemTime() without vi.useFakeTimers() (e.g. to pin screenshots to
76
+ // a fixed date), which freezes Date.now() while leaving setTimeout on the
77
+ // real clock — Date.now() < deadline would then stay true forever and this
78
+ // loop would never exit on its own.
79
+ const deadline = performance.now() + PENDING_FETCH_TIMEOUT_MS;
75
80
  // A tracked fetch's own resolution can synchronously trigger another
76
81
  // tracked fetch (e.g. fetch(user).then(() => fetch(user.posts))) — re-check
77
82
  // pendingFetches after each round instead of racing a single snapshot of
78
83
  // it, so a same-story follow-up fetch is also waited for, within the same
79
84
  // overall deadline.
80
- while (pendingFetches.size > 0 && Date.now() < deadline) {
85
+ while (pendingFetches.size > 0 && performance.now() < deadline) {
81
86
  // Each iteration re-reads pendingFetches, which the previous iteration's
82
87
  // wait may have grown, so this can't be hoisted out of the loop.
83
88
  await Promise.race([
84
89
  Promise.all(pendingFetches),
85
- new Promise((resolve) => setTimeout(resolve, deadline - Date.now())),
90
+ new Promise((resolve) => setTimeout(resolve, deadline - performance.now())),
86
91
  ]);
87
92
  }
88
93
  if (pendingFetches.size > 0) {
package/package.json CHANGED
@@ -74,7 +74,7 @@
74
74
  "typescript": "6.0.3",
75
75
  "vitest": "4.1.10"
76
76
  },
77
- "version": "0.1.6",
77
+ "version": "0.1.7",
78
78
  "scripts": {
79
79
  "clean": "rimraf lib tsconfig.tsbuildinfo",
80
80
  "prebuild": "pnpm run clean",