@teyik0/furin 0.1.0-alpha.11 → 0.1.0-alpha.12

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.
@@ -1598,10 +1598,15 @@ function generateHydrateEntry(routes, rootLayout, basePath) {
1598
1598
  const conventionImportLines = [...conventionIdents.entries()].map(([filePath, ident]) => `import ${ident} from "${filePath.replace(/\\/g, "/")}";`).join(`
1599
1599
  `);
1600
1600
  const basePathLiteral = JSON.stringify(basePath);
1601
- const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral}; return (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; })()` : "window.location.pathname";
1601
+ const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral}; const stripped = (p.startsWith(b) && (p.length === b.length || p[b.length] === "/")) ? p.slice(b.length) || "/" : p; return stripped === "/" ? "/" : stripped.replace(/\\/+$/, ""); })()` : `window.location.pathname.replace(/\\/+$/, "") || "/"`;
1602
1602
  const logEndpoint = basePath ? `${JSON.stringify(basePath)} + "/_furin/ingest"` : `"/_furin/ingest"`;
1603
- const basePathProp = basePath ? `
1604
- basePath: ${basePathLiteral},` : "";
1603
+ const routerProviderDefaults = `
1604
+ autoRefresh: true,
1605
+ basePath: ${basePathLiteral},
1606
+ defaultPreload: "intent",
1607
+ defaultPreloadDelay: 50,
1608
+ defaultPreloadStaleTime: 30000,
1609
+ prefetchCacheSize: 50,`;
1605
1610
  const conventionImportsBlock = conventionImportLines ? `
1606
1611
  ${conventionImportLines}` : "";
1607
1612
  return `import { hydrateRoot, createRoot } from "react-dom/client";
@@ -1650,7 +1655,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
1650
1655
  initialMatch: match,
1651
1656
  initialData: loaderData,
1652
1657
  initialDigest: loaderData.__furinError?.digest,
1653
- initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${basePathProp}
1658
+ initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
1654
1659
  } as any);
1655
1660
  } else if (loaderData.__furinStatus === 404) {
1656
1661
  // Direct load to an unknown URL. The server sent the root not-found UI
@@ -1667,7 +1672,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
1667
1672
  initialMatch: null,
1668
1673
  initialData: cleanData,
1669
1674
  initialDigest: loaderData.__furinError?.digest,
1670
- initialNotFound: loaderData.__furinNotFound ?? {},${basePathProp}
1675
+ initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
1671
1676
  } as any);
1672
1677
  } else {
1673
1678
  // No match and no 404 signal \u2014 either the client bundle is out of sync
@@ -2255,9 +2260,24 @@ function assembleHTML(template, headData, reactHtml, data) {
2255
2260
  }
2256
2261
 
2257
2262
  // src/render/index.ts
2258
- import { createElement as createElement2 } from "react";
2263
+ import { createElement as createElement3 } from "react";
2259
2264
  import { renderToReadableStream } from "react-dom/server";
2260
2265
 
2266
+ // src/not-found.ts
2267
+ var NOT_FOUND_BRAND = "FURIN_NOT_FOUND";
2268
+
2269
+ class FurinNotFoundError extends Error {
2270
+ __furinBrand = NOT_FOUND_BRAND;
2271
+ data;
2272
+ constructor(options) {
2273
+ super(options?.message ?? "");
2274
+ this.data = options?.data;
2275
+ }
2276
+ }
2277
+ function isNotFoundError(err) {
2278
+ return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
2279
+ }
2280
+
2261
2281
  // ../../node_modules/.bun/evlog@2.14.1+6b630eaba8c4f70c/node_modules/evlog/dist/utils.mjs
2262
2282
  function formatDuration(ms) {
2263
2283
  if (ms < 1000)
@@ -3163,15 +3183,16 @@ function finalizeAudit(event) {
3163
3183
  return;
3164
3184
  event.audit = decorateAudit(a, String(event.timestamp));
3165
3185
  }
3166
- // src/link.tsx
3186
+ // src/router-provider.tsx
3167
3187
  import {
3168
3188
  createContext,
3169
- createElement,
3170
- useCallback,
3189
+ createElement as createElement2,
3190
+ useCallback as useCallback2,
3171
3191
  useContext,
3172
- useEffect,
3192
+ useEffect as useEffect2,
3193
+ useLayoutEffect,
3173
3194
  useMemo,
3174
- useRef,
3195
+ useRef as useRef2,
3175
3196
  useState
3176
3197
  } from "react";
3177
3198
 
@@ -3187,19 +3208,193 @@ function getPublicErrorMessage(error) {
3187
3208
  return "Something went wrong";
3188
3209
  }
3189
3210
 
3190
- // src/not-found.ts
3191
- var NOT_FOUND_BRAND = "FURIN_NOT_FOUND";
3192
-
3193
- class FurinNotFoundError extends Error {
3194
- __furinBrand = NOT_FOUND_BRAND;
3195
- data;
3196
- constructor(options) {
3197
- super(options?.message ?? "");
3198
- this.data = options?.data;
3199
- }
3211
+ // src/link.tsx
3212
+ import { createElement, useCallback, useEffect, useRef } from "react";
3213
+ function computeLinkView({
3214
+ to,
3215
+ search,
3216
+ hash,
3217
+ children,
3218
+ activeProps,
3219
+ inactiveProps
3220
+ }, router) {
3221
+ const logicalHref = buildHref(to, search, hash);
3222
+ const logicalHrefWithoutHash = buildHref(to, search, undefined);
3223
+ const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
3224
+ const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
3225
+ const isActive = router.currentHref === logicalHrefWithoutHash;
3226
+ const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
3227
+ const extraProps = {
3228
+ ...inactiveProps && !isActive ? inactiveProps() : {},
3229
+ ...activeProps ? activeProps({ isActive }) : {}
3230
+ };
3231
+ return { logicalHref, href, isActive, resolvedChildren, extraProps };
3200
3232
  }
3201
- function isNotFoundError(err) {
3202
- return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
3233
+ function LinkInteractive({
3234
+ to,
3235
+ search,
3236
+ hash,
3237
+ preload,
3238
+ preloadDelay,
3239
+ preloadStaleTime,
3240
+ replace,
3241
+ disabled,
3242
+ resetScroll,
3243
+ activeProps,
3244
+ inactiveProps,
3245
+ onClick,
3246
+ onMouseEnter,
3247
+ onMouseLeave,
3248
+ onFocus,
3249
+ children,
3250
+ href: _href,
3251
+ ...anchorProps
3252
+ }) {
3253
+ const router = useRouter();
3254
+ const anchorRef = useRef(null);
3255
+ const intentTimerRef = useRef(null);
3256
+ const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
3257
+ const effectivePreload = preload ?? router.defaultPreload;
3258
+ const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
3259
+ const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
3260
+ const triggerPrefetch = useCallback(() => {
3261
+ router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
3262
+ }, [router, logicalHref, effectiveStaleTime]);
3263
+ useEffect(() => {
3264
+ if (effectivePreload === "render") {
3265
+ triggerPrefetch();
3266
+ }
3267
+ }, [effectivePreload, triggerPrefetch]);
3268
+ useEffect(() => {
3269
+ if (effectivePreload !== "viewport" || !anchorRef.current) {
3270
+ return;
3271
+ }
3272
+ const observer = new IntersectionObserver(([entry]) => {
3273
+ if (entry?.isIntersecting) {
3274
+ triggerPrefetch();
3275
+ observer.disconnect();
3276
+ }
3277
+ }, { rootMargin: "200px" });
3278
+ observer.observe(anchorRef.current);
3279
+ return () => observer.disconnect();
3280
+ }, [effectivePreload, triggerPrefetch]);
3281
+ useEffect(() => () => {
3282
+ if (intentTimerRef.current !== null) {
3283
+ clearTimeout(intentTimerRef.current);
3284
+ intentTimerRef.current = null;
3285
+ }
3286
+ }, []);
3287
+ const isInternal = (url) => {
3288
+ try {
3289
+ return new URL(url, window.location.origin).origin === window.location.origin;
3290
+ } catch {
3291
+ return false;
3292
+ }
3293
+ };
3294
+ const handleClick = (e) => {
3295
+ onClick?.(e);
3296
+ if (e.defaultPrevented) {
3297
+ return;
3298
+ }
3299
+ if (disabled) {
3300
+ e.preventDefault();
3301
+ return;
3302
+ }
3303
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
3304
+ return;
3305
+ }
3306
+ if (anchorProps.target && anchorProps.target !== "_self") {
3307
+ return;
3308
+ }
3309
+ if (!isInternal(href)) {
3310
+ return;
3311
+ }
3312
+ e.preventDefault();
3313
+ router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
3314
+ };
3315
+ const handleMouseEnter = (e) => {
3316
+ onMouseEnter?.(e);
3317
+ if (!disabled && effectivePreload === "intent" && isInternal(href)) {
3318
+ intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
3319
+ }
3320
+ };
3321
+ const handleMouseLeave = (e) => {
3322
+ onMouseLeave?.(e);
3323
+ if (intentTimerRef.current !== null) {
3324
+ clearTimeout(intentTimerRef.current);
3325
+ intentTimerRef.current = null;
3326
+ }
3327
+ };
3328
+ const handleFocus = (e) => {
3329
+ onFocus?.(e);
3330
+ if (!disabled && effectivePreload === "intent" && isInternal(href)) {
3331
+ triggerPrefetch();
3332
+ }
3333
+ };
3334
+ return createElement("a", {
3335
+ ref: anchorRef,
3336
+ href,
3337
+ "data-furin-link": true,
3338
+ onClick: handleClick,
3339
+ onMouseEnter: handleMouseEnter,
3340
+ onMouseLeave: handleMouseLeave,
3341
+ onFocus: handleFocus,
3342
+ ...isActive ? { "data-status": "active" } : {},
3343
+ ...anchorProps,
3344
+ ...extraProps,
3345
+ ...disabled ? { "aria-disabled": true } : {}
3346
+ }, resolvedChildren);
3347
+ }
3348
+ var SSR_FALLBACK_ROUTER = {
3349
+ basePath: "",
3350
+ currentHref: "/",
3351
+ navigate: () => Promise.resolve(),
3352
+ prefetch: () => {},
3353
+ invalidatePrefetch: () => {},
3354
+ refresh: () => Promise.resolve(),
3355
+ isNavigating: false,
3356
+ defaultPreload: "intent",
3357
+ defaultPreloadDelay: 50,
3358
+ defaultPreloadStaleTime: 30000
3359
+ };
3360
+ function renderLinkElement(props, router) {
3361
+ const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
3362
+ const {
3363
+ to: _to,
3364
+ search: _search,
3365
+ hash: _hash,
3366
+ children: _children,
3367
+ activeProps: _ap,
3368
+ inactiveProps: _ip,
3369
+ disabled,
3370
+ preload: _p,
3371
+ preloadDelay: _pd,
3372
+ preloadStaleTime: _ps,
3373
+ replace: _r,
3374
+ resetScroll: _rs,
3375
+ onClick: _oc,
3376
+ onMouseEnter: _ome,
3377
+ onMouseLeave: _oml,
3378
+ onFocus: _of,
3379
+ href: _href,
3380
+ ...anchorProps
3381
+ } = props;
3382
+ return createElement("a", {
3383
+ href,
3384
+ "data-furin-link": true,
3385
+ ...isActive ? { "data-status": "active" } : {},
3386
+ ...anchorProps,
3387
+ ...extraProps,
3388
+ ...disabled ? { "aria-disabled": true } : {}
3389
+ }, resolvedChildren);
3390
+ }
3391
+ function Link(props) {
3392
+ if (typeof window === "undefined") {
3393
+ return createElement(RouterContext.Consumer, {
3394
+ children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
3395
+ });
3396
+ }
3397
+ return createElement(LinkInteractive, props);
3203
3398
  }
3204
3399
 
3205
3400
  // src/render/default-screens.tsx
@@ -3587,7 +3782,7 @@ class FurinNotFoundBoundary extends Component {
3587
3782
  }
3588
3783
  }
3589
3784
 
3590
- // src/link.tsx
3785
+ // src/router-provider.tsx
3591
3786
  import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
3592
3787
  function buildHref(to, search, hash) {
3593
3788
  let url = to;
@@ -3610,7 +3805,8 @@ function buildHref(to, search, hash) {
3610
3805
  }
3611
3806
  var RouterContext = createContext(null);
3612
3807
  function useRouter() {
3613
- return useContext(RouterContext) ?? {
3808
+ const ctx = useContext(RouterContext);
3809
+ return ctx ?? {
3614
3810
  basePath: "",
3615
3811
  currentHref: "/",
3616
3812
  navigate: (href) => {
@@ -3629,177 +3825,6 @@ function useRouter() {
3629
3825
  defaultPreloadStaleTime: 30000
3630
3826
  };
3631
3827
  }
3632
- function computeLinkView({
3633
- to,
3634
- search,
3635
- hash,
3636
- children,
3637
- activeProps,
3638
- inactiveProps
3639
- }, router) {
3640
- const logicalHref = buildHref(to, search, hash);
3641
- const logicalHrefWithoutHash = buildHref(to, search, undefined);
3642
- const href = router.basePath + logicalHref;
3643
- const isActive = router.currentHref === logicalHrefWithoutHash;
3644
- const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
3645
- const extraProps = {
3646
- ...inactiveProps && !isActive ? inactiveProps() : {},
3647
- ...activeProps ? activeProps({ isActive }) : {}
3648
- };
3649
- return { logicalHref, href, isActive, resolvedChildren, extraProps };
3650
- }
3651
- function LinkInteractive({
3652
- to,
3653
- search,
3654
- hash,
3655
- preload,
3656
- preloadDelay,
3657
- preloadStaleTime,
3658
- replace,
3659
- disabled,
3660
- resetScroll,
3661
- activeProps,
3662
- inactiveProps,
3663
- onClick,
3664
- onMouseEnter,
3665
- onMouseLeave,
3666
- onFocus,
3667
- children,
3668
- ...anchorProps
3669
- }) {
3670
- const router = useRouter();
3671
- const anchorRef = useRef(null);
3672
- const intentTimerRef = useRef(null);
3673
- const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
3674
- const effectivePreload = preload ?? router.defaultPreload;
3675
- const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
3676
- const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
3677
- const triggerPrefetch = useCallback(() => {
3678
- router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
3679
- }, [router, logicalHref, effectiveStaleTime]);
3680
- useEffect(() => {
3681
- if (effectivePreload === "render") {
3682
- triggerPrefetch();
3683
- }
3684
- }, [effectivePreload, triggerPrefetch]);
3685
- useEffect(() => {
3686
- if (effectivePreload !== "viewport" || !anchorRef.current) {
3687
- return;
3688
- }
3689
- const observer = new IntersectionObserver(([entry]) => {
3690
- if (entry?.isIntersecting) {
3691
- triggerPrefetch();
3692
- observer.disconnect();
3693
- }
3694
- }, { rootMargin: "200px" });
3695
- observer.observe(anchorRef.current);
3696
- return () => observer.disconnect();
3697
- }, [effectivePreload, triggerPrefetch]);
3698
- const isInternal = (url) => {
3699
- try {
3700
- return new URL(url, window.location.origin).origin === window.location.origin;
3701
- } catch {
3702
- return false;
3703
- }
3704
- };
3705
- const handleClick = (e) => {
3706
- onClick?.(e);
3707
- if (e.defaultPrevented || disabled) {
3708
- return;
3709
- }
3710
- if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
3711
- return;
3712
- }
3713
- if (anchorProps.target && anchorProps.target !== "_self") {
3714
- return;
3715
- }
3716
- if (!isInternal(href)) {
3717
- return;
3718
- }
3719
- e.preventDefault();
3720
- router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
3721
- };
3722
- const handleMouseEnter = (e) => {
3723
- onMouseEnter?.(e);
3724
- if (!disabled && effectivePreload === "intent" && isInternal(href)) {
3725
- intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
3726
- }
3727
- };
3728
- const handleMouseLeave = (e) => {
3729
- onMouseLeave?.(e);
3730
- if (intentTimerRef.current !== null) {
3731
- clearTimeout(intentTimerRef.current);
3732
- intentTimerRef.current = null;
3733
- }
3734
- };
3735
- const handleFocus = (e) => {
3736
- onFocus?.(e);
3737
- if (!disabled && effectivePreload === "intent" && isInternal(href)) {
3738
- triggerPrefetch();
3739
- }
3740
- };
3741
- return createElement("a", {
3742
- ref: anchorRef,
3743
- href,
3744
- onClick: handleClick,
3745
- onMouseEnter: handleMouseEnter,
3746
- onMouseLeave: handleMouseLeave,
3747
- onFocus: handleFocus,
3748
- ...isActive ? { "data-status": "active" } : {},
3749
- ...anchorProps,
3750
- ...extraProps,
3751
- ...disabled ? { "aria-disabled": true } : {}
3752
- }, resolvedChildren);
3753
- }
3754
- var SSR_FALLBACK_ROUTER = {
3755
- basePath: "",
3756
- currentHref: "/",
3757
- navigate: () => Promise.resolve(),
3758
- prefetch: () => {},
3759
- invalidatePrefetch: () => {},
3760
- refresh: () => Promise.resolve(),
3761
- isNavigating: false,
3762
- defaultPreload: "intent",
3763
- defaultPreloadDelay: 50,
3764
- defaultPreloadStaleTime: 30000
3765
- };
3766
- function renderLinkElement(props, router) {
3767
- const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
3768
- const {
3769
- to: _to,
3770
- search: _search,
3771
- hash: _hash,
3772
- children: _children,
3773
- activeProps: _ap,
3774
- inactiveProps: _ip,
3775
- disabled,
3776
- preload: _p,
3777
- preloadDelay: _pd,
3778
- preloadStaleTime: _ps,
3779
- replace: _r,
3780
- resetScroll: _rs,
3781
- onClick: _oc,
3782
- onMouseEnter: _ome,
3783
- onMouseLeave: _oml,
3784
- onFocus: _of,
3785
- ...anchorProps
3786
- } = props;
3787
- return createElement("a", {
3788
- href,
3789
- ...isActive ? { "data-status": "active" } : {},
3790
- ...anchorProps,
3791
- ...extraProps,
3792
- ...disabled ? { "aria-disabled": true } : {}
3793
- }, resolvedChildren);
3794
- }
3795
- function Link(props) {
3796
- if (typeof window === "undefined") {
3797
- return createElement(RouterContext.Consumer, {
3798
- children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
3799
- });
3800
- }
3801
- return createElement(LinkInteractive, props);
3802
- }
3803
3828
 
3804
3829
  // src/render/cache.ts
3805
3830
  import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
@@ -3850,33 +3875,139 @@ async function runInSyntheticRenderScope(fn, initialContext) {
3850
3875
  }
3851
3876
  }
3852
3877
 
3853
- // src/render/cache.ts
3854
- var MAX_SSG_CACHE_SIZE = 1000;
3855
- var isrCache = new Map;
3856
- var ssgCache = new Map;
3857
- function evictOldest(map, maxSize) {
3858
- if (map.size > maxSize) {
3859
- const oldest = map.keys().next().value;
3878
+ // src/render/route-cache.ts
3879
+ function defaultPathFromKey(key) {
3880
+ return key;
3881
+ }
3882
+ function matchesPath(urlPath, path, type) {
3883
+ if (type === "page") {
3884
+ return urlPath === path;
3885
+ }
3886
+ const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
3887
+ return urlPath === path || urlPath.startsWith(prefix);
3888
+ }
3889
+ function createRouteCache(options) {
3890
+ const store = new Map;
3891
+ const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
3892
+ const evictOldest = () => {
3893
+ if (options.maxSize === undefined || store.size <= options.maxSize) {
3894
+ return;
3895
+ }
3896
+ const oldest = store.keys().next().value;
3860
3897
  if (oldest !== undefined) {
3861
- map.delete(oldest);
3898
+ deleteEntry(oldest);
3862
3899
  }
3863
- }
3900
+ };
3901
+ const deleteEntry = (key) => {
3902
+ const entry = store.get(key);
3903
+ if (entry === undefined) {
3904
+ return false;
3905
+ }
3906
+ store.delete(key);
3907
+ options.onDelete?.(key, entry);
3908
+ return true;
3909
+ };
3910
+ return {
3911
+ name: options.name,
3912
+ store,
3913
+ get size() {
3914
+ return store.size;
3915
+ },
3916
+ get(key) {
3917
+ const entry = store.get(key);
3918
+ if (entry !== undefined && options.maxSize !== undefined) {
3919
+ store.delete(key);
3920
+ store.set(key, entry);
3921
+ }
3922
+ return entry;
3923
+ },
3924
+ set(key, entry) {
3925
+ const previous = store.get(key);
3926
+ if (previous !== undefined) {
3927
+ store.delete(key);
3928
+ }
3929
+ store.set(key, entry);
3930
+ options.onSet?.(key, entry, previous);
3931
+ evictOldest();
3932
+ },
3933
+ delete(key) {
3934
+ return deleteEntry(key);
3935
+ },
3936
+ clear() {
3937
+ for (const key of [...store.keys()]) {
3938
+ deleteEntry(key);
3939
+ }
3940
+ store.clear();
3941
+ },
3942
+ has(key) {
3943
+ return store.has(key);
3944
+ },
3945
+ entries() {
3946
+ return store.entries();
3947
+ },
3948
+ keys() {
3949
+ return store.keys();
3950
+ },
3951
+ invalidatePath(path, type) {
3952
+ let deleted = false;
3953
+ const purgedPaths = [];
3954
+ for (const key of [...store.keys()]) {
3955
+ const urlPath = pathFromKey(key);
3956
+ if (urlPath === null || !matchesPath(urlPath, path, type)) {
3957
+ continue;
3958
+ }
3959
+ deleteEntry(key);
3960
+ deleted = true;
3961
+ purgedPaths.push(urlPath);
3962
+ }
3963
+ return { deleted, purgedPaths: [...new Set(purgedPaths)] };
3964
+ }
3965
+ };
3864
3966
  }
3967
+
3968
+ // src/render/cache.ts
3969
+ var MAX_ISR_CACHE_SIZE = 1000;
3970
+ var MAX_SSG_CACHE_SIZE = 1000;
3971
+ var isrRouteCache = createRouteCache({
3972
+ maxSize: MAX_ISR_CACHE_SIZE,
3973
+ name: "render:isr-html"
3974
+ });
3975
+ var ssgRouteCache = createRouteCache({
3976
+ maxSize: MAX_SSG_CACHE_SIZE,
3977
+ name: "render:ssg-html"
3978
+ });
3979
+ var isrCache = isrRouteCache.store;
3980
+ var ssgCache = ssgRouteCache.store;
3865
3981
  function getSSGCache(key) {
3866
- const entry = ssgCache.get(key);
3867
- if (entry !== undefined) {
3868
- ssgCache.delete(key);
3869
- ssgCache.set(key, entry);
3870
- }
3871
- return entry;
3982
+ return ssgRouteCache.get(key);
3872
3983
  }
3873
3984
  function setSSGCache(key, entry) {
3874
- ssgCache.delete(key);
3875
- ssgCache.set(key, entry);
3876
- evictOldest(ssgCache, MAX_SSG_CACHE_SIZE);
3985
+ ssgRouteCache.set(key, entry);
3877
3986
  }
3878
3987
  var _requestInvalidationScope = new AsyncLocalStorage3;
3879
3988
  var _globalPendingInvalidations = new Set;
3989
+ var _cacheInvalidators = new Map;
3990
+ function registerCacheInvalidator(invalidator) {
3991
+ const existing = _cacheInvalidators.get(invalidator.name);
3992
+ if (existing !== undefined && existing !== invalidator) {
3993
+ throw new Error(`Cache invalidator "${invalidator.name}" is already registered with a different instance.`);
3994
+ }
3995
+ if (existing === invalidator) {
3996
+ return () => {
3997
+ if (_cacheInvalidators.get(invalidator.name) === invalidator) {
3998
+ _cacheInvalidators.delete(invalidator.name);
3999
+ }
4000
+ };
4001
+ }
4002
+ _cacheInvalidators.set(invalidator.name, invalidator);
4003
+ return () => {
4004
+ if (_cacheInvalidators.get(invalidator.name) === invalidator) {
4005
+ _cacheInvalidators.delete(invalidator.name);
4006
+ }
4007
+ };
4008
+ }
4009
+ registerCacheInvalidator(isrRouteCache);
4010
+ registerCacheInvalidator(ssgRouteCache);
3880
4011
 
3881
4012
  // src/render/element.tsx
3882
4013
  import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
@@ -4066,7 +4197,7 @@ var IS_DEV = true;
4066
4197
 
4067
4198
  // src/render/index.ts
4068
4199
  function withSSRRouterContext(element, contextValue) {
4069
- return createElement2(RouterContext.Provider, { value: contextValue }, element);
4200
+ return createElement3(RouterContext.Provider, { value: contextValue }, element);
4070
4201
  }
4071
4202
  async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
4072
4203
  const loaderStart = Date.now();
@@ -4385,9 +4516,55 @@ function getCompileContext() {
4385
4516
  }
4386
4517
 
4387
4518
  // src/render/dev-cache.ts
4388
- var devISRLoaderCache = new Map;
4389
- var devSSGLoaderCache = new Map;
4390
4519
  var sourceFileToCacheKeys = new Map;
4520
+ function indexEntryDependencies(cacheKey, deps) {
4521
+ for (const dep of deps) {
4522
+ let bucket = sourceFileToCacheKeys.get(dep);
4523
+ if (!bucket) {
4524
+ bucket = new Set;
4525
+ sourceFileToCacheKeys.set(dep, bucket);
4526
+ }
4527
+ bucket.add(cacheKey);
4528
+ }
4529
+ }
4530
+ function unindexEntryDependencies(cacheKey, deps) {
4531
+ for (const dep of deps) {
4532
+ const bucket = sourceFileToCacheKeys.get(dep);
4533
+ if (!bucket) {
4534
+ continue;
4535
+ }
4536
+ bucket.delete(cacheKey);
4537
+ if (bucket.size === 0) {
4538
+ sourceFileToCacheKeys.delete(dep);
4539
+ }
4540
+ }
4541
+ }
4542
+ function createDevLoaderCache(name) {
4543
+ return createRouteCache({
4544
+ name,
4545
+ onDelete: (key, entry) => {
4546
+ unindexEntryDependencies(key, entry.dependencies);
4547
+ },
4548
+ onSet: (key, entry, previous) => {
4549
+ if (previous) {
4550
+ unindexEntryDependencies(key, previous.dependencies);
4551
+ }
4552
+ indexEntryDependencies(key, entry.dependencies);
4553
+ },
4554
+ pathFromKey: urlPathFromCacheKey
4555
+ });
4556
+ }
4557
+ var devISRLoaderCache = createDevLoaderCache("render:dev-isr-loader");
4558
+ var devSSGLoaderCache = createDevLoaderCache("render:dev-ssg-loader");
4559
+ function urlPathFromCacheKey(key) {
4560
+ const sep2 = key.lastIndexOf(":/");
4561
+ if (sep2 === -1) {
4562
+ return null;
4563
+ }
4564
+ return key.slice(sep2 + 1);
4565
+ }
4566
+ registerCacheInvalidator(devISRLoaderCache);
4567
+ registerCacheInvalidator(devSSGLoaderCache);
4391
4568
 
4392
4569
  // src/utils.ts
4393
4570
  function isFurinPage(value) {