@workflow/web 5.1.0 → 5.2.0
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/build/client/assets/app-DSMA-d-h.css +1 -0
- package/build/client/assets/{arrow-up-right-KWrqnTig.js → arrow-up-right-Cpa3Pdwo.js} +1 -1
- package/build/client/assets/{highlighted-body-JLMTFACH-DcETTNIg.js → highlighted-body-JLMTFACH-B3GqULNn.js} +1 -1
- package/build/client/assets/{home-DXDIbwXs.js → home-D79hgIWW.js} +18 -1412
- package/build/client/assets/{loader-circle-CTGjdS9p.js → loader-circle-JR85kUd5.js} +1 -1
- package/build/client/assets/manifest-59ebdf79.js +1 -0
- package/build/client/assets/{mermaid-WFAXDIZX-C05IxJpM.js → mermaid-WFAXDIZX-CWiYj6ob.js} +21920 -21866
- package/build/client/assets/root-Cv68eh5c.css +1 -0
- package/build/client/assets/{root-BxCk7uqa.js → root-DgYJfBXO.js} +24 -9
- package/build/client/assets/{run-detail-CZBOEgvx.js → run-detail-Befe_Bls.js} +1868 -1952
- package/build/client/assets/{index-DsOfMZH2.js → url-state-DtiYSmtM.js} +1520 -95
- package/build/client/assets/{zstd-browser-decoder-DADxxRqK.js → zstd-browser-decoder-feFoAFP-.js} +1 -1
- package/build/server/assets/{app-DT6Gt-BX.js → app-BXJVj0oU.js} +22544 -25746
- package/build/server/assets/{highlighted-body-JLMTFACH-CHR6of_B.js → highlighted-body-JLMTFACH-DBscEG8Y.js} +2 -4
- package/build/server/assets/{index-puMiLsWF.js → index-DFAOTIzy.js} +276 -87
- package/build/server/assets/{mermaid-WFAXDIZX-D-xr2vKt.js → mermaid-WFAXDIZX-hv3921YS.js} +2 -4
- package/build/server/assets/{token-D41jJA1K.js → token-BPk8AzMN.js} +2 -2
- package/build/server/assets/{token-CwT5ChW-.js → token-CXneDSmI.js} +1 -1
- package/build/server/assets/{token-util-DqfRGa3d.js → token-util-C_CN233b.js} +1 -1
- package/build/server/assets/{token-util-BJpBdFnQ.js → token-util-lTSClVuJ.js} +2 -2
- package/build/server/assets/{wrapper-Cr0R902L.js → wrapper-CaZIHABu.js} +10 -12
- package/build/server/assets/{zstd-browser-decoder-B48pzCro.js → zstd-browser-decoder-XCzFkM-Z.js} +2 -4
- package/build/server/index.js +3 -5
- package/package.json +10 -10
- package/build/client/assets/app-C_84j2Id.css +0 -1
- package/build/client/assets/manifest-d238ca03.js +0 -1
- package/build/client/assets/root-DUrWgRk7.css +0 -1
- package/build/server/assets/dist-BQmT5wQz.js +0 -210
- /package/build/client/assets/{index-C9ccOmbh.css → url-state-C9ccOmbh.css} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as reactExports, j as jsxRuntimeExports, z as Link,
|
|
2
|
-
import { R as ResolveHookModal, S as Send,
|
|
3
|
-
import { c as createLucideIcon, h as useToast, e as cn, i as
|
|
4
|
-
import { L as LoaderCircle } from "./loader-circle-
|
|
1
|
+
import { r as reactExports, j as jsxRuntimeExports, z as Link, f as reactDomExports, B as useSearchParams, A as useNavigate, C as useLocation, w as withComponentProps } from "./index-BS6T0Zjc.js";
|
|
2
|
+
import { R as ResolveHookModal, S as Send, u as unwrapOrThrow, W as WorkflowWebAPIError, f as fetchHookToken, a as Skeleton, b as RelativeTime, A as Alert, C as CircleAlert, c as AlertTitle, g as getErrorTitle, d as AlertDescription, e as getErrorMessage, h as CopyableText, D as DropdownMenu, i as DropdownMenuTrigger, E as Ellipsis, j as DropdownMenuContent, k as DropdownMenuItem, r as resumeHook, l as useDirection, m as createCollection, n as hideOthers, o as useFocusGuards, p as ReactRemoveScroll, q as ChevronUp, X, s as useWorkflowRunsInfinite, t as bulkCancelRuns, v as reenqueueRun, w as parseWorkflowName, x as StatusBadge, Z as Zap, y as CircleX, z as RunActionsDropdownItems, B as Dialog, F as DialogContent, G as DialogClose, H as DialogTitle, I as DialogDescription, J as DialogPortal, K as DialogOverlay, L as unwrapServerActionResult, M as WorkflowGraphViewer, N as useOptimisticSearchParams, T as Tabs, O as TabsList, P as TabsTrigger, Q as TabsContent, U as ErrorBoundary } from "./url-state-DtiYSmtM.js";
|
|
3
|
+
import { c as createLucideIcon, h as useToast, e as cn, i as fetchHooks, j as getPaginationDisplay, T as Tooltip, a as TooltipTrigger, C as Check, k as Copy, b as TooltipContent, D as DEFAULT_PAGE_SIZE, B as Button, l as ChevronRight, m as fetchEvents, n as useComposedRefs, o as useLayoutEffect2, P as Primitive, p as useControllableState, q as useId, s as Popper, V as VISUALLY_HIDDEN_STYLES, v as createPopperScope, w as createContextScope, x as PopperAnchor, y as composeEventHandlers, z as Portal, A as Presence, F as FocusScope, E as DismissableLayer, G as PopperContent, H as useCallbackRef, J as createSlot, K as ChevronDown, L as useSize, u as useServerConfig, M as BULK_CANCEL_MAX_RUN_IDS, t as toast, N as fetchRun, O as cva, Q as fetchWorkflowsManifest } from "./mermaid-WFAXDIZX-CWiYj6ob.js";
|
|
4
|
+
import { L as LoaderCircle } from "./loader-circle-JR85kUd5.js";
|
|
5
5
|
/**
|
|
6
6
|
* @license lucide-react v0.575.0 - ISC
|
|
7
7
|
*
|
|
@@ -288,1398 +288,6 @@ const TableCaption = reactExports.forwardRef(({ className, ...props }, ref) => /
|
|
|
288
288
|
}
|
|
289
289
|
));
|
|
290
290
|
TableCaption.displayName = "TableCaption";
|
|
291
|
-
var shimExports = requireShim();
|
|
292
|
-
var has = Object.prototype.hasOwnProperty;
|
|
293
|
-
function dequal(foo, bar) {
|
|
294
|
-
var ctor, len;
|
|
295
|
-
if (foo === bar) return true;
|
|
296
|
-
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
297
|
-
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
298
|
-
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
299
|
-
if (ctor === Array) {
|
|
300
|
-
if ((len = foo.length) === bar.length) {
|
|
301
|
-
while (len-- && dequal(foo[len], bar[len])) ;
|
|
302
|
-
}
|
|
303
|
-
return len === -1;
|
|
304
|
-
}
|
|
305
|
-
if (!ctor || typeof foo === "object") {
|
|
306
|
-
len = 0;
|
|
307
|
-
for (ctor in foo) {
|
|
308
|
-
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
309
|
-
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
|
310
|
-
}
|
|
311
|
-
return Object.keys(bar).length === len;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return foo !== foo && bar !== bar;
|
|
315
|
-
}
|
|
316
|
-
const FOCUS_EVENT = 0;
|
|
317
|
-
const RECONNECT_EVENT = 1;
|
|
318
|
-
const MUTATE_EVENT = 2;
|
|
319
|
-
const ERROR_REVALIDATE_EVENT = 3;
|
|
320
|
-
const UNLOAD_EVENT = 4;
|
|
321
|
-
const SWRGlobalState = /* @__PURE__ */ new WeakMap();
|
|
322
|
-
const noop = () => {
|
|
323
|
-
};
|
|
324
|
-
const UNDEFINED = (
|
|
325
|
-
/*#__NOINLINE__*/
|
|
326
|
-
noop()
|
|
327
|
-
);
|
|
328
|
-
const OBJECT = Object;
|
|
329
|
-
const isUndefined = (v) => v === UNDEFINED;
|
|
330
|
-
const isFunction$2 = (v) => typeof v == "function";
|
|
331
|
-
const mergeObjects = (a, b) => ({
|
|
332
|
-
...a,
|
|
333
|
-
...b
|
|
334
|
-
});
|
|
335
|
-
const isPromiseLike = (x) => isFunction$2(x.then);
|
|
336
|
-
const EMPTY_CACHE = {};
|
|
337
|
-
const INITIAL_CACHE = {};
|
|
338
|
-
const STR_UNDEFINED = "undefined";
|
|
339
|
-
const isWindowDefined = typeof window != STR_UNDEFINED;
|
|
340
|
-
const isDocumentDefined = typeof document != STR_UNDEFINED;
|
|
341
|
-
const isLegacyDeno = isWindowDefined && "Deno" in window;
|
|
342
|
-
const hasRequestAnimationFrame = () => isWindowDefined && typeof window["requestAnimationFrame"] != STR_UNDEFINED;
|
|
343
|
-
const createCacheHelper = (cache2, key) => {
|
|
344
|
-
const state = SWRGlobalState.get(cache2);
|
|
345
|
-
return [
|
|
346
|
-
// Getter
|
|
347
|
-
() => !isUndefined(key) && cache2.get(key) || EMPTY_CACHE,
|
|
348
|
-
// Setter
|
|
349
|
-
(info) => {
|
|
350
|
-
if (!isUndefined(key)) {
|
|
351
|
-
const prev = cache2.get(key);
|
|
352
|
-
if (!(key in INITIAL_CACHE)) {
|
|
353
|
-
INITIAL_CACHE[key] = prev;
|
|
354
|
-
}
|
|
355
|
-
state[5](key, mergeObjects(prev, info), prev || EMPTY_CACHE);
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
// Subscriber
|
|
359
|
-
state[6],
|
|
360
|
-
// Get server cache snapshot
|
|
361
|
-
() => {
|
|
362
|
-
if (!isUndefined(key)) {
|
|
363
|
-
if (key in INITIAL_CACHE) return INITIAL_CACHE[key];
|
|
364
|
-
}
|
|
365
|
-
return !isUndefined(key) && cache2.get(key) || EMPTY_CACHE;
|
|
366
|
-
}
|
|
367
|
-
];
|
|
368
|
-
};
|
|
369
|
-
let online = true;
|
|
370
|
-
const isOnline = () => online;
|
|
371
|
-
const [onWindowEvent, offWindowEvent] = isWindowDefined && window.addEventListener ? [
|
|
372
|
-
window.addEventListener.bind(window),
|
|
373
|
-
window.removeEventListener.bind(window)
|
|
374
|
-
] : [
|
|
375
|
-
noop,
|
|
376
|
-
noop
|
|
377
|
-
];
|
|
378
|
-
const isVisible = () => {
|
|
379
|
-
const visibilityState = isDocumentDefined && document.visibilityState;
|
|
380
|
-
return isUndefined(visibilityState) || visibilityState !== "hidden";
|
|
381
|
-
};
|
|
382
|
-
const initFocus = (callback) => {
|
|
383
|
-
if (isDocumentDefined) {
|
|
384
|
-
document.addEventListener("visibilitychange", callback);
|
|
385
|
-
}
|
|
386
|
-
onWindowEvent("focus", callback);
|
|
387
|
-
return () => {
|
|
388
|
-
if (isDocumentDefined) {
|
|
389
|
-
document.removeEventListener("visibilitychange", callback);
|
|
390
|
-
}
|
|
391
|
-
offWindowEvent("focus", callback);
|
|
392
|
-
};
|
|
393
|
-
};
|
|
394
|
-
const initReconnect = (callback) => {
|
|
395
|
-
const onOnline = () => {
|
|
396
|
-
online = true;
|
|
397
|
-
callback();
|
|
398
|
-
};
|
|
399
|
-
const onOffline = () => {
|
|
400
|
-
online = false;
|
|
401
|
-
};
|
|
402
|
-
onWindowEvent("online", onOnline);
|
|
403
|
-
onWindowEvent("offline", onOffline);
|
|
404
|
-
return () => {
|
|
405
|
-
offWindowEvent("online", onOnline);
|
|
406
|
-
offWindowEvent("offline", onOffline);
|
|
407
|
-
};
|
|
408
|
-
};
|
|
409
|
-
const preset = {
|
|
410
|
-
isOnline,
|
|
411
|
-
isVisible
|
|
412
|
-
};
|
|
413
|
-
const defaultConfigOptions = {
|
|
414
|
-
initFocus,
|
|
415
|
-
initReconnect
|
|
416
|
-
};
|
|
417
|
-
const IS_REACT_LEGACY = !ReactExports.useId;
|
|
418
|
-
const IS_SERVER = !isWindowDefined || isLegacyDeno;
|
|
419
|
-
const rAF = (f) => hasRequestAnimationFrame() ? window["requestAnimationFrame"](f) : setTimeout(f, 1);
|
|
420
|
-
const useIsomorphicLayoutEffect = IS_SERVER ? reactExports.useEffect : reactExports.useLayoutEffect;
|
|
421
|
-
const navigatorConnection = typeof navigator !== "undefined" && navigator.connection;
|
|
422
|
-
const slowConnection = !IS_SERVER && navigatorConnection && ([
|
|
423
|
-
"slow-2g",
|
|
424
|
-
"2g"
|
|
425
|
-
].includes(navigatorConnection.effectiveType) || navigatorConnection.saveData);
|
|
426
|
-
const table = /* @__PURE__ */ new WeakMap();
|
|
427
|
-
const getTypeName = (value) => OBJECT.prototype.toString.call(value);
|
|
428
|
-
const isObjectTypeName = (typeName, type) => typeName === `[object ${type}]`;
|
|
429
|
-
let counter = 0;
|
|
430
|
-
const stableHash = (arg) => {
|
|
431
|
-
const type = typeof arg;
|
|
432
|
-
const typeName = getTypeName(arg);
|
|
433
|
-
const isDate = isObjectTypeName(typeName, "Date");
|
|
434
|
-
const isRegex = isObjectTypeName(typeName, "RegExp");
|
|
435
|
-
const isPlainObject = isObjectTypeName(typeName, "Object");
|
|
436
|
-
let result;
|
|
437
|
-
let index;
|
|
438
|
-
if (OBJECT(arg) === arg && !isDate && !isRegex) {
|
|
439
|
-
result = table.get(arg);
|
|
440
|
-
if (result) return result;
|
|
441
|
-
result = ++counter + "~";
|
|
442
|
-
table.set(arg, result);
|
|
443
|
-
if (Array.isArray(arg)) {
|
|
444
|
-
result = "@";
|
|
445
|
-
for (index = 0; index < arg.length; index++) {
|
|
446
|
-
result += stableHash(arg[index]) + ",";
|
|
447
|
-
}
|
|
448
|
-
table.set(arg, result);
|
|
449
|
-
}
|
|
450
|
-
if (isPlainObject) {
|
|
451
|
-
result = "#";
|
|
452
|
-
const keys = OBJECT.keys(arg).sort();
|
|
453
|
-
while (!isUndefined(index = keys.pop())) {
|
|
454
|
-
if (!isUndefined(arg[index])) {
|
|
455
|
-
result += index + ":" + stableHash(arg[index]) + ",";
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
table.set(arg, result);
|
|
459
|
-
}
|
|
460
|
-
} else {
|
|
461
|
-
result = isDate ? arg.toJSON() : type == "symbol" ? arg.toString() : type == "string" ? JSON.stringify(arg) : "" + arg;
|
|
462
|
-
}
|
|
463
|
-
return result;
|
|
464
|
-
};
|
|
465
|
-
const serialize = (key) => {
|
|
466
|
-
if (isFunction$2(key)) {
|
|
467
|
-
try {
|
|
468
|
-
key = key();
|
|
469
|
-
} catch (err) {
|
|
470
|
-
key = "";
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
const args = key;
|
|
474
|
-
key = typeof key == "string" ? key : (Array.isArray(key) ? key.length : key) ? stableHash(key) : "";
|
|
475
|
-
return [
|
|
476
|
-
key,
|
|
477
|
-
args
|
|
478
|
-
];
|
|
479
|
-
};
|
|
480
|
-
let __timestamp = 0;
|
|
481
|
-
const getTimestamp = () => ++__timestamp;
|
|
482
|
-
async function internalMutate(...args) {
|
|
483
|
-
const [cache2, _key, _data, _opts] = args;
|
|
484
|
-
const options = mergeObjects({
|
|
485
|
-
populateCache: true,
|
|
486
|
-
throwOnError: true
|
|
487
|
-
}, typeof _opts === "boolean" ? {
|
|
488
|
-
revalidate: _opts
|
|
489
|
-
} : _opts || {});
|
|
490
|
-
let populateCache = options.populateCache;
|
|
491
|
-
const rollbackOnErrorOption = options.rollbackOnError;
|
|
492
|
-
let optimisticData = options.optimisticData;
|
|
493
|
-
const rollbackOnError = (error) => {
|
|
494
|
-
return typeof rollbackOnErrorOption === "function" ? rollbackOnErrorOption(error) : rollbackOnErrorOption !== false;
|
|
495
|
-
};
|
|
496
|
-
const throwOnError = options.throwOnError;
|
|
497
|
-
if (isFunction$2(_key)) {
|
|
498
|
-
const keyFilter = _key;
|
|
499
|
-
const matchedKeys = [];
|
|
500
|
-
const it = cache2.keys();
|
|
501
|
-
for (const key of it) {
|
|
502
|
-
if (
|
|
503
|
-
// Skip the special useSWRInfinite and useSWRSubscription keys.
|
|
504
|
-
!/^\$(inf|sub)\$/.test(key) && keyFilter(cache2.get(key)._k)
|
|
505
|
-
) {
|
|
506
|
-
matchedKeys.push(key);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
return Promise.all(matchedKeys.map(mutateByKey));
|
|
510
|
-
}
|
|
511
|
-
return mutateByKey(_key);
|
|
512
|
-
async function mutateByKey(_k) {
|
|
513
|
-
const [key] = serialize(_k);
|
|
514
|
-
if (!key) return;
|
|
515
|
-
const [get, set] = createCacheHelper(cache2, key);
|
|
516
|
-
const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache2);
|
|
517
|
-
const startRevalidate = () => {
|
|
518
|
-
const revalidators = EVENT_REVALIDATORS[key];
|
|
519
|
-
const revalidate = isFunction$2(options.revalidate) ? options.revalidate(get().data, _k) : options.revalidate !== false;
|
|
520
|
-
if (revalidate) {
|
|
521
|
-
delete FETCH[key];
|
|
522
|
-
delete PRELOAD[key];
|
|
523
|
-
if (revalidators && revalidators[0]) {
|
|
524
|
-
return revalidators[0](MUTATE_EVENT).then(() => get().data);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return get().data;
|
|
528
|
-
};
|
|
529
|
-
if (args.length < 3) {
|
|
530
|
-
return startRevalidate();
|
|
531
|
-
}
|
|
532
|
-
let data = _data;
|
|
533
|
-
let error;
|
|
534
|
-
let isError = false;
|
|
535
|
-
const beforeMutationTs = getTimestamp();
|
|
536
|
-
MUTATION[key] = [
|
|
537
|
-
beforeMutationTs,
|
|
538
|
-
0
|
|
539
|
-
];
|
|
540
|
-
const hasOptimisticData = !isUndefined(optimisticData);
|
|
541
|
-
const state = get();
|
|
542
|
-
const displayedData = state.data;
|
|
543
|
-
const currentData = state._c;
|
|
544
|
-
const committedData = isUndefined(currentData) ? displayedData : currentData;
|
|
545
|
-
if (hasOptimisticData) {
|
|
546
|
-
optimisticData = isFunction$2(optimisticData) ? optimisticData(committedData, displayedData) : optimisticData;
|
|
547
|
-
set({
|
|
548
|
-
data: optimisticData,
|
|
549
|
-
_c: committedData
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
if (isFunction$2(data)) {
|
|
553
|
-
try {
|
|
554
|
-
data = data(committedData);
|
|
555
|
-
} catch (err) {
|
|
556
|
-
error = err;
|
|
557
|
-
isError = true;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
if (data && isPromiseLike(data)) {
|
|
561
|
-
data = await data.catch((err) => {
|
|
562
|
-
error = err;
|
|
563
|
-
isError = true;
|
|
564
|
-
});
|
|
565
|
-
if (beforeMutationTs !== MUTATION[key][0]) {
|
|
566
|
-
if (isError) throw error;
|
|
567
|
-
return data;
|
|
568
|
-
} else if (isError && hasOptimisticData && rollbackOnError(error)) {
|
|
569
|
-
populateCache = true;
|
|
570
|
-
set({
|
|
571
|
-
data: committedData,
|
|
572
|
-
_c: UNDEFINED
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
if (populateCache) {
|
|
577
|
-
if (!isError) {
|
|
578
|
-
if (isFunction$2(populateCache)) {
|
|
579
|
-
const populateCachedData = populateCache(data, committedData);
|
|
580
|
-
set({
|
|
581
|
-
data: populateCachedData,
|
|
582
|
-
error: UNDEFINED,
|
|
583
|
-
_c: UNDEFINED
|
|
584
|
-
});
|
|
585
|
-
} else {
|
|
586
|
-
set({
|
|
587
|
-
data,
|
|
588
|
-
error: UNDEFINED,
|
|
589
|
-
_c: UNDEFINED
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
MUTATION[key][1] = getTimestamp();
|
|
595
|
-
Promise.resolve(startRevalidate()).then(() => {
|
|
596
|
-
set({
|
|
597
|
-
_c: UNDEFINED
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
if (isError) {
|
|
601
|
-
if (throwOnError) throw error;
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
return data;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
const revalidateAllKeys = (revalidators, type) => {
|
|
608
|
-
for (const key in revalidators) {
|
|
609
|
-
if (revalidators[key][0]) revalidators[key][0](type);
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
const initCache = (provider, options) => {
|
|
613
|
-
if (!SWRGlobalState.has(provider)) {
|
|
614
|
-
const opts = mergeObjects(defaultConfigOptions, options);
|
|
615
|
-
const EVENT_REVALIDATORS = /* @__PURE__ */ Object.create(null);
|
|
616
|
-
const mutate2 = internalMutate.bind(UNDEFINED, provider);
|
|
617
|
-
let unmount = noop;
|
|
618
|
-
const subscriptions = /* @__PURE__ */ Object.create(null);
|
|
619
|
-
const subscribe = (key, callback) => {
|
|
620
|
-
const subs = subscriptions[key] || [];
|
|
621
|
-
subscriptions[key] = subs;
|
|
622
|
-
subs.push(callback);
|
|
623
|
-
return () => {
|
|
624
|
-
const index = subs.indexOf(callback);
|
|
625
|
-
if (index >= 0) {
|
|
626
|
-
subs[index] = subs[subs.length - 1];
|
|
627
|
-
subs.pop();
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
};
|
|
631
|
-
const setter = (key, value, prev) => {
|
|
632
|
-
provider.set(key, value);
|
|
633
|
-
const subs = subscriptions[key];
|
|
634
|
-
if (subs) {
|
|
635
|
-
for (const fn of subs) {
|
|
636
|
-
fn(value, prev);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
const unload2 = (unloadOptions) => {
|
|
641
|
-
const state2 = SWRGlobalState.get(provider);
|
|
642
|
-
const [, MUTATION, FETCH, PRELOAD] = state2;
|
|
643
|
-
const ts = getTimestamp();
|
|
644
|
-
state2[8]++;
|
|
645
|
-
for (const key in FETCH) delete FETCH[key];
|
|
646
|
-
for (const key in PRELOAD) delete PRELOAD[key];
|
|
647
|
-
for (const key in MUTATION) MUTATION[key] = [
|
|
648
|
-
ts,
|
|
649
|
-
ts
|
|
650
|
-
];
|
|
651
|
-
const emptyState = {};
|
|
652
|
-
for (const key of [
|
|
653
|
-
...provider.keys()
|
|
654
|
-
]) {
|
|
655
|
-
const prev = provider.get(key);
|
|
656
|
-
provider.delete(key);
|
|
657
|
-
const subs = subscriptions[key];
|
|
658
|
-
if (subs) {
|
|
659
|
-
for (const fn of subs) {
|
|
660
|
-
fn(emptyState, prev);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
const revalidate = !unloadOptions || unloadOptions.revalidate !== false;
|
|
665
|
-
for (const key in EVENT_REVALIDATORS) {
|
|
666
|
-
const revalidators = EVENT_REVALIDATORS[key];
|
|
667
|
-
for (let i = 0; i < revalidators.length; i++) {
|
|
668
|
-
revalidators[i](UNLOAD_EVENT, {
|
|
669
|
-
revalidate: revalidate && !i
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
const initProvider = () => {
|
|
675
|
-
if (!SWRGlobalState.has(provider)) {
|
|
676
|
-
SWRGlobalState.set(provider, [
|
|
677
|
-
EVENT_REVALIDATORS,
|
|
678
|
-
/* @__PURE__ */ Object.create(null),
|
|
679
|
-
/* @__PURE__ */ Object.create(null),
|
|
680
|
-
/* @__PURE__ */ Object.create(null),
|
|
681
|
-
mutate2,
|
|
682
|
-
setter,
|
|
683
|
-
subscribe,
|
|
684
|
-
unload2,
|
|
685
|
-
0
|
|
686
|
-
]);
|
|
687
|
-
if (!IS_SERVER) {
|
|
688
|
-
const releaseFocus = opts.initFocus(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, FOCUS_EVENT)));
|
|
689
|
-
const releaseReconnect = opts.initReconnect(setTimeout.bind(UNDEFINED, revalidateAllKeys.bind(UNDEFINED, EVENT_REVALIDATORS, RECONNECT_EVENT)));
|
|
690
|
-
unmount = () => {
|
|
691
|
-
releaseFocus && releaseFocus();
|
|
692
|
-
releaseReconnect && releaseReconnect();
|
|
693
|
-
SWRGlobalState.delete(provider);
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
initProvider();
|
|
699
|
-
return [
|
|
700
|
-
provider,
|
|
701
|
-
mutate2,
|
|
702
|
-
initProvider,
|
|
703
|
-
unmount,
|
|
704
|
-
unload2
|
|
705
|
-
];
|
|
706
|
-
}
|
|
707
|
-
const state = SWRGlobalState.get(provider);
|
|
708
|
-
return [
|
|
709
|
-
provider,
|
|
710
|
-
state[4],
|
|
711
|
-
UNDEFINED,
|
|
712
|
-
UNDEFINED,
|
|
713
|
-
state[7]
|
|
714
|
-
];
|
|
715
|
-
};
|
|
716
|
-
const onErrorRetry = (_, __, config, revalidate, opts) => {
|
|
717
|
-
const maxRetryCount = config.errorRetryCount;
|
|
718
|
-
const currentRetryCount = opts.retryCount;
|
|
719
|
-
const timeout = ~~((Math.random() + 0.5) * (1 << (currentRetryCount < 8 ? currentRetryCount : 8))) * config.errorRetryInterval;
|
|
720
|
-
if (!isUndefined(maxRetryCount) && currentRetryCount > maxRetryCount) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
setTimeout(revalidate, timeout, opts);
|
|
724
|
-
};
|
|
725
|
-
const compare = dequal;
|
|
726
|
-
const [cache, mutate, , , unload] = initCache(/* @__PURE__ */ new Map());
|
|
727
|
-
const defaultConfig = mergeObjects(
|
|
728
|
-
{
|
|
729
|
-
// events
|
|
730
|
-
onLoadingSlow: noop,
|
|
731
|
-
onSuccess: noop,
|
|
732
|
-
onError: noop,
|
|
733
|
-
onErrorRetry,
|
|
734
|
-
onDiscarded: noop,
|
|
735
|
-
// switches
|
|
736
|
-
revalidateOnFocus: true,
|
|
737
|
-
revalidateOnReconnect: true,
|
|
738
|
-
revalidateIfStale: true,
|
|
739
|
-
shouldRetryOnError: true,
|
|
740
|
-
// timeouts
|
|
741
|
-
errorRetryInterval: slowConnection ? 1e4 : 5e3,
|
|
742
|
-
focusThrottleInterval: 5 * 1e3,
|
|
743
|
-
dedupingInterval: 2 * 1e3,
|
|
744
|
-
loadingTimeout: slowConnection ? 5e3 : 3e3,
|
|
745
|
-
// providers
|
|
746
|
-
compare,
|
|
747
|
-
isPaused: () => false,
|
|
748
|
-
cache,
|
|
749
|
-
mutate,
|
|
750
|
-
unload,
|
|
751
|
-
fallback: {}
|
|
752
|
-
},
|
|
753
|
-
// use web preset by default
|
|
754
|
-
preset
|
|
755
|
-
);
|
|
756
|
-
const mergeConfigs = (a, b) => {
|
|
757
|
-
const v = mergeObjects(a, b);
|
|
758
|
-
if (b) {
|
|
759
|
-
const { use: u1, fallback: f1, cacheData: c1 } = a;
|
|
760
|
-
const { use: u2, fallback: f2, cacheData: c2 } = b;
|
|
761
|
-
if (u1 && u2) {
|
|
762
|
-
v.use = u1.concat(u2);
|
|
763
|
-
}
|
|
764
|
-
if (f1 && f2) {
|
|
765
|
-
v.fallback = mergeObjects(f1, f2);
|
|
766
|
-
}
|
|
767
|
-
if (c1 && c2) {
|
|
768
|
-
v.cacheData = mergeObjects(c1, c2);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
return v;
|
|
772
|
-
};
|
|
773
|
-
const SWRConfigContext = reactExports.createContext({});
|
|
774
|
-
const INFINITE_PREFIX = "$inf$";
|
|
775
|
-
const enableDevtools = isWindowDefined && window.__SWR_DEVTOOLS_USE__;
|
|
776
|
-
const use$1 = enableDevtools ? window.__SWR_DEVTOOLS_USE__ : [];
|
|
777
|
-
const setupDevTools = () => {
|
|
778
|
-
if (enableDevtools) {
|
|
779
|
-
window.__SWR_DEVTOOLS_REACT__ = ReactExports;
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
const normalize = (args) => {
|
|
783
|
-
return isFunction$2(args[1]) ? [
|
|
784
|
-
args[0],
|
|
785
|
-
args[1],
|
|
786
|
-
args[2] || {}
|
|
787
|
-
] : [
|
|
788
|
-
args[0],
|
|
789
|
-
null,
|
|
790
|
-
(args[1] === null ? args[2] : args[1]) || {}
|
|
791
|
-
];
|
|
792
|
-
};
|
|
793
|
-
const useSWRConfig = () => {
|
|
794
|
-
const parentConfig = reactExports.useContext(SWRConfigContext);
|
|
795
|
-
const mergedConfig = reactExports.useMemo(() => mergeObjects(defaultConfig, parentConfig), [
|
|
796
|
-
parentConfig
|
|
797
|
-
]);
|
|
798
|
-
return mergedConfig;
|
|
799
|
-
};
|
|
800
|
-
const middleware = (useSWRNext) => (key_, fetcher_, config) => {
|
|
801
|
-
const fetcher = fetcher_ && ((...args) => {
|
|
802
|
-
const [key] = serialize(key_);
|
|
803
|
-
const [, , , PRELOAD] = SWRGlobalState.get(cache);
|
|
804
|
-
if (key.startsWith(INFINITE_PREFIX)) {
|
|
805
|
-
return fetcher_(...args);
|
|
806
|
-
}
|
|
807
|
-
const req = PRELOAD[key];
|
|
808
|
-
if (isUndefined(req)) return fetcher_(...args);
|
|
809
|
-
delete PRELOAD[key];
|
|
810
|
-
return req;
|
|
811
|
-
});
|
|
812
|
-
return useSWRNext(key_, fetcher, config);
|
|
813
|
-
};
|
|
814
|
-
const BUILT_IN_MIDDLEWARE = use$1.concat(middleware);
|
|
815
|
-
const withArgs = (hook) => {
|
|
816
|
-
return function useSWRArgs(...args) {
|
|
817
|
-
const fallbackConfig = useSWRConfig();
|
|
818
|
-
const [key, fn, _config] = normalize(args);
|
|
819
|
-
const config = mergeConfigs(fallbackConfig, _config);
|
|
820
|
-
let next = hook;
|
|
821
|
-
const { use: use2 } = config;
|
|
822
|
-
const middleware2 = (use2 || []).concat(BUILT_IN_MIDDLEWARE);
|
|
823
|
-
for (let i = middleware2.length; i--; ) {
|
|
824
|
-
next = middleware2[i](next);
|
|
825
|
-
}
|
|
826
|
-
return next(key, fn || config.fetcher || null, config);
|
|
827
|
-
};
|
|
828
|
-
};
|
|
829
|
-
const subscribeCallback = (key, callbacks, callback) => {
|
|
830
|
-
const keyedRevalidators = callbacks[key] || (callbacks[key] = []);
|
|
831
|
-
keyedRevalidators.push(callback);
|
|
832
|
-
return () => {
|
|
833
|
-
const index = keyedRevalidators.indexOf(callback);
|
|
834
|
-
if (index >= 0) {
|
|
835
|
-
keyedRevalidators[index] = keyedRevalidators[keyedRevalidators.length - 1];
|
|
836
|
-
keyedRevalidators.pop();
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
};
|
|
840
|
-
const withMiddleware = (useSWR2, middleware2) => {
|
|
841
|
-
return (...args) => {
|
|
842
|
-
const [key, fn, config] = normalize(args);
|
|
843
|
-
const uses = (config.use || []).concat(middleware2);
|
|
844
|
-
return useSWR2(key, fn, {
|
|
845
|
-
...config,
|
|
846
|
-
use: uses
|
|
847
|
-
});
|
|
848
|
-
};
|
|
849
|
-
};
|
|
850
|
-
setupDevTools();
|
|
851
|
-
const use = ReactExports.use || // This extra generic is to avoid TypeScript mixing up the generic and JSX sytax
|
|
852
|
-
// and emitting an error.
|
|
853
|
-
// We assume that this is only for the `use(thenable)` case, not `use(context)`.
|
|
854
|
-
// https://github.com/facebook/react/blob/aed00dacfb79d17c53218404c52b1c7aa59c4a89/packages/react-server/src/ReactFizzThenable.js#L45
|
|
855
|
-
((thenable) => {
|
|
856
|
-
switch (thenable.status) {
|
|
857
|
-
case "pending":
|
|
858
|
-
throw thenable;
|
|
859
|
-
case "fulfilled":
|
|
860
|
-
return thenable.value;
|
|
861
|
-
case "rejected":
|
|
862
|
-
throw thenable.reason;
|
|
863
|
-
default:
|
|
864
|
-
thenable.status = "pending";
|
|
865
|
-
thenable.then((v) => {
|
|
866
|
-
thenable.status = "fulfilled";
|
|
867
|
-
thenable.value = v;
|
|
868
|
-
}, (e) => {
|
|
869
|
-
thenable.status = "rejected";
|
|
870
|
-
thenable.reason = e;
|
|
871
|
-
});
|
|
872
|
-
throw thenable;
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
const WITH_DEDUPE = {
|
|
876
|
-
dedupe: true
|
|
877
|
-
};
|
|
878
|
-
const isCacheDataConsumed = (consumedCacheData, cacheData, key) => {
|
|
879
|
-
var _consumedCacheData_get;
|
|
880
|
-
return cacheData ? ((_consumedCacheData_get = consumedCacheData.get(cacheData)) == null ? void 0 : _consumedCacheData_get.has(key)) === true : false;
|
|
881
|
-
};
|
|
882
|
-
const markCacheDataConsumed = (consumedCacheData, cacheData, key) => {
|
|
883
|
-
if (!cacheData) return;
|
|
884
|
-
let consumedKeys = consumedCacheData.get(cacheData);
|
|
885
|
-
if (!consumedKeys) {
|
|
886
|
-
consumedKeys = /* @__PURE__ */ new Set();
|
|
887
|
-
consumedCacheData.set(cacheData, consumedKeys);
|
|
888
|
-
}
|
|
889
|
-
consumedKeys.add(key);
|
|
890
|
-
};
|
|
891
|
-
const commitCacheData = ({ value, getCacheData, canCommit, setCache }) => {
|
|
892
|
-
const commit = (state) => {
|
|
893
|
-
if (canCommit() && isUndefined(getCacheData())) {
|
|
894
|
-
setCache(state);
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
Promise.resolve(value).then((data) => {
|
|
898
|
-
commit({
|
|
899
|
-
data,
|
|
900
|
-
error: UNDEFINED
|
|
901
|
-
});
|
|
902
|
-
}, (error) => {
|
|
903
|
-
commit({
|
|
904
|
-
error
|
|
905
|
-
});
|
|
906
|
-
});
|
|
907
|
-
};
|
|
908
|
-
const resolvedUndef = Promise.resolve(UNDEFINED);
|
|
909
|
-
resolvedUndef.status = "fulfilled";
|
|
910
|
-
resolvedUndef.value = UNDEFINED;
|
|
911
|
-
const sub = () => noop;
|
|
912
|
-
const useSWRHandler = (_key, fetcher, config) => {
|
|
913
|
-
const { cache: cache2, compare: compare2, suspense, fallbackData, revalidateOnMount, revalidateIfStale, refreshInterval, refreshWhenHidden, refreshWhenOffline, keepPreviousData, strictServerPrefetchWarning } = config;
|
|
914
|
-
const [EVENT_REVALIDATORS, MUTATION, FETCH, PRELOAD] = SWRGlobalState.get(cache2);
|
|
915
|
-
const [key, fnArg] = serialize(_key);
|
|
916
|
-
const initialMountedRef = reactExports.useRef(false);
|
|
917
|
-
const unmountedRef = reactExports.useRef(false);
|
|
918
|
-
const keyRef = reactExports.useRef(key);
|
|
919
|
-
const fetcherRef = reactExports.useRef(fetcher);
|
|
920
|
-
const configRef = reactExports.useRef(config);
|
|
921
|
-
const getConfig = () => configRef.current;
|
|
922
|
-
const isActive = () => getConfig().isVisible() && getConfig().isOnline();
|
|
923
|
-
const [getCache, setCache, subscribeCache, getInitialCache] = createCacheHelper(cache2, key);
|
|
924
|
-
const stateDependencies = reactExports.useRef({}).current;
|
|
925
|
-
const fallback = isUndefined(fallbackData) ? isUndefined(config.fallback) ? UNDEFINED : config.fallback[key] : fallbackData;
|
|
926
|
-
const serverCacheData = config.cacheData;
|
|
927
|
-
const configCacheData = !key ? UNDEFINED : serverCacheData == null ? void 0 : serverCacheData[key];
|
|
928
|
-
const req = key ? PRELOAD[key] : UNDEFINED;
|
|
929
|
-
const hasCacheData = isUndefined(req) && !isUndefined(configCacheData);
|
|
930
|
-
const preloadedData = hasCacheData ? configCacheData : req;
|
|
931
|
-
const isEqual = (prev, current) => {
|
|
932
|
-
for (const _ in stateDependencies) {
|
|
933
|
-
const t = _;
|
|
934
|
-
if (t === "data") {
|
|
935
|
-
if (!compare2(prev[t], current[t])) {
|
|
936
|
-
if (!isUndefined(prev[t])) {
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
if (!compare2(returnedData, current[t])) {
|
|
940
|
-
return false;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
} else {
|
|
944
|
-
if (current[t] !== prev[t]) {
|
|
945
|
-
return false;
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
return true;
|
|
950
|
-
};
|
|
951
|
-
const isInitialMount = !initialMountedRef.current;
|
|
952
|
-
const getSnapshot = reactExports.useMemo(() => {
|
|
953
|
-
const cachedData2 = getCache();
|
|
954
|
-
const initialData = getInitialCache();
|
|
955
|
-
const getSelectedCache = (state) => {
|
|
956
|
-
const snapshot = mergeObjects(state);
|
|
957
|
-
delete snapshot._k;
|
|
958
|
-
const shouldStartRequest = (() => {
|
|
959
|
-
if (!key) return false;
|
|
960
|
-
if (!fetcher) return false;
|
|
961
|
-
if (getConfig().isPaused()) return false;
|
|
962
|
-
if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount;
|
|
963
|
-
const data2 = !isUndefined(fallback) ? fallback : snapshot.data;
|
|
964
|
-
if (suspense && hasCacheData && isUndefined(data2)) return false;
|
|
965
|
-
if (suspense) return isUndefined(data2) || revalidateIfStale;
|
|
966
|
-
return isUndefined(data2) || revalidateIfStale;
|
|
967
|
-
})();
|
|
968
|
-
if (!shouldStartRequest) {
|
|
969
|
-
return snapshot;
|
|
970
|
-
}
|
|
971
|
-
return {
|
|
972
|
-
isValidating: true,
|
|
973
|
-
isLoading: true,
|
|
974
|
-
...snapshot
|
|
975
|
-
};
|
|
976
|
-
};
|
|
977
|
-
const clientSnapshot = getSelectedCache(cachedData2);
|
|
978
|
-
const serverSnapshot = cachedData2 === initialData ? clientSnapshot : getSelectedCache(initialData);
|
|
979
|
-
let memorizedSnapshot = clientSnapshot;
|
|
980
|
-
return [
|
|
981
|
-
() => {
|
|
982
|
-
const newSnapshot = getSelectedCache(getCache());
|
|
983
|
-
const compareResult = isEqual(newSnapshot, memorizedSnapshot);
|
|
984
|
-
if (compareResult) {
|
|
985
|
-
memorizedSnapshot.data = newSnapshot.data;
|
|
986
|
-
memorizedSnapshot.isLoading = newSnapshot.isLoading;
|
|
987
|
-
memorizedSnapshot.isValidating = newSnapshot.isValidating;
|
|
988
|
-
memorizedSnapshot.error = newSnapshot.error;
|
|
989
|
-
return memorizedSnapshot;
|
|
990
|
-
} else {
|
|
991
|
-
memorizedSnapshot = newSnapshot;
|
|
992
|
-
return newSnapshot;
|
|
993
|
-
}
|
|
994
|
-
},
|
|
995
|
-
() => serverSnapshot
|
|
996
|
-
];
|
|
997
|
-
}, [
|
|
998
|
-
cache2,
|
|
999
|
-
key
|
|
1000
|
-
]);
|
|
1001
|
-
const cached = shimExports.useSyncExternalStore(reactExports.useCallback(
|
|
1002
|
-
(callback) => subscribeCache(key, (current, prev) => {
|
|
1003
|
-
if (!isEqual(prev, current)) callback();
|
|
1004
|
-
}),
|
|
1005
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1006
|
-
[
|
|
1007
|
-
cache2,
|
|
1008
|
-
key
|
|
1009
|
-
]
|
|
1010
|
-
), getSnapshot[0], getSnapshot[1]);
|
|
1011
|
-
const hasRevalidator = EVENT_REVALIDATORS[key] && EVENT_REVALIDATORS[key].length > 0;
|
|
1012
|
-
const cachedData = cached.data;
|
|
1013
|
-
let data = isUndefined(cachedData) ? fallback && isPromiseLike(fallback) ? use(fallback) : fallback : cachedData;
|
|
1014
|
-
const error = cached.error;
|
|
1015
|
-
const laggyDataRef = reactExports.useRef(data);
|
|
1016
|
-
const consumedCacheDataRef = reactExports.useRef(UNDEFINED);
|
|
1017
|
-
let consumedCacheData = consumedCacheDataRef.current;
|
|
1018
|
-
if (!consumedCacheData) {
|
|
1019
|
-
consumedCacheData = /* @__PURE__ */ new WeakMap();
|
|
1020
|
-
consumedCacheDataRef.current = consumedCacheData;
|
|
1021
|
-
}
|
|
1022
|
-
const preloadCacheRef = reactExports.useRef(null);
|
|
1023
|
-
let returnedData = keepPreviousData ? isUndefined(cachedData) ? isUndefined(laggyDataRef.current) ? data : laggyDataRef.current : cachedData : data;
|
|
1024
|
-
const hasKeyButNoData = key && isUndefined(data);
|
|
1025
|
-
const hydrationRef = reactExports.useRef(null);
|
|
1026
|
-
!IS_SERVER && // getServerSnapshot is only called during hydration
|
|
1027
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
1028
|
-
shimExports.useSyncExternalStore(sub, () => {
|
|
1029
|
-
hydrationRef.current = false;
|
|
1030
|
-
return hydrationRef;
|
|
1031
|
-
}, () => {
|
|
1032
|
-
hydrationRef.current = true;
|
|
1033
|
-
return hydrationRef;
|
|
1034
|
-
});
|
|
1035
|
-
const isHydration = hydrationRef.current;
|
|
1036
|
-
if (strictServerPrefetchWarning && isHydration && !suspense && hasKeyButNoData) {
|
|
1037
|
-
console.warn(`Missing pre-initiated data for serialized key "${key}" during server-side rendering. Data fetching should be initiated on the server and provided to SWR via fallback data. You can set "strictServerPrefetchWarning: false" to disable this warning.`);
|
|
1038
|
-
}
|
|
1039
|
-
const shouldDoInitialRevalidation = (() => {
|
|
1040
|
-
if (!key || !fetcher) return false;
|
|
1041
|
-
if (getConfig().isPaused()) return false;
|
|
1042
|
-
if (hasRevalidator && !isUndefined(error)) return false;
|
|
1043
|
-
if (isInitialMount && !isUndefined(revalidateOnMount)) return revalidateOnMount;
|
|
1044
|
-
if (suspense && hasCacheData && hasKeyButNoData) return false;
|
|
1045
|
-
if (suspense) return isUndefined(data) ? false : revalidateIfStale;
|
|
1046
|
-
return isUndefined(data) || revalidateIfStale;
|
|
1047
|
-
})();
|
|
1048
|
-
const defaultValidatingState = isInitialMount && shouldDoInitialRevalidation;
|
|
1049
|
-
const isValidating = isUndefined(cached.isValidating) ? defaultValidatingState : cached.isValidating;
|
|
1050
|
-
const isLoading = isUndefined(cached.isLoading) ? defaultValidatingState : cached.isLoading;
|
|
1051
|
-
const revalidate = reactExports.useCallback(
|
|
1052
|
-
async (revalidateOpts) => {
|
|
1053
|
-
const currentFetcher = fetcherRef.current;
|
|
1054
|
-
if (!key || !currentFetcher || unmountedRef.current || getConfig().isPaused()) {
|
|
1055
|
-
return false;
|
|
1056
|
-
}
|
|
1057
|
-
let newData;
|
|
1058
|
-
let startAt;
|
|
1059
|
-
let loading = true;
|
|
1060
|
-
const opts = revalidateOpts || {};
|
|
1061
|
-
const shouldStartNewRequest = !FETCH[key] || !opts.dedupe;
|
|
1062
|
-
const shouldUseRSCPreload = hasCacheData && !isCacheDataConsumed(consumedCacheData, serverCacheData, key) && !isUndefined(preloadedData) && isUndefined(getCache().data);
|
|
1063
|
-
const callbackSafeguard = () => {
|
|
1064
|
-
if (IS_REACT_LEGACY) {
|
|
1065
|
-
return !unmountedRef.current && key === keyRef.current && initialMountedRef.current;
|
|
1066
|
-
}
|
|
1067
|
-
return key === keyRef.current;
|
|
1068
|
-
};
|
|
1069
|
-
const finalState = {
|
|
1070
|
-
isValidating: false,
|
|
1071
|
-
isLoading: false
|
|
1072
|
-
};
|
|
1073
|
-
const finishRequestAndUpdateState = () => {
|
|
1074
|
-
setCache(finalState);
|
|
1075
|
-
};
|
|
1076
|
-
const cleanupState = () => {
|
|
1077
|
-
const requestInfo = FETCH[key];
|
|
1078
|
-
if (requestInfo && requestInfo[1] === startAt) {
|
|
1079
|
-
delete FETCH[key];
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
const initialState = {
|
|
1083
|
-
isValidating: true
|
|
1084
|
-
};
|
|
1085
|
-
if (isUndefined(getCache().data)) {
|
|
1086
|
-
initialState.isLoading = true;
|
|
1087
|
-
}
|
|
1088
|
-
try {
|
|
1089
|
-
if (shouldStartNewRequest) {
|
|
1090
|
-
setCache(initialState);
|
|
1091
|
-
if (config.loadingTimeout && isUndefined(getCache().data)) {
|
|
1092
|
-
setTimeout(() => {
|
|
1093
|
-
if (loading && callbackSafeguard()) {
|
|
1094
|
-
getConfig().onLoadingSlow(key, config);
|
|
1095
|
-
}
|
|
1096
|
-
}, config.loadingTimeout);
|
|
1097
|
-
}
|
|
1098
|
-
if (shouldUseRSCPreload) {
|
|
1099
|
-
markCacheDataConsumed(consumedCacheData, serverCacheData, key);
|
|
1100
|
-
}
|
|
1101
|
-
FETCH[key] = [
|
|
1102
|
-
shouldUseRSCPreload ? preloadedData : currentFetcher(fnArg),
|
|
1103
|
-
getTimestamp()
|
|
1104
|
-
];
|
|
1105
|
-
if (shouldUseRSCPreload && PRELOAD[key]) {
|
|
1106
|
-
delete PRELOAD[key];
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
;
|
|
1110
|
-
[newData, startAt] = FETCH[key];
|
|
1111
|
-
newData = await newData;
|
|
1112
|
-
if (shouldStartNewRequest) {
|
|
1113
|
-
setTimeout(cleanupState, config.dedupingInterval);
|
|
1114
|
-
}
|
|
1115
|
-
if (!FETCH[key] || FETCH[key][1] !== startAt) {
|
|
1116
|
-
if (shouldStartNewRequest) {
|
|
1117
|
-
if (callbackSafeguard()) {
|
|
1118
|
-
getConfig().onDiscarded(key);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
return false;
|
|
1122
|
-
}
|
|
1123
|
-
finalState.error = UNDEFINED;
|
|
1124
|
-
const mutationInfo = MUTATION[key];
|
|
1125
|
-
if (!isUndefined(mutationInfo) && // case 1
|
|
1126
|
-
(startAt <= mutationInfo[0] || // case 2
|
|
1127
|
-
startAt <= mutationInfo[1] || // case 3
|
|
1128
|
-
mutationInfo[1] === 0)) {
|
|
1129
|
-
finishRequestAndUpdateState();
|
|
1130
|
-
if (shouldStartNewRequest) {
|
|
1131
|
-
if (callbackSafeguard()) {
|
|
1132
|
-
getConfig().onDiscarded(key);
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
return false;
|
|
1136
|
-
}
|
|
1137
|
-
const cacheData = getCache().data;
|
|
1138
|
-
finalState.data = compare2(cacheData, newData) ? cacheData : newData;
|
|
1139
|
-
if (shouldStartNewRequest) {
|
|
1140
|
-
if (callbackSafeguard()) {
|
|
1141
|
-
getConfig().onSuccess(newData, key, config);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
} catch (err) {
|
|
1145
|
-
cleanupState();
|
|
1146
|
-
const currentConfig = getConfig();
|
|
1147
|
-
const { shouldRetryOnError } = currentConfig;
|
|
1148
|
-
if (!currentConfig.isPaused()) {
|
|
1149
|
-
finalState.error = err;
|
|
1150
|
-
if (shouldStartNewRequest && callbackSafeguard()) {
|
|
1151
|
-
currentConfig.onError(err, key, currentConfig);
|
|
1152
|
-
if (shouldRetryOnError === true || isFunction$2(shouldRetryOnError) && shouldRetryOnError(err)) {
|
|
1153
|
-
if (!getConfig().revalidateOnFocus || !getConfig().revalidateOnReconnect || isActive()) {
|
|
1154
|
-
currentConfig.onErrorRetry(err, key, currentConfig, (_opts) => {
|
|
1155
|
-
const revalidators = EVENT_REVALIDATORS[key];
|
|
1156
|
-
if (revalidators && revalidators[0]) {
|
|
1157
|
-
revalidators[0](ERROR_REVALIDATE_EVENT, _opts);
|
|
1158
|
-
}
|
|
1159
|
-
}, {
|
|
1160
|
-
retryCount: (opts.retryCount || 0) + 1,
|
|
1161
|
-
dedupe: true
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
loading = false;
|
|
1169
|
-
finishRequestAndUpdateState();
|
|
1170
|
-
return true;
|
|
1171
|
-
},
|
|
1172
|
-
// `setState` is immutable, and `eventsCallback`, `fnArg`, and
|
|
1173
|
-
// `keyValidating` are depending on `key`, so we can exclude them from
|
|
1174
|
-
// the deps array.
|
|
1175
|
-
//
|
|
1176
|
-
// FIXME:
|
|
1177
|
-
// `fn` and `config` might be changed during the lifecycle,
|
|
1178
|
-
// but they might be changed every render like this.
|
|
1179
|
-
// `useSWR('key', () => fetch('/api/'), { suspense: true })`
|
|
1180
|
-
// So we omit the values from the deps array
|
|
1181
|
-
// even though it might cause unexpected behaviors.
|
|
1182
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1183
|
-
[
|
|
1184
|
-
key,
|
|
1185
|
-
cache2
|
|
1186
|
-
]
|
|
1187
|
-
);
|
|
1188
|
-
const boundMutate = reactExports.useCallback(
|
|
1189
|
-
// Use callback to make sure `keyRef.current` returns latest result every time
|
|
1190
|
-
(...args) => {
|
|
1191
|
-
return internalMutate(cache2, keyRef.current, ...args);
|
|
1192
|
-
},
|
|
1193
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1194
|
-
[]
|
|
1195
|
-
);
|
|
1196
|
-
useIsomorphicLayoutEffect(() => {
|
|
1197
|
-
const preloaded = preloadCacheRef.current;
|
|
1198
|
-
if (!preloaded) return;
|
|
1199
|
-
preloadCacheRef.current = null;
|
|
1200
|
-
markCacheDataConsumed(consumedCacheData, preloaded.cacheData, preloaded.key);
|
|
1201
|
-
if (isUndefined(getCache().data)) {
|
|
1202
|
-
setCache({
|
|
1203
|
-
data: preloaded.data,
|
|
1204
|
-
error: UNDEFINED,
|
|
1205
|
-
_k: preloaded._k
|
|
1206
|
-
});
|
|
1207
|
-
}
|
|
1208
|
-
if (PRELOAD[preloaded.key]) {
|
|
1209
|
-
delete PRELOAD[preloaded.key];
|
|
1210
|
-
}
|
|
1211
|
-
});
|
|
1212
|
-
useIsomorphicLayoutEffect(() => {
|
|
1213
|
-
fetcherRef.current = fetcher;
|
|
1214
|
-
configRef.current = config;
|
|
1215
|
-
if (!isUndefined(cachedData)) {
|
|
1216
|
-
laggyDataRef.current = cachedData;
|
|
1217
|
-
}
|
|
1218
|
-
});
|
|
1219
|
-
useIsomorphicLayoutEffect(() => {
|
|
1220
|
-
if (fetcher || !hasCacheData || isUndefined(preloadedData) || isCacheDataConsumed(consumedCacheData, serverCacheData, key) || !isUndefined(getCache().data)) {
|
|
1221
|
-
return;
|
|
1222
|
-
}
|
|
1223
|
-
markCacheDataConsumed(consumedCacheData, serverCacheData, key);
|
|
1224
|
-
const mutation = MUTATION[key];
|
|
1225
|
-
commitCacheData({
|
|
1226
|
-
value: preloadedData,
|
|
1227
|
-
getCacheData: () => getCache().data,
|
|
1228
|
-
canCommit: () => !unmountedRef.current && key === keyRef.current && MUTATION[key] === mutation,
|
|
1229
|
-
setCache: (state) => setCache({
|
|
1230
|
-
...state,
|
|
1231
|
-
_k: fnArg
|
|
1232
|
-
})
|
|
1233
|
-
});
|
|
1234
|
-
});
|
|
1235
|
-
useIsomorphicLayoutEffect(() => {
|
|
1236
|
-
if (!key) return;
|
|
1237
|
-
const softRevalidate = revalidate.bind(UNDEFINED, WITH_DEDUPE);
|
|
1238
|
-
let nextFocusRevalidatedAt = 0;
|
|
1239
|
-
if (getConfig().revalidateOnFocus) {
|
|
1240
|
-
const initNow = Date.now();
|
|
1241
|
-
nextFocusRevalidatedAt = initNow + getConfig().focusThrottleInterval;
|
|
1242
|
-
}
|
|
1243
|
-
const onRevalidate = (type, opts = {}) => {
|
|
1244
|
-
if (type == FOCUS_EVENT) {
|
|
1245
|
-
const now = Date.now();
|
|
1246
|
-
if (getConfig().revalidateOnFocus && now > nextFocusRevalidatedAt && isActive()) {
|
|
1247
|
-
nextFocusRevalidatedAt = now + getConfig().focusThrottleInterval;
|
|
1248
|
-
softRevalidate();
|
|
1249
|
-
}
|
|
1250
|
-
} else if (type == RECONNECT_EVENT) {
|
|
1251
|
-
if (getConfig().revalidateOnReconnect && isActive()) {
|
|
1252
|
-
softRevalidate();
|
|
1253
|
-
}
|
|
1254
|
-
} else if (type == MUTATE_EVENT) {
|
|
1255
|
-
return revalidate();
|
|
1256
|
-
} else if (type == ERROR_REVALIDATE_EVENT) {
|
|
1257
|
-
return revalidate(opts);
|
|
1258
|
-
} else if (type == UNLOAD_EVENT) {
|
|
1259
|
-
laggyDataRef.current = UNDEFINED;
|
|
1260
|
-
if (opts.revalidate) {
|
|
1261
|
-
return revalidate();
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
return;
|
|
1265
|
-
};
|
|
1266
|
-
const unsubEvents = subscribeCallback(key, EVENT_REVALIDATORS, onRevalidate);
|
|
1267
|
-
unmountedRef.current = false;
|
|
1268
|
-
keyRef.current = key;
|
|
1269
|
-
initialMountedRef.current = true;
|
|
1270
|
-
setCache({
|
|
1271
|
-
_k: fnArg
|
|
1272
|
-
});
|
|
1273
|
-
if (shouldDoInitialRevalidation) {
|
|
1274
|
-
if (!FETCH[key]) {
|
|
1275
|
-
if (isUndefined(data) || IS_SERVER) {
|
|
1276
|
-
softRevalidate();
|
|
1277
|
-
} else {
|
|
1278
|
-
rAF(softRevalidate);
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
return () => {
|
|
1283
|
-
unmountedRef.current = true;
|
|
1284
|
-
unsubEvents();
|
|
1285
|
-
};
|
|
1286
|
-
}, [
|
|
1287
|
-
key
|
|
1288
|
-
]);
|
|
1289
|
-
useIsomorphicLayoutEffect(() => {
|
|
1290
|
-
let timer;
|
|
1291
|
-
function next() {
|
|
1292
|
-
const interval = isFunction$2(refreshInterval) ? refreshInterval(getCache().data) : refreshInterval;
|
|
1293
|
-
if (interval && timer !== -1) {
|
|
1294
|
-
timer = setTimeout(execute, interval);
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
function execute() {
|
|
1298
|
-
if (!getCache().error && (refreshWhenHidden || getConfig().isVisible()) && (refreshWhenOffline || getConfig().isOnline())) {
|
|
1299
|
-
revalidate(WITH_DEDUPE).then(next);
|
|
1300
|
-
} else {
|
|
1301
|
-
next();
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
next();
|
|
1305
|
-
return () => {
|
|
1306
|
-
if (timer) {
|
|
1307
|
-
clearTimeout(timer);
|
|
1308
|
-
timer = -1;
|
|
1309
|
-
}
|
|
1310
|
-
};
|
|
1311
|
-
}, [
|
|
1312
|
-
refreshInterval,
|
|
1313
|
-
refreshWhenHidden,
|
|
1314
|
-
refreshWhenOffline,
|
|
1315
|
-
key
|
|
1316
|
-
]);
|
|
1317
|
-
reactExports.useDebugValue(returnedData);
|
|
1318
|
-
if (suspense) {
|
|
1319
|
-
if (!IS_REACT_LEGACY && IS_SERVER && hasKeyButNoData && isUndefined(preloadedData)) {
|
|
1320
|
-
throw new Error("Fallback data is required when using Suspense in SSR.");
|
|
1321
|
-
}
|
|
1322
|
-
if (hasKeyButNoData) {
|
|
1323
|
-
fetcherRef.current = fetcher;
|
|
1324
|
-
configRef.current = config;
|
|
1325
|
-
unmountedRef.current = false;
|
|
1326
|
-
}
|
|
1327
|
-
const shouldConsumePreload = !isUndefined(preloadedData) && hasKeyButNoData;
|
|
1328
|
-
let preloadData = UNDEFINED;
|
|
1329
|
-
if (shouldConsumePreload && hasCacheData) {
|
|
1330
|
-
preloadData = preloadedData && isPromiseLike(preloadedData) ? use(preloadedData) : preloadedData;
|
|
1331
|
-
data = preloadData;
|
|
1332
|
-
returnedData = preloadData;
|
|
1333
|
-
if (!IS_SERVER) {
|
|
1334
|
-
preloadCacheRef.current = {
|
|
1335
|
-
data: preloadData,
|
|
1336
|
-
_k: fnArg,
|
|
1337
|
-
key,
|
|
1338
|
-
cacheData: serverCacheData
|
|
1339
|
-
};
|
|
1340
|
-
}
|
|
1341
|
-
} else {
|
|
1342
|
-
const mutateReq = shouldConsumePreload ? boundMutate(preloadedData) : resolvedUndef;
|
|
1343
|
-
use(mutateReq);
|
|
1344
|
-
}
|
|
1345
|
-
if (!isUndefined(error) && hasKeyButNoData) {
|
|
1346
|
-
throw error;
|
|
1347
|
-
}
|
|
1348
|
-
const revalidation = hasKeyButNoData && isUndefined(preloadData) ? revalidate(WITH_DEDUPE) : resolvedUndef;
|
|
1349
|
-
if (!isUndefined(returnedData) && hasKeyButNoData) {
|
|
1350
|
-
revalidation.status = "fulfilled";
|
|
1351
|
-
revalidation.value = true;
|
|
1352
|
-
}
|
|
1353
|
-
use(revalidation);
|
|
1354
|
-
}
|
|
1355
|
-
const swrResponse = {
|
|
1356
|
-
mutate: boundMutate,
|
|
1357
|
-
get data() {
|
|
1358
|
-
stateDependencies.data = true;
|
|
1359
|
-
return returnedData;
|
|
1360
|
-
},
|
|
1361
|
-
get error() {
|
|
1362
|
-
stateDependencies.error = true;
|
|
1363
|
-
return error;
|
|
1364
|
-
},
|
|
1365
|
-
get isValidating() {
|
|
1366
|
-
stateDependencies.isValidating = true;
|
|
1367
|
-
return isValidating;
|
|
1368
|
-
},
|
|
1369
|
-
get isLoading() {
|
|
1370
|
-
stateDependencies.isLoading = true;
|
|
1371
|
-
return isLoading;
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
return swrResponse;
|
|
1375
|
-
};
|
|
1376
|
-
const useSWR = withArgs(useSWRHandler);
|
|
1377
|
-
const getFirstPageKey = (getKey) => {
|
|
1378
|
-
return serialize(getKey ? getKey(0, null) : null)[0];
|
|
1379
|
-
};
|
|
1380
|
-
const EMPTY_PROMISE = Promise.resolve();
|
|
1381
|
-
const infinite = (useSWRNext) => (getKey, fn, config) => {
|
|
1382
|
-
const didMountRef = reactExports.useRef(false);
|
|
1383
|
-
const { cache: cache$1, initialSize = 1, revalidateAll = false, persistSize = false, revalidateFirstPage = true, revalidateOnMount = false, parallel = false } = config;
|
|
1384
|
-
const [, , , PRELOAD] = SWRGlobalState.get(cache);
|
|
1385
|
-
let infiniteKey;
|
|
1386
|
-
try {
|
|
1387
|
-
infiniteKey = getFirstPageKey(getKey);
|
|
1388
|
-
if (infiniteKey) infiniteKey = INFINITE_PREFIX + infiniteKey;
|
|
1389
|
-
} catch (err) {
|
|
1390
|
-
}
|
|
1391
|
-
const [get, set, subscribeCache] = createCacheHelper(cache$1, infiniteKey);
|
|
1392
|
-
const getSnapshot = reactExports.useCallback(() => {
|
|
1393
|
-
const size = isUndefined(get()._l) ? initialSize : get()._l;
|
|
1394
|
-
return size;
|
|
1395
|
-
}, [
|
|
1396
|
-
cache$1,
|
|
1397
|
-
infiniteKey,
|
|
1398
|
-
initialSize
|
|
1399
|
-
]);
|
|
1400
|
-
shimExports.useSyncExternalStore(reactExports.useCallback(
|
|
1401
|
-
(callback) => {
|
|
1402
|
-
if (infiniteKey) return subscribeCache(infiniteKey, () => {
|
|
1403
|
-
callback();
|
|
1404
|
-
});
|
|
1405
|
-
return () => {
|
|
1406
|
-
};
|
|
1407
|
-
},
|
|
1408
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1409
|
-
[
|
|
1410
|
-
cache$1,
|
|
1411
|
-
infiniteKey
|
|
1412
|
-
]
|
|
1413
|
-
), getSnapshot, getSnapshot);
|
|
1414
|
-
const resolvePageSize = reactExports.useCallback(() => {
|
|
1415
|
-
const cachedPageSize = get()._l;
|
|
1416
|
-
return isUndefined(cachedPageSize) ? initialSize : cachedPageSize;
|
|
1417
|
-
}, [
|
|
1418
|
-
infiniteKey,
|
|
1419
|
-
initialSize
|
|
1420
|
-
]);
|
|
1421
|
-
const lastPageSizeRef = reactExports.useRef(resolvePageSize());
|
|
1422
|
-
useIsomorphicLayoutEffect(() => {
|
|
1423
|
-
if (!didMountRef.current) {
|
|
1424
|
-
didMountRef.current = true;
|
|
1425
|
-
return;
|
|
1426
|
-
}
|
|
1427
|
-
if (infiniteKey) {
|
|
1428
|
-
set({
|
|
1429
|
-
_l: persistSize ? lastPageSizeRef.current : resolvePageSize()
|
|
1430
|
-
});
|
|
1431
|
-
}
|
|
1432
|
-
}, [
|
|
1433
|
-
infiniteKey,
|
|
1434
|
-
cache$1
|
|
1435
|
-
]);
|
|
1436
|
-
const shouldRevalidateOnMount = revalidateOnMount && !didMountRef.current;
|
|
1437
|
-
const swr = useSWRNext(infiniteKey, async (key) => {
|
|
1438
|
-
const forceRevalidateAll = get()._i;
|
|
1439
|
-
const shouldRevalidatePage = get()._r;
|
|
1440
|
-
const state = SWRGlobalState.get(cache$1);
|
|
1441
|
-
const unloadGeneration = state[8];
|
|
1442
|
-
const unloadedDuringRequest = () => state[8] !== unloadGeneration;
|
|
1443
|
-
set({
|
|
1444
|
-
_r: UNDEFINED
|
|
1445
|
-
});
|
|
1446
|
-
const data = [];
|
|
1447
|
-
const pageSize = resolvePageSize();
|
|
1448
|
-
const [getCache] = createCacheHelper(cache$1, key);
|
|
1449
|
-
const cacheData = getCache().data;
|
|
1450
|
-
const revalidators = [];
|
|
1451
|
-
let previousPageData = null;
|
|
1452
|
-
for (let i = 0; i < pageSize; ++i) {
|
|
1453
|
-
const [pageKey, pageArg] = serialize(getKey(i, parallel ? null : previousPageData));
|
|
1454
|
-
if (!pageKey) {
|
|
1455
|
-
break;
|
|
1456
|
-
}
|
|
1457
|
-
const [getSWRCache, setSWRCache] = createCacheHelper(cache$1, pageKey);
|
|
1458
|
-
let pageData = getSWRCache().data;
|
|
1459
|
-
const shouldFetchPage = revalidateAll || forceRevalidateAll || isUndefined(pageData) || revalidateFirstPage && !i && !isUndefined(cacheData) || shouldRevalidateOnMount || cacheData && !isUndefined(cacheData[i]) && !config.compare(cacheData[i], pageData);
|
|
1460
|
-
if (fn && (typeof shouldRevalidatePage === "function" ? shouldRevalidatePage(pageData, pageArg) : shouldFetchPage)) {
|
|
1461
|
-
const revalidate = async () => {
|
|
1462
|
-
const hasPreloadedRequest = pageKey in PRELOAD;
|
|
1463
|
-
if (!hasPreloadedRequest) {
|
|
1464
|
-
pageData = await fn(pageArg);
|
|
1465
|
-
} else {
|
|
1466
|
-
const req = PRELOAD[pageKey];
|
|
1467
|
-
delete PRELOAD[pageKey];
|
|
1468
|
-
pageData = await req;
|
|
1469
|
-
}
|
|
1470
|
-
if (!unloadedDuringRequest()) {
|
|
1471
|
-
setSWRCache({
|
|
1472
|
-
data: pageData,
|
|
1473
|
-
_k: pageArg
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
data[i] = pageData;
|
|
1477
|
-
};
|
|
1478
|
-
if (parallel) {
|
|
1479
|
-
revalidators.push(revalidate);
|
|
1480
|
-
} else {
|
|
1481
|
-
await revalidate();
|
|
1482
|
-
}
|
|
1483
|
-
} else {
|
|
1484
|
-
data[i] = pageData;
|
|
1485
|
-
}
|
|
1486
|
-
if (!parallel) {
|
|
1487
|
-
previousPageData = pageData;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
if (parallel) {
|
|
1491
|
-
await Promise.all(revalidators.map((r) => r()));
|
|
1492
|
-
}
|
|
1493
|
-
if (!unloadedDuringRequest()) {
|
|
1494
|
-
set({
|
|
1495
|
-
_i: UNDEFINED
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
return data;
|
|
1499
|
-
}, config);
|
|
1500
|
-
const mutate2 = reactExports.useCallback(
|
|
1501
|
-
// eslint-disable-next-line func-names
|
|
1502
|
-
function(data, opts) {
|
|
1503
|
-
const options = typeof opts === "boolean" ? {
|
|
1504
|
-
revalidate: opts
|
|
1505
|
-
} : opts || {};
|
|
1506
|
-
const shouldRevalidate = options.revalidate !== false;
|
|
1507
|
-
if (!infiniteKey) return EMPTY_PROMISE;
|
|
1508
|
-
if (shouldRevalidate) {
|
|
1509
|
-
if (!isUndefined(data)) {
|
|
1510
|
-
set({
|
|
1511
|
-
_i: false,
|
|
1512
|
-
_r: options.revalidate
|
|
1513
|
-
});
|
|
1514
|
-
} else {
|
|
1515
|
-
set({
|
|
1516
|
-
_i: true,
|
|
1517
|
-
_r: options.revalidate
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
return arguments.length ? swr.mutate(data, {
|
|
1522
|
-
...options,
|
|
1523
|
-
revalidate: shouldRevalidate
|
|
1524
|
-
}) : swr.mutate();
|
|
1525
|
-
},
|
|
1526
|
-
// swr.mutate is always the same reference
|
|
1527
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1528
|
-
[
|
|
1529
|
-
infiniteKey,
|
|
1530
|
-
cache$1
|
|
1531
|
-
]
|
|
1532
|
-
);
|
|
1533
|
-
const setSize = reactExports.useCallback(
|
|
1534
|
-
(arg) => {
|
|
1535
|
-
if (!infiniteKey) return EMPTY_PROMISE;
|
|
1536
|
-
const [, changeSize] = createCacheHelper(cache$1, infiniteKey);
|
|
1537
|
-
let size;
|
|
1538
|
-
if (isFunction$2(arg)) {
|
|
1539
|
-
size = arg(resolvePageSize());
|
|
1540
|
-
} else if (typeof arg == "number") {
|
|
1541
|
-
size = arg;
|
|
1542
|
-
}
|
|
1543
|
-
if (typeof size != "number") return EMPTY_PROMISE;
|
|
1544
|
-
changeSize({
|
|
1545
|
-
_l: size
|
|
1546
|
-
});
|
|
1547
|
-
lastPageSizeRef.current = size;
|
|
1548
|
-
const data = [];
|
|
1549
|
-
const [getInfiniteCache] = createCacheHelper(cache$1, infiniteKey);
|
|
1550
|
-
let previousPageData = null;
|
|
1551
|
-
for (let i = 0; i < size; ++i) {
|
|
1552
|
-
const [pageKey] = serialize(getKey(i, previousPageData));
|
|
1553
|
-
const [getCache] = createCacheHelper(cache$1, pageKey);
|
|
1554
|
-
const pageData = pageKey ? getCache().data : UNDEFINED;
|
|
1555
|
-
if (isUndefined(pageData)) {
|
|
1556
|
-
return mutate2(getInfiniteCache().data);
|
|
1557
|
-
}
|
|
1558
|
-
data.push(pageData);
|
|
1559
|
-
previousPageData = pageData;
|
|
1560
|
-
}
|
|
1561
|
-
return mutate2(data);
|
|
1562
|
-
},
|
|
1563
|
-
// exclude getKey from the dependencies, which isn't allowed to change during the lifecycle
|
|
1564
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1565
|
-
[
|
|
1566
|
-
infiniteKey,
|
|
1567
|
-
cache$1,
|
|
1568
|
-
mutate2,
|
|
1569
|
-
resolvePageSize
|
|
1570
|
-
]
|
|
1571
|
-
);
|
|
1572
|
-
return {
|
|
1573
|
-
size: resolvePageSize(),
|
|
1574
|
-
setSize,
|
|
1575
|
-
mutate: mutate2,
|
|
1576
|
-
get data() {
|
|
1577
|
-
return swr.data;
|
|
1578
|
-
},
|
|
1579
|
-
get error() {
|
|
1580
|
-
return swr.error;
|
|
1581
|
-
},
|
|
1582
|
-
get isValidating() {
|
|
1583
|
-
return swr.isValidating;
|
|
1584
|
-
},
|
|
1585
|
-
get isLoading() {
|
|
1586
|
-
return swr.isLoading;
|
|
1587
|
-
}
|
|
1588
|
-
};
|
|
1589
|
-
};
|
|
1590
|
-
const useSWRInfinite = withMiddleware(useSWR, infinite);
|
|
1591
|
-
function useInfiniteList(cacheKey, fetchFn, getItemKey) {
|
|
1592
|
-
var _a;
|
|
1593
|
-
const getKey = reactExports.useCallback(
|
|
1594
|
-
(_index, prev) => {
|
|
1595
|
-
if (prev && (!prev.hasMore || !prev.cursor)) return null;
|
|
1596
|
-
return [cacheKey, (prev == null ? void 0 : prev.cursor) ?? null];
|
|
1597
|
-
},
|
|
1598
|
-
[cacheKey]
|
|
1599
|
-
);
|
|
1600
|
-
const {
|
|
1601
|
-
data: pages,
|
|
1602
|
-
error,
|
|
1603
|
-
isLoading,
|
|
1604
|
-
isValidating,
|
|
1605
|
-
size,
|
|
1606
|
-
setSize,
|
|
1607
|
-
mutate: mutate2
|
|
1608
|
-
} = useSWRInfinite(
|
|
1609
|
-
getKey,
|
|
1610
|
-
([, cursor]) => fetchFn(cursor ?? void 0),
|
|
1611
|
-
{
|
|
1612
|
-
revalidateFirstPage: false,
|
|
1613
|
-
revalidateIfStale: false,
|
|
1614
|
-
revalidateOnFocus: false,
|
|
1615
|
-
keepPreviousData: true
|
|
1616
|
-
}
|
|
1617
|
-
);
|
|
1618
|
-
const items = reactExports.useMemo(() => {
|
|
1619
|
-
if (!pages) return [];
|
|
1620
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1621
|
-
const result = [];
|
|
1622
|
-
for (const page of pages) {
|
|
1623
|
-
for (const item of page.data) {
|
|
1624
|
-
const key = getItemKey(item);
|
|
1625
|
-
if (seen.has(key)) continue;
|
|
1626
|
-
seen.add(key);
|
|
1627
|
-
result.push(item);
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
return result;
|
|
1631
|
-
}, [pages, getItemKey]);
|
|
1632
|
-
const lastPage = pages == null ? void 0 : pages[pages.length - 1];
|
|
1633
|
-
const hasMore = Boolean((lastPage == null ? void 0 : lastPage.hasMore) && (lastPage == null ? void 0 : lastPage.cursor));
|
|
1634
|
-
const isLoadingMore = size > 0 && Boolean(pages) && pages.length < size;
|
|
1635
|
-
const loadMore = reactExports.useCallback(() => {
|
|
1636
|
-
if (isValidating || !hasMore) return;
|
|
1637
|
-
void setSize((s) => s + 1);
|
|
1638
|
-
}, [isValidating, hasMore, setSize]);
|
|
1639
|
-
const reload = reactExports.useCallback(() => {
|
|
1640
|
-
void setSize(1);
|
|
1641
|
-
void mutate2();
|
|
1642
|
-
}, [setSize, mutate2]);
|
|
1643
|
-
const normalizedError = error ? error instanceof Error ? error : new WorkflowWebAPIError(String(error), { layer: "client" }) : null;
|
|
1644
|
-
return {
|
|
1645
|
-
items,
|
|
1646
|
-
error: normalizedError,
|
|
1647
|
-
isLoading,
|
|
1648
|
-
isLoadingMore,
|
|
1649
|
-
hasMore,
|
|
1650
|
-
loadMore,
|
|
1651
|
-
reload,
|
|
1652
|
-
refresh: reload,
|
|
1653
|
-
pageInfo: (_a = pages == null ? void 0 : pages[0]) == null ? void 0 : _a.pageInfo
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
function useWorkflowRunsInfinite(env, params) {
|
|
1657
|
-
const {
|
|
1658
|
-
workflowName,
|
|
1659
|
-
status,
|
|
1660
|
-
limit = 25,
|
|
1661
|
-
sortOrder = "desc",
|
|
1662
|
-
startTime,
|
|
1663
|
-
endTime
|
|
1664
|
-
} = params;
|
|
1665
|
-
const cacheKey = `workflow-runs:${workflowName ?? ""}:${status ?? ""}:${sortOrder}:${limit}:${startTime ?? ""}:${endTime ?? ""}`;
|
|
1666
|
-
const fetchFn = reactExports.useCallback(
|
|
1667
|
-
(cursor) => unwrapOrThrow(
|
|
1668
|
-
fetchRuns(env, {
|
|
1669
|
-
cursor,
|
|
1670
|
-
sortOrder,
|
|
1671
|
-
limit,
|
|
1672
|
-
workflowName,
|
|
1673
|
-
status,
|
|
1674
|
-
startTime,
|
|
1675
|
-
endTime
|
|
1676
|
-
})
|
|
1677
|
-
),
|
|
1678
|
-
[env, workflowName, limit, sortOrder, status, startTime, endTime]
|
|
1679
|
-
);
|
|
1680
|
-
const getItemKey = reactExports.useCallback((run) => run.runId, []);
|
|
1681
|
-
return useInfiniteList(cacheKey, fetchFn, getItemKey);
|
|
1682
|
-
}
|
|
1683
291
|
function useLoadMoreOnScroll(loadMore, {
|
|
1684
292
|
hasMore,
|
|
1685
293
|
isLoadingMore,
|
|
@@ -3503,7 +2111,7 @@ const SelectTrigger = reactExports.forwardRef(({ className, children, ...props }
|
|
|
3503
2111
|
...props,
|
|
3504
2112
|
children: [
|
|
3505
2113
|
children,
|
|
3506
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectIcon, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "h-4 w-4
|
|
2114
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectIcon, { asChild: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "h-4 w-4 text-gray-700" }) })
|
|
3507
2115
|
]
|
|
3508
2116
|
}
|
|
3509
2117
|
));
|
|
@@ -4225,7 +2833,7 @@ const PERIOD_PRESETS = [
|
|
|
4225
2833
|
];
|
|
4226
2834
|
const DEFAULT_PERIOD = "24h";
|
|
4227
2835
|
function isPeriodId(value) {
|
|
4228
|
-
return PERIOD_PRESETS.some((
|
|
2836
|
+
return PERIOD_PRESETS.some((preset) => preset.id === value);
|
|
4229
2837
|
}
|
|
4230
2838
|
function useWorkflowFilter() {
|
|
4231
2839
|
const navigate = useNavigate();
|
|
@@ -4318,19 +2926,19 @@ function FilterControls({
|
|
|
4318
2926
|
disabled: loading,
|
|
4319
2927
|
children: [
|
|
4320
2928
|
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectTrigger, { className: "w-[150px] h-9", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectValue, { placeholder: "Time window" }) }),
|
|
4321
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectContent, { children: PERIOD_PRESETS.map((
|
|
4322
|
-
const beyondPlan = planWindowMs !== void 0 &&
|
|
2929
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(SelectContent, { children: PERIOD_PRESETS.map((preset) => {
|
|
2930
|
+
const beyondPlan = planWindowMs !== void 0 && preset.ms > planWindowMs;
|
|
4323
2931
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
4324
2932
|
SelectItem,
|
|
4325
2933
|
{
|
|
4326
|
-
value:
|
|
2934
|
+
value: preset.id,
|
|
4327
2935
|
disabled: beyondPlan,
|
|
4328
2936
|
children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4329
|
-
|
|
2937
|
+
preset.label,
|
|
4330
2938
|
beyondPlan && planUpgradeAvailable && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs text-muted-foreground", children: "Observability Plus" })
|
|
4331
2939
|
] })
|
|
4332
2940
|
},
|
|
4333
|
-
|
|
2941
|
+
preset.id
|
|
4334
2942
|
);
|
|
4335
2943
|
}) })
|
|
4336
2944
|
]
|
|
@@ -4431,7 +3039,7 @@ function RunsTable({ onRunClick }) {
|
|
|
4431
3039
|
const workflowNameFilter = searchParams.get("workflow");
|
|
4432
3040
|
const rawPeriod = searchParams.get("period");
|
|
4433
3041
|
const period = isPeriodId(rawPeriod) ? rawPeriod : DEFAULT_PERIOD;
|
|
4434
|
-
const periodPreset = PERIOD_PRESETS.find((
|
|
3042
|
+
const periodPreset = PERIOD_PRESETS.find((preset) => preset.id === period) ?? PERIOD_PRESETS[2];
|
|
4435
3043
|
const handlePeriodFilter = usePeriodFilter();
|
|
4436
3044
|
const [sortOrder, setSortOrder] = reactExports.useState("desc");
|
|
4437
3045
|
const [lastRefreshTime, setLastRefreshTime] = reactExports.useState(
|
|
@@ -4467,7 +3075,6 @@ function RunsTable({ onRunClick }) {
|
|
|
4467
3075
|
hasMore,
|
|
4468
3076
|
loadMore,
|
|
4469
3077
|
reload,
|
|
4470
|
-
refresh,
|
|
4471
3078
|
pageInfo: analyticsPageInfo
|
|
4472
3079
|
} = useWorkflowRunsInfinite(env, {
|
|
4473
3080
|
sortOrder,
|
|
@@ -4525,8 +3132,8 @@ function RunsTable({ onRunClick }) {
|
|
|
4525
3132
|
const onRefresh = reactExports.useCallback(() => {
|
|
4526
3133
|
setLastRefreshTime(() => /* @__PURE__ */ new Date());
|
|
4527
3134
|
refreshListingWindow();
|
|
4528
|
-
|
|
4529
|
-
}, [
|
|
3135
|
+
reload();
|
|
3136
|
+
}, [reload, refreshListingWindow]);
|
|
4530
3137
|
const selectedRuns = reactExports.useMemo(() => {
|
|
4531
3138
|
return runs.filter((run) => selection.selectedIds.has(run.runId));
|
|
4532
3139
|
}, [runs, selection.selectedIds]);
|
|
@@ -4879,7 +3486,7 @@ function SheetContent({
|
|
|
4879
3486
|
...props,
|
|
4880
3487
|
children: [
|
|
4881
3488
|
children,
|
|
4882
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(DialogClose, { className: "ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs
|
|
3489
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(DialogClose, { className: "ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs text-gray-900 transition-colors hover:text-gray-1000 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none", children: [
|
|
4883
3490
|
/* @__PURE__ */ jsxRuntimeExports.jsx(X, { className: "size-4" }),
|
|
4884
3491
|
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sr-only", children: "Close" })
|
|
4885
3492
|
] })
|
|
@@ -5222,14 +3829,13 @@ const home = withComponentProps(function Home() {
|
|
|
5222
3829
|
const {
|
|
5223
3830
|
serverConfig
|
|
5224
3831
|
} = useServerConfig();
|
|
5225
|
-
const [searchParams,
|
|
3832
|
+
const [searchParams, updateSearchParams] = useOptimisticSearchParams();
|
|
5226
3833
|
const sidebar = searchParams.get("sidebar");
|
|
5227
3834
|
const hookId = searchParams.get("hookId");
|
|
5228
3835
|
const tab = searchParams.get("tab") || "runs";
|
|
5229
3836
|
const setTab = (value) => {
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
return prev;
|
|
3837
|
+
updateSearchParams({
|
|
3838
|
+
tab: value
|
|
5233
3839
|
}, {
|
|
5234
3840
|
replace: true
|
|
5235
3841
|
});
|