@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.
- package/dist/build/index.js +394 -217
- package/dist/cli/index.js +394 -217
- package/dist/furin.js +394 -259
- package/dist/link.d.ts +5 -438
- package/dist/link.js +225 -136
- package/dist/render/cache.d.ts +18 -5
- package/dist/render/dev-cache.d.ts +29 -0
- package/dist/render/route-cache.d.ts +26 -0
- package/dist/router-provider.d.ts +466 -0
- package/dist/router.js +508 -369
- package/package.json +6 -5
- package/src/build/hydrate.ts +7 -5
- package/src/dev-page-plugin.ts +6 -0
- package/src/link.tsx +40 -1295
- package/src/render/cache.ts +77 -67
- package/src/render/dev-cache.ts +106 -15
- package/src/render/index.ts +1 -1
- package/src/render/route-cache.ts +124 -0
- package/src/router-provider.tsx +1426 -0
package/dist/cli/index.js
CHANGED
|
@@ -1537,10 +1537,15 @@ function generateHydrateEntry(routes, rootLayout, basePath) {
|
|
|
1537
1537
|
const conventionImportLines = [...conventionIdents.entries()].map(([filePath, ident]) => `import ${ident} from "${filePath.replace(/\\/g, "/")}";`).join(`
|
|
1538
1538
|
`);
|
|
1539
1539
|
const basePathLiteral = JSON.stringify(basePath);
|
|
1540
|
-
const pathnameExpr = basePath ? `(() => { const p = window.location.pathname; const b = ${basePathLiteral};
|
|
1540
|
+
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(/\\/+$/, "") || "/"`;
|
|
1541
1541
|
const logEndpoint = basePath ? `${JSON.stringify(basePath)} + "/_furin/ingest"` : `"/_furin/ingest"`;
|
|
1542
|
-
const
|
|
1543
|
-
|
|
1542
|
+
const routerProviderDefaults = `
|
|
1543
|
+
autoRefresh: true,
|
|
1544
|
+
basePath: ${basePathLiteral},
|
|
1545
|
+
defaultPreload: "intent",
|
|
1546
|
+
defaultPreloadDelay: 50,
|
|
1547
|
+
defaultPreloadStaleTime: 30000,
|
|
1548
|
+
prefetchCacheSize: 50,`;
|
|
1544
1549
|
const conventionImportsBlock = conventionImportLines ? `
|
|
1545
1550
|
${conventionImportLines}` : "";
|
|
1546
1551
|
return `import { hydrateRoot, createRoot } from "react-dom/client";
|
|
@@ -1589,7 +1594,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
1589
1594
|
initialMatch: match,
|
|
1590
1595
|
initialData: loaderData,
|
|
1591
1596
|
initialDigest: loaderData.__furinError?.digest,
|
|
1592
|
-
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${
|
|
1597
|
+
initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
|
|
1593
1598
|
} as any);
|
|
1594
1599
|
} else if (loaderData.__furinStatus === 404) {
|
|
1595
1600
|
// Direct load to an unknown URL. The server sent the root not-found UI
|
|
@@ -1606,7 +1611,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
|
|
|
1606
1611
|
initialMatch: null,
|
|
1607
1612
|
initialData: cleanData,
|
|
1608
1613
|
initialDigest: loaderData.__furinError?.digest,
|
|
1609
|
-
initialNotFound: loaderData.__furinNotFound ?? {},${
|
|
1614
|
+
initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
|
|
1610
1615
|
} as any);
|
|
1611
1616
|
} else {
|
|
1612
1617
|
// No match and no 404 signal \u2014 either the client bundle is out of sync
|
|
@@ -2175,9 +2180,24 @@ function assembleHTML(template, headData, reactHtml, data) {
|
|
|
2175
2180
|
}
|
|
2176
2181
|
|
|
2177
2182
|
// src/render/index.ts
|
|
2178
|
-
import { createElement as
|
|
2183
|
+
import { createElement as createElement3 } from "react";
|
|
2179
2184
|
import { renderToReadableStream } from "react-dom/server";
|
|
2180
2185
|
|
|
2186
|
+
// src/not-found.ts
|
|
2187
|
+
var NOT_FOUND_BRAND = "FURIN_NOT_FOUND";
|
|
2188
|
+
|
|
2189
|
+
class FurinNotFoundError extends Error {
|
|
2190
|
+
__furinBrand = NOT_FOUND_BRAND;
|
|
2191
|
+
data;
|
|
2192
|
+
constructor(options) {
|
|
2193
|
+
super(options?.message ?? "");
|
|
2194
|
+
this.data = options?.data;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
function isNotFoundError(err) {
|
|
2198
|
+
return err instanceof FurinNotFoundError || typeof err === "object" && err !== null && err.__furinBrand === NOT_FOUND_BRAND;
|
|
2199
|
+
}
|
|
2200
|
+
|
|
2181
2201
|
// ../../node_modules/.bun/evlog@2.14.1+6b630eaba8c4f70c/node_modules/evlog/dist/utils.mjs
|
|
2182
2202
|
function formatDuration(ms) {
|
|
2183
2203
|
if (ms < 1000)
|
|
@@ -3083,15 +3103,16 @@ function finalizeAudit(event) {
|
|
|
3083
3103
|
return;
|
|
3084
3104
|
event.audit = decorateAudit(a, String(event.timestamp));
|
|
3085
3105
|
}
|
|
3086
|
-
// src/
|
|
3106
|
+
// src/router-provider.tsx
|
|
3087
3107
|
import {
|
|
3088
3108
|
createContext,
|
|
3089
|
-
createElement,
|
|
3090
|
-
useCallback,
|
|
3109
|
+
createElement as createElement2,
|
|
3110
|
+
useCallback as useCallback2,
|
|
3091
3111
|
useContext,
|
|
3092
|
-
useEffect,
|
|
3112
|
+
useEffect as useEffect2,
|
|
3113
|
+
useLayoutEffect,
|
|
3093
3114
|
useMemo,
|
|
3094
|
-
useRef,
|
|
3115
|
+
useRef as useRef2,
|
|
3095
3116
|
useState
|
|
3096
3117
|
} from "react";
|
|
3097
3118
|
|
|
@@ -3107,19 +3128,193 @@ function getPublicErrorMessage(error) {
|
|
|
3107
3128
|
return "Something went wrong";
|
|
3108
3129
|
}
|
|
3109
3130
|
|
|
3110
|
-
// src/
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3131
|
+
// src/link.tsx
|
|
3132
|
+
import { createElement, useCallback, useEffect, useRef } from "react";
|
|
3133
|
+
function computeLinkView({
|
|
3134
|
+
to,
|
|
3135
|
+
search,
|
|
3136
|
+
hash,
|
|
3137
|
+
children,
|
|
3138
|
+
activeProps,
|
|
3139
|
+
inactiveProps
|
|
3140
|
+
}, router) {
|
|
3141
|
+
const logicalHref = buildHref(to, search, hash);
|
|
3142
|
+
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3143
|
+
const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
|
|
3144
|
+
const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
|
|
3145
|
+
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
3146
|
+
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3147
|
+
const extraProps = {
|
|
3148
|
+
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
3149
|
+
...activeProps ? activeProps({ isActive }) : {}
|
|
3150
|
+
};
|
|
3151
|
+
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
3120
3152
|
}
|
|
3121
|
-
function
|
|
3122
|
-
|
|
3153
|
+
function LinkInteractive({
|
|
3154
|
+
to,
|
|
3155
|
+
search,
|
|
3156
|
+
hash,
|
|
3157
|
+
preload,
|
|
3158
|
+
preloadDelay,
|
|
3159
|
+
preloadStaleTime,
|
|
3160
|
+
replace,
|
|
3161
|
+
disabled,
|
|
3162
|
+
resetScroll,
|
|
3163
|
+
activeProps,
|
|
3164
|
+
inactiveProps,
|
|
3165
|
+
onClick,
|
|
3166
|
+
onMouseEnter,
|
|
3167
|
+
onMouseLeave,
|
|
3168
|
+
onFocus,
|
|
3169
|
+
children,
|
|
3170
|
+
href: _href,
|
|
3171
|
+
...anchorProps
|
|
3172
|
+
}) {
|
|
3173
|
+
const router = useRouter();
|
|
3174
|
+
const anchorRef = useRef(null);
|
|
3175
|
+
const intentTimerRef = useRef(null);
|
|
3176
|
+
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
|
|
3177
|
+
const effectivePreload = preload ?? router.defaultPreload;
|
|
3178
|
+
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
3179
|
+
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
3180
|
+
const triggerPrefetch = useCallback(() => {
|
|
3181
|
+
router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
3182
|
+
}, [router, logicalHref, effectiveStaleTime]);
|
|
3183
|
+
useEffect(() => {
|
|
3184
|
+
if (effectivePreload === "render") {
|
|
3185
|
+
triggerPrefetch();
|
|
3186
|
+
}
|
|
3187
|
+
}, [effectivePreload, triggerPrefetch]);
|
|
3188
|
+
useEffect(() => {
|
|
3189
|
+
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
3190
|
+
return;
|
|
3191
|
+
}
|
|
3192
|
+
const observer = new IntersectionObserver(([entry]) => {
|
|
3193
|
+
if (entry?.isIntersecting) {
|
|
3194
|
+
triggerPrefetch();
|
|
3195
|
+
observer.disconnect();
|
|
3196
|
+
}
|
|
3197
|
+
}, { rootMargin: "200px" });
|
|
3198
|
+
observer.observe(anchorRef.current);
|
|
3199
|
+
return () => observer.disconnect();
|
|
3200
|
+
}, [effectivePreload, triggerPrefetch]);
|
|
3201
|
+
useEffect(() => () => {
|
|
3202
|
+
if (intentTimerRef.current !== null) {
|
|
3203
|
+
clearTimeout(intentTimerRef.current);
|
|
3204
|
+
intentTimerRef.current = null;
|
|
3205
|
+
}
|
|
3206
|
+
}, []);
|
|
3207
|
+
const isInternal = (url) => {
|
|
3208
|
+
try {
|
|
3209
|
+
return new URL(url, window.location.origin).origin === window.location.origin;
|
|
3210
|
+
} catch {
|
|
3211
|
+
return false;
|
|
3212
|
+
}
|
|
3213
|
+
};
|
|
3214
|
+
const handleClick = (e) => {
|
|
3215
|
+
onClick?.(e);
|
|
3216
|
+
if (e.defaultPrevented) {
|
|
3217
|
+
return;
|
|
3218
|
+
}
|
|
3219
|
+
if (disabled) {
|
|
3220
|
+
e.preventDefault();
|
|
3221
|
+
return;
|
|
3222
|
+
}
|
|
3223
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
if (anchorProps.target && anchorProps.target !== "_self") {
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
if (!isInternal(href)) {
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3232
|
+
e.preventDefault();
|
|
3233
|
+
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
3234
|
+
};
|
|
3235
|
+
const handleMouseEnter = (e) => {
|
|
3236
|
+
onMouseEnter?.(e);
|
|
3237
|
+
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3238
|
+
intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
|
|
3239
|
+
}
|
|
3240
|
+
};
|
|
3241
|
+
const handleMouseLeave = (e) => {
|
|
3242
|
+
onMouseLeave?.(e);
|
|
3243
|
+
if (intentTimerRef.current !== null) {
|
|
3244
|
+
clearTimeout(intentTimerRef.current);
|
|
3245
|
+
intentTimerRef.current = null;
|
|
3246
|
+
}
|
|
3247
|
+
};
|
|
3248
|
+
const handleFocus = (e) => {
|
|
3249
|
+
onFocus?.(e);
|
|
3250
|
+
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3251
|
+
triggerPrefetch();
|
|
3252
|
+
}
|
|
3253
|
+
};
|
|
3254
|
+
return createElement("a", {
|
|
3255
|
+
ref: anchorRef,
|
|
3256
|
+
href,
|
|
3257
|
+
"data-furin-link": true,
|
|
3258
|
+
onClick: handleClick,
|
|
3259
|
+
onMouseEnter: handleMouseEnter,
|
|
3260
|
+
onMouseLeave: handleMouseLeave,
|
|
3261
|
+
onFocus: handleFocus,
|
|
3262
|
+
...isActive ? { "data-status": "active" } : {},
|
|
3263
|
+
...anchorProps,
|
|
3264
|
+
...extraProps,
|
|
3265
|
+
...disabled ? { "aria-disabled": true } : {}
|
|
3266
|
+
}, resolvedChildren);
|
|
3267
|
+
}
|
|
3268
|
+
var SSR_FALLBACK_ROUTER = {
|
|
3269
|
+
basePath: "",
|
|
3270
|
+
currentHref: "/",
|
|
3271
|
+
navigate: () => Promise.resolve(),
|
|
3272
|
+
prefetch: () => {},
|
|
3273
|
+
invalidatePrefetch: () => {},
|
|
3274
|
+
refresh: () => Promise.resolve(),
|
|
3275
|
+
isNavigating: false,
|
|
3276
|
+
defaultPreload: "intent",
|
|
3277
|
+
defaultPreloadDelay: 50,
|
|
3278
|
+
defaultPreloadStaleTime: 30000
|
|
3279
|
+
};
|
|
3280
|
+
function renderLinkElement(props, router) {
|
|
3281
|
+
const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
|
|
3282
|
+
const {
|
|
3283
|
+
to: _to,
|
|
3284
|
+
search: _search,
|
|
3285
|
+
hash: _hash,
|
|
3286
|
+
children: _children,
|
|
3287
|
+
activeProps: _ap,
|
|
3288
|
+
inactiveProps: _ip,
|
|
3289
|
+
disabled,
|
|
3290
|
+
preload: _p,
|
|
3291
|
+
preloadDelay: _pd,
|
|
3292
|
+
preloadStaleTime: _ps,
|
|
3293
|
+
replace: _r,
|
|
3294
|
+
resetScroll: _rs,
|
|
3295
|
+
onClick: _oc,
|
|
3296
|
+
onMouseEnter: _ome,
|
|
3297
|
+
onMouseLeave: _oml,
|
|
3298
|
+
onFocus: _of,
|
|
3299
|
+
href: _href,
|
|
3300
|
+
...anchorProps
|
|
3301
|
+
} = props;
|
|
3302
|
+
return createElement("a", {
|
|
3303
|
+
href,
|
|
3304
|
+
"data-furin-link": true,
|
|
3305
|
+
...isActive ? { "data-status": "active" } : {},
|
|
3306
|
+
...anchorProps,
|
|
3307
|
+
...extraProps,
|
|
3308
|
+
...disabled ? { "aria-disabled": true } : {}
|
|
3309
|
+
}, resolvedChildren);
|
|
3310
|
+
}
|
|
3311
|
+
function Link(props) {
|
|
3312
|
+
if (typeof window === "undefined") {
|
|
3313
|
+
return createElement(RouterContext.Consumer, {
|
|
3314
|
+
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
3315
|
+
});
|
|
3316
|
+
}
|
|
3317
|
+
return createElement(LinkInteractive, props);
|
|
3123
3318
|
}
|
|
3124
3319
|
|
|
3125
3320
|
// src/render/default-screens.tsx
|
|
@@ -3507,7 +3702,7 @@ class FurinNotFoundBoundary extends Component {
|
|
|
3507
3702
|
}
|
|
3508
3703
|
}
|
|
3509
3704
|
|
|
3510
|
-
// src/
|
|
3705
|
+
// src/router-provider.tsx
|
|
3511
3706
|
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
3512
3707
|
function buildHref(to, search, hash) {
|
|
3513
3708
|
let url = to;
|
|
@@ -3530,7 +3725,8 @@ function buildHref(to, search, hash) {
|
|
|
3530
3725
|
}
|
|
3531
3726
|
var RouterContext = createContext(null);
|
|
3532
3727
|
function useRouter() {
|
|
3533
|
-
|
|
3728
|
+
const ctx = useContext(RouterContext);
|
|
3729
|
+
return ctx ?? {
|
|
3534
3730
|
basePath: "",
|
|
3535
3731
|
currentHref: "/",
|
|
3536
3732
|
navigate: (href) => {
|
|
@@ -3549,177 +3745,6 @@ function useRouter() {
|
|
|
3549
3745
|
defaultPreloadStaleTime: 30000
|
|
3550
3746
|
};
|
|
3551
3747
|
}
|
|
3552
|
-
function computeLinkView({
|
|
3553
|
-
to,
|
|
3554
|
-
search,
|
|
3555
|
-
hash,
|
|
3556
|
-
children,
|
|
3557
|
-
activeProps,
|
|
3558
|
-
inactiveProps
|
|
3559
|
-
}, router) {
|
|
3560
|
-
const logicalHref = buildHref(to, search, hash);
|
|
3561
|
-
const logicalHrefWithoutHash = buildHref(to, search, undefined);
|
|
3562
|
-
const href = router.basePath + logicalHref;
|
|
3563
|
-
const isActive = router.currentHref === logicalHrefWithoutHash;
|
|
3564
|
-
const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
|
|
3565
|
-
const extraProps = {
|
|
3566
|
-
...inactiveProps && !isActive ? inactiveProps() : {},
|
|
3567
|
-
...activeProps ? activeProps({ isActive }) : {}
|
|
3568
|
-
};
|
|
3569
|
-
return { logicalHref, href, isActive, resolvedChildren, extraProps };
|
|
3570
|
-
}
|
|
3571
|
-
function LinkInteractive({
|
|
3572
|
-
to,
|
|
3573
|
-
search,
|
|
3574
|
-
hash,
|
|
3575
|
-
preload,
|
|
3576
|
-
preloadDelay,
|
|
3577
|
-
preloadStaleTime,
|
|
3578
|
-
replace,
|
|
3579
|
-
disabled,
|
|
3580
|
-
resetScroll,
|
|
3581
|
-
activeProps,
|
|
3582
|
-
inactiveProps,
|
|
3583
|
-
onClick,
|
|
3584
|
-
onMouseEnter,
|
|
3585
|
-
onMouseLeave,
|
|
3586
|
-
onFocus,
|
|
3587
|
-
children,
|
|
3588
|
-
...anchorProps
|
|
3589
|
-
}) {
|
|
3590
|
-
const router = useRouter();
|
|
3591
|
-
const anchorRef = useRef(null);
|
|
3592
|
-
const intentTimerRef = useRef(null);
|
|
3593
|
-
const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
|
|
3594
|
-
const effectivePreload = preload ?? router.defaultPreload;
|
|
3595
|
-
const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
|
|
3596
|
-
const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
|
|
3597
|
-
const triggerPrefetch = useCallback(() => {
|
|
3598
|
-
router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
|
|
3599
|
-
}, [router, logicalHref, effectiveStaleTime]);
|
|
3600
|
-
useEffect(() => {
|
|
3601
|
-
if (effectivePreload === "render") {
|
|
3602
|
-
triggerPrefetch();
|
|
3603
|
-
}
|
|
3604
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
3605
|
-
useEffect(() => {
|
|
3606
|
-
if (effectivePreload !== "viewport" || !anchorRef.current) {
|
|
3607
|
-
return;
|
|
3608
|
-
}
|
|
3609
|
-
const observer = new IntersectionObserver(([entry]) => {
|
|
3610
|
-
if (entry?.isIntersecting) {
|
|
3611
|
-
triggerPrefetch();
|
|
3612
|
-
observer.disconnect();
|
|
3613
|
-
}
|
|
3614
|
-
}, { rootMargin: "200px" });
|
|
3615
|
-
observer.observe(anchorRef.current);
|
|
3616
|
-
return () => observer.disconnect();
|
|
3617
|
-
}, [effectivePreload, triggerPrefetch]);
|
|
3618
|
-
const isInternal = (url) => {
|
|
3619
|
-
try {
|
|
3620
|
-
return new URL(url, window.location.origin).origin === window.location.origin;
|
|
3621
|
-
} catch {
|
|
3622
|
-
return false;
|
|
3623
|
-
}
|
|
3624
|
-
};
|
|
3625
|
-
const handleClick = (e) => {
|
|
3626
|
-
onClick?.(e);
|
|
3627
|
-
if (e.defaultPrevented || disabled) {
|
|
3628
|
-
return;
|
|
3629
|
-
}
|
|
3630
|
-
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
3631
|
-
return;
|
|
3632
|
-
}
|
|
3633
|
-
if (anchorProps.target && anchorProps.target !== "_self") {
|
|
3634
|
-
return;
|
|
3635
|
-
}
|
|
3636
|
-
if (!isInternal(href)) {
|
|
3637
|
-
return;
|
|
3638
|
-
}
|
|
3639
|
-
e.preventDefault();
|
|
3640
|
-
router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
|
|
3641
|
-
};
|
|
3642
|
-
const handleMouseEnter = (e) => {
|
|
3643
|
-
onMouseEnter?.(e);
|
|
3644
|
-
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3645
|
-
intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
|
|
3646
|
-
}
|
|
3647
|
-
};
|
|
3648
|
-
const handleMouseLeave = (e) => {
|
|
3649
|
-
onMouseLeave?.(e);
|
|
3650
|
-
if (intentTimerRef.current !== null) {
|
|
3651
|
-
clearTimeout(intentTimerRef.current);
|
|
3652
|
-
intentTimerRef.current = null;
|
|
3653
|
-
}
|
|
3654
|
-
};
|
|
3655
|
-
const handleFocus = (e) => {
|
|
3656
|
-
onFocus?.(e);
|
|
3657
|
-
if (!disabled && effectivePreload === "intent" && isInternal(href)) {
|
|
3658
|
-
triggerPrefetch();
|
|
3659
|
-
}
|
|
3660
|
-
};
|
|
3661
|
-
return createElement("a", {
|
|
3662
|
-
ref: anchorRef,
|
|
3663
|
-
href,
|
|
3664
|
-
onClick: handleClick,
|
|
3665
|
-
onMouseEnter: handleMouseEnter,
|
|
3666
|
-
onMouseLeave: handleMouseLeave,
|
|
3667
|
-
onFocus: handleFocus,
|
|
3668
|
-
...isActive ? { "data-status": "active" } : {},
|
|
3669
|
-
...anchorProps,
|
|
3670
|
-
...extraProps,
|
|
3671
|
-
...disabled ? { "aria-disabled": true } : {}
|
|
3672
|
-
}, resolvedChildren);
|
|
3673
|
-
}
|
|
3674
|
-
var SSR_FALLBACK_ROUTER = {
|
|
3675
|
-
basePath: "",
|
|
3676
|
-
currentHref: "/",
|
|
3677
|
-
navigate: () => Promise.resolve(),
|
|
3678
|
-
prefetch: () => {},
|
|
3679
|
-
invalidatePrefetch: () => {},
|
|
3680
|
-
refresh: () => Promise.resolve(),
|
|
3681
|
-
isNavigating: false,
|
|
3682
|
-
defaultPreload: "intent",
|
|
3683
|
-
defaultPreloadDelay: 50,
|
|
3684
|
-
defaultPreloadStaleTime: 30000
|
|
3685
|
-
};
|
|
3686
|
-
function renderLinkElement(props, router) {
|
|
3687
|
-
const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
|
|
3688
|
-
const {
|
|
3689
|
-
to: _to,
|
|
3690
|
-
search: _search,
|
|
3691
|
-
hash: _hash,
|
|
3692
|
-
children: _children,
|
|
3693
|
-
activeProps: _ap,
|
|
3694
|
-
inactiveProps: _ip,
|
|
3695
|
-
disabled,
|
|
3696
|
-
preload: _p,
|
|
3697
|
-
preloadDelay: _pd,
|
|
3698
|
-
preloadStaleTime: _ps,
|
|
3699
|
-
replace: _r,
|
|
3700
|
-
resetScroll: _rs,
|
|
3701
|
-
onClick: _oc,
|
|
3702
|
-
onMouseEnter: _ome,
|
|
3703
|
-
onMouseLeave: _oml,
|
|
3704
|
-
onFocus: _of,
|
|
3705
|
-
...anchorProps
|
|
3706
|
-
} = props;
|
|
3707
|
-
return createElement("a", {
|
|
3708
|
-
href,
|
|
3709
|
-
...isActive ? { "data-status": "active" } : {},
|
|
3710
|
-
...anchorProps,
|
|
3711
|
-
...extraProps,
|
|
3712
|
-
...disabled ? { "aria-disabled": true } : {}
|
|
3713
|
-
}, resolvedChildren);
|
|
3714
|
-
}
|
|
3715
|
-
function Link(props) {
|
|
3716
|
-
if (typeof window === "undefined") {
|
|
3717
|
-
return createElement(RouterContext.Consumer, {
|
|
3718
|
-
children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
|
|
3719
|
-
});
|
|
3720
|
-
}
|
|
3721
|
-
return createElement(LinkInteractive, props);
|
|
3722
|
-
}
|
|
3723
3748
|
|
|
3724
3749
|
// src/render/cache.ts
|
|
3725
3750
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
|
|
@@ -3770,33 +3795,139 @@ async function runInSyntheticRenderScope(fn, initialContext) {
|
|
|
3770
3795
|
}
|
|
3771
3796
|
}
|
|
3772
3797
|
|
|
3773
|
-
// src/render/cache.ts
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
function
|
|
3778
|
-
if (
|
|
3779
|
-
|
|
3798
|
+
// src/render/route-cache.ts
|
|
3799
|
+
function defaultPathFromKey(key) {
|
|
3800
|
+
return key;
|
|
3801
|
+
}
|
|
3802
|
+
function matchesPath(urlPath, path, type) {
|
|
3803
|
+
if (type === "page") {
|
|
3804
|
+
return urlPath === path;
|
|
3805
|
+
}
|
|
3806
|
+
const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
|
|
3807
|
+
return urlPath === path || urlPath.startsWith(prefix);
|
|
3808
|
+
}
|
|
3809
|
+
function createRouteCache(options) {
|
|
3810
|
+
const store = new Map;
|
|
3811
|
+
const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
|
|
3812
|
+
const evictOldest = () => {
|
|
3813
|
+
if (options.maxSize === undefined || store.size <= options.maxSize) {
|
|
3814
|
+
return;
|
|
3815
|
+
}
|
|
3816
|
+
const oldest = store.keys().next().value;
|
|
3780
3817
|
if (oldest !== undefined) {
|
|
3781
|
-
|
|
3818
|
+
deleteEntry(oldest);
|
|
3782
3819
|
}
|
|
3783
|
-
}
|
|
3820
|
+
};
|
|
3821
|
+
const deleteEntry = (key) => {
|
|
3822
|
+
const entry = store.get(key);
|
|
3823
|
+
if (entry === undefined) {
|
|
3824
|
+
return false;
|
|
3825
|
+
}
|
|
3826
|
+
store.delete(key);
|
|
3827
|
+
options.onDelete?.(key, entry);
|
|
3828
|
+
return true;
|
|
3829
|
+
};
|
|
3830
|
+
return {
|
|
3831
|
+
name: options.name,
|
|
3832
|
+
store,
|
|
3833
|
+
get size() {
|
|
3834
|
+
return store.size;
|
|
3835
|
+
},
|
|
3836
|
+
get(key) {
|
|
3837
|
+
const entry = store.get(key);
|
|
3838
|
+
if (entry !== undefined && options.maxSize !== undefined) {
|
|
3839
|
+
store.delete(key);
|
|
3840
|
+
store.set(key, entry);
|
|
3841
|
+
}
|
|
3842
|
+
return entry;
|
|
3843
|
+
},
|
|
3844
|
+
set(key, entry) {
|
|
3845
|
+
const previous = store.get(key);
|
|
3846
|
+
if (previous !== undefined) {
|
|
3847
|
+
store.delete(key);
|
|
3848
|
+
}
|
|
3849
|
+
store.set(key, entry);
|
|
3850
|
+
options.onSet?.(key, entry, previous);
|
|
3851
|
+
evictOldest();
|
|
3852
|
+
},
|
|
3853
|
+
delete(key) {
|
|
3854
|
+
return deleteEntry(key);
|
|
3855
|
+
},
|
|
3856
|
+
clear() {
|
|
3857
|
+
for (const key of [...store.keys()]) {
|
|
3858
|
+
deleteEntry(key);
|
|
3859
|
+
}
|
|
3860
|
+
store.clear();
|
|
3861
|
+
},
|
|
3862
|
+
has(key) {
|
|
3863
|
+
return store.has(key);
|
|
3864
|
+
},
|
|
3865
|
+
entries() {
|
|
3866
|
+
return store.entries();
|
|
3867
|
+
},
|
|
3868
|
+
keys() {
|
|
3869
|
+
return store.keys();
|
|
3870
|
+
},
|
|
3871
|
+
invalidatePath(path, type) {
|
|
3872
|
+
let deleted = false;
|
|
3873
|
+
const purgedPaths = [];
|
|
3874
|
+
for (const key of [...store.keys()]) {
|
|
3875
|
+
const urlPath = pathFromKey(key);
|
|
3876
|
+
if (urlPath === null || !matchesPath(urlPath, path, type)) {
|
|
3877
|
+
continue;
|
|
3878
|
+
}
|
|
3879
|
+
deleteEntry(key);
|
|
3880
|
+
deleted = true;
|
|
3881
|
+
purgedPaths.push(urlPath);
|
|
3882
|
+
}
|
|
3883
|
+
return { deleted, purgedPaths: [...new Set(purgedPaths)] };
|
|
3884
|
+
}
|
|
3885
|
+
};
|
|
3784
3886
|
}
|
|
3887
|
+
|
|
3888
|
+
// src/render/cache.ts
|
|
3889
|
+
var MAX_ISR_CACHE_SIZE = 1000;
|
|
3890
|
+
var MAX_SSG_CACHE_SIZE = 1000;
|
|
3891
|
+
var isrRouteCache = createRouteCache({
|
|
3892
|
+
maxSize: MAX_ISR_CACHE_SIZE,
|
|
3893
|
+
name: "render:isr-html"
|
|
3894
|
+
});
|
|
3895
|
+
var ssgRouteCache = createRouteCache({
|
|
3896
|
+
maxSize: MAX_SSG_CACHE_SIZE,
|
|
3897
|
+
name: "render:ssg-html"
|
|
3898
|
+
});
|
|
3899
|
+
var isrCache = isrRouteCache.store;
|
|
3900
|
+
var ssgCache = ssgRouteCache.store;
|
|
3785
3901
|
function getSSGCache(key) {
|
|
3786
|
-
|
|
3787
|
-
if (entry !== undefined) {
|
|
3788
|
-
ssgCache.delete(key);
|
|
3789
|
-
ssgCache.set(key, entry);
|
|
3790
|
-
}
|
|
3791
|
-
return entry;
|
|
3902
|
+
return ssgRouteCache.get(key);
|
|
3792
3903
|
}
|
|
3793
3904
|
function setSSGCache(key, entry) {
|
|
3794
|
-
|
|
3795
|
-
ssgCache.set(key, entry);
|
|
3796
|
-
evictOldest(ssgCache, MAX_SSG_CACHE_SIZE);
|
|
3905
|
+
ssgRouteCache.set(key, entry);
|
|
3797
3906
|
}
|
|
3798
3907
|
var _requestInvalidationScope = new AsyncLocalStorage3;
|
|
3799
3908
|
var _globalPendingInvalidations = new Set;
|
|
3909
|
+
var _cacheInvalidators = new Map;
|
|
3910
|
+
function registerCacheInvalidator(invalidator) {
|
|
3911
|
+
const existing = _cacheInvalidators.get(invalidator.name);
|
|
3912
|
+
if (existing !== undefined && existing !== invalidator) {
|
|
3913
|
+
throw new Error(`Cache invalidator "${invalidator.name}" is already registered with a different instance.`);
|
|
3914
|
+
}
|
|
3915
|
+
if (existing === invalidator) {
|
|
3916
|
+
return () => {
|
|
3917
|
+
if (_cacheInvalidators.get(invalidator.name) === invalidator) {
|
|
3918
|
+
_cacheInvalidators.delete(invalidator.name);
|
|
3919
|
+
}
|
|
3920
|
+
};
|
|
3921
|
+
}
|
|
3922
|
+
_cacheInvalidators.set(invalidator.name, invalidator);
|
|
3923
|
+
return () => {
|
|
3924
|
+
if (_cacheInvalidators.get(invalidator.name) === invalidator) {
|
|
3925
|
+
_cacheInvalidators.delete(invalidator.name);
|
|
3926
|
+
}
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
registerCacheInvalidator(isrRouteCache);
|
|
3930
|
+
registerCacheInvalidator(ssgRouteCache);
|
|
3800
3931
|
|
|
3801
3932
|
// src/render/element.tsx
|
|
3802
3933
|
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
@@ -3986,7 +4117,7 @@ var IS_DEV = true;
|
|
|
3986
4117
|
|
|
3987
4118
|
// src/render/index.ts
|
|
3988
4119
|
function withSSRRouterContext(element, contextValue) {
|
|
3989
|
-
return
|
|
4120
|
+
return createElement3(RouterContext.Provider, { value: contextValue }, element);
|
|
3990
4121
|
}
|
|
3991
4122
|
async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
|
|
3992
4123
|
const loaderStart = Date.now();
|
|
@@ -4305,9 +4436,55 @@ function getCompileContext() {
|
|
|
4305
4436
|
}
|
|
4306
4437
|
|
|
4307
4438
|
// src/render/dev-cache.ts
|
|
4308
|
-
var devISRLoaderCache = new Map;
|
|
4309
|
-
var devSSGLoaderCache = new Map;
|
|
4310
4439
|
var sourceFileToCacheKeys = new Map;
|
|
4440
|
+
function indexEntryDependencies(cacheKey, deps) {
|
|
4441
|
+
for (const dep of deps) {
|
|
4442
|
+
let bucket = sourceFileToCacheKeys.get(dep);
|
|
4443
|
+
if (!bucket) {
|
|
4444
|
+
bucket = new Set;
|
|
4445
|
+
sourceFileToCacheKeys.set(dep, bucket);
|
|
4446
|
+
}
|
|
4447
|
+
bucket.add(cacheKey);
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
function unindexEntryDependencies(cacheKey, deps) {
|
|
4451
|
+
for (const dep of deps) {
|
|
4452
|
+
const bucket = sourceFileToCacheKeys.get(dep);
|
|
4453
|
+
if (!bucket) {
|
|
4454
|
+
continue;
|
|
4455
|
+
}
|
|
4456
|
+
bucket.delete(cacheKey);
|
|
4457
|
+
if (bucket.size === 0) {
|
|
4458
|
+
sourceFileToCacheKeys.delete(dep);
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
function createDevLoaderCache(name) {
|
|
4463
|
+
return createRouteCache({
|
|
4464
|
+
name,
|
|
4465
|
+
onDelete: (key, entry) => {
|
|
4466
|
+
unindexEntryDependencies(key, entry.dependencies);
|
|
4467
|
+
},
|
|
4468
|
+
onSet: (key, entry, previous) => {
|
|
4469
|
+
if (previous) {
|
|
4470
|
+
unindexEntryDependencies(key, previous.dependencies);
|
|
4471
|
+
}
|
|
4472
|
+
indexEntryDependencies(key, entry.dependencies);
|
|
4473
|
+
},
|
|
4474
|
+
pathFromKey: urlPathFromCacheKey
|
|
4475
|
+
});
|
|
4476
|
+
}
|
|
4477
|
+
var devISRLoaderCache = createDevLoaderCache("render:dev-isr-loader");
|
|
4478
|
+
var devSSGLoaderCache = createDevLoaderCache("render:dev-ssg-loader");
|
|
4479
|
+
function urlPathFromCacheKey(key) {
|
|
4480
|
+
const sep2 = key.lastIndexOf(":/");
|
|
4481
|
+
if (sep2 === -1) {
|
|
4482
|
+
return null;
|
|
4483
|
+
}
|
|
4484
|
+
return key.slice(sep2 + 1);
|
|
4485
|
+
}
|
|
4486
|
+
registerCacheInvalidator(devISRLoaderCache);
|
|
4487
|
+
registerCacheInvalidator(devSSGLoaderCache);
|
|
4311
4488
|
|
|
4312
4489
|
// src/utils.ts
|
|
4313
4490
|
function isFurinPage(value) {
|