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

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/furin.js CHANGED
@@ -1273,41 +1273,109 @@ var init_context_logger = __esm(() => {
1273
1273
  syntheticRenderStorage = new AsyncLocalStorage2;
1274
1274
  });
1275
1275
 
1276
- // src/render/cache.ts
1277
- import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
1278
- function evictOldest(map, maxSize) {
1279
- if (map.size > maxSize) {
1280
- const oldest = map.keys().next().value;
1276
+ // src/render/route-cache.ts
1277
+ function defaultPathFromKey(key) {
1278
+ return key;
1279
+ }
1280
+ function matchesPath(urlPath, path, type) {
1281
+ if (type === "page") {
1282
+ return urlPath === path;
1283
+ }
1284
+ const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
1285
+ return urlPath === path || urlPath.startsWith(prefix);
1286
+ }
1287
+ function createRouteCache(options) {
1288
+ const store = new Map;
1289
+ const pathFromKey = options.pathFromKey ?? defaultPathFromKey;
1290
+ const evictOldest = () => {
1291
+ if (options.maxSize === undefined || store.size <= options.maxSize) {
1292
+ return;
1293
+ }
1294
+ const oldest = store.keys().next().value;
1281
1295
  if (oldest !== undefined) {
1282
- map.delete(oldest);
1296
+ deleteEntry(oldest);
1283
1297
  }
1284
- }
1298
+ };
1299
+ const deleteEntry = (key) => {
1300
+ const entry = store.get(key);
1301
+ if (entry === undefined) {
1302
+ return false;
1303
+ }
1304
+ store.delete(key);
1305
+ options.onDelete?.(key, entry);
1306
+ return true;
1307
+ };
1308
+ return {
1309
+ name: options.name,
1310
+ store,
1311
+ get size() {
1312
+ return store.size;
1313
+ },
1314
+ get(key) {
1315
+ const entry = store.get(key);
1316
+ if (entry !== undefined && options.maxSize !== undefined) {
1317
+ store.delete(key);
1318
+ store.set(key, entry);
1319
+ }
1320
+ return entry;
1321
+ },
1322
+ set(key, entry) {
1323
+ const previous = store.get(key);
1324
+ if (previous !== undefined) {
1325
+ store.delete(key);
1326
+ }
1327
+ store.set(key, entry);
1328
+ options.onSet?.(key, entry, previous);
1329
+ evictOldest();
1330
+ },
1331
+ delete(key) {
1332
+ return deleteEntry(key);
1333
+ },
1334
+ clear() {
1335
+ for (const key of [...store.keys()]) {
1336
+ deleteEntry(key);
1337
+ }
1338
+ store.clear();
1339
+ },
1340
+ has(key) {
1341
+ return store.has(key);
1342
+ },
1343
+ entries() {
1344
+ return store.entries();
1345
+ },
1346
+ keys() {
1347
+ return store.keys();
1348
+ },
1349
+ invalidatePath(path, type) {
1350
+ let deleted = false;
1351
+ const purgedPaths = [];
1352
+ for (const key of [...store.keys()]) {
1353
+ const urlPath = pathFromKey(key);
1354
+ if (urlPath === null || !matchesPath(urlPath, path, type)) {
1355
+ continue;
1356
+ }
1357
+ deleteEntry(key);
1358
+ deleted = true;
1359
+ purgedPaths.push(urlPath);
1360
+ }
1361
+ return { deleted, purgedPaths: [...new Set(purgedPaths)] };
1362
+ }
1363
+ };
1285
1364
  }
1365
+
1366
+ // src/render/cache.ts
1367
+ import { AsyncLocalStorage as AsyncLocalStorage3 } from "async_hooks";
1286
1368
  function getISRCache(key) {
1287
- const entry = isrCache.get(key);
1288
- if (entry !== undefined) {
1289
- isrCache.delete(key);
1290
- isrCache.set(key, entry);
1291
- }
1292
- return entry;
1369
+ return isrRouteCache.get(key);
1293
1370
  }
1294
1371
  function getSSGCache(key) {
1295
- const entry = ssgCache.get(key);
1296
- if (entry !== undefined) {
1297
- ssgCache.delete(key);
1298
- ssgCache.set(key, entry);
1299
- }
1300
- return entry;
1372
+ return ssgRouteCache.get(key);
1301
1373
  }
1302
1374
  function setISRCache(key, entry) {
1303
- isrCache.delete(key);
1304
- isrCache.set(key, entry);
1305
- evictOldest(isrCache, MAX_ISR_CACHE_SIZE);
1375
+ isrRouteCache.set(key, entry);
1306
1376
  }
1307
1377
  function setSSGCache(key, entry) {
1308
- ssgCache.delete(key);
1309
- ssgCache.set(key, entry);
1310
- evictOldest(ssgCache, MAX_SSG_CACHE_SIZE);
1378
+ ssgRouteCache.set(key, entry);
1311
1379
  }
1312
1380
  function setBuildId(id) {
1313
1381
  _buildId = id;
@@ -1349,54 +1417,60 @@ function callCachePurger(paths) {
1349
1417
  logger.emit();
1350
1418
  });
1351
1419
  }
1352
- function revalidatePath(path, type = "page") {
1353
- _activeInvalidationSet().add(type === "layout" ? `${path}:layout` : path);
1354
- let deleted = false;
1355
- if (type === "page") {
1356
- deleted = isrCache.delete(path) || deleted;
1357
- deleted = ssgCache.delete(path) || deleted;
1358
- callCachePurger([path]);
1359
- return deleted;
1420
+ function registerCacheInvalidator(invalidator) {
1421
+ const existing = _cacheInvalidators.get(invalidator.name);
1422
+ if (existing !== undefined && existing !== invalidator) {
1423
+ throw new Error(`Cache invalidator "${invalidator.name}" is already registered with a different instance.`);
1360
1424
  }
1361
- const prefix = path === "/" || path.endsWith("/") ? path : `${path}/`;
1362
- const purgedPaths = [];
1363
- for (const key of isrCache.keys()) {
1364
- if (key === path || key.startsWith(prefix)) {
1365
- isrCache.delete(key);
1366
- deleted = true;
1367
- purgedPaths.push(key);
1368
- }
1369
- }
1370
- for (const key of ssgCache.keys()) {
1371
- if (key === path || key.startsWith(prefix)) {
1372
- ssgCache.delete(key);
1373
- deleted = true;
1374
- if (!purgedPaths.includes(key)) {
1375
- purgedPaths.push(key);
1425
+ if (existing === invalidator) {
1426
+ return () => {
1427
+ if (_cacheInvalidators.get(invalidator.name) === invalidator) {
1428
+ _cacheInvalidators.delete(invalidator.name);
1376
1429
  }
1430
+ };
1431
+ }
1432
+ _cacheInvalidators.set(invalidator.name, invalidator);
1433
+ return () => {
1434
+ if (_cacheInvalidators.get(invalidator.name) === invalidator) {
1435
+ _cacheInvalidators.delete(invalidator.name);
1377
1436
  }
1437
+ };
1438
+ }
1439
+ function dedupePaths(paths) {
1440
+ return [...new Set(paths)];
1441
+ }
1442
+ function revalidatePath(path, type) {
1443
+ _activeInvalidationSet().add(type === "layout" ? `${path}:layout` : path);
1444
+ let deleted = false;
1445
+ const purgedPaths = [];
1446
+ for (const invalidator of _cacheInvalidators.values()) {
1447
+ const result = invalidator.invalidatePath(path, type);
1448
+ deleted = result.deleted || deleted;
1449
+ purgedPaths.push(...result.purgedPaths);
1378
1450
  }
1379
- callCachePurger(purgedPaths.length > 0 ? purgedPaths : [path]);
1451
+ callCachePurger(dedupePaths([...purgedPaths, path]));
1380
1452
  return deleted;
1381
1453
  }
1382
- var MAX_ISR_CACHE_SIZE = 1000, MAX_SSG_CACHE_SIZE = 1000, isrCache, ssgCache, _buildId = "", _requestInvalidationScope, _globalPendingInvalidations, _cachePurger = null;
1454
+ var MAX_ISR_CACHE_SIZE = 1000, MAX_SSG_CACHE_SIZE = 1000, isrRouteCache, ssgRouteCache, isrCache, ssgCache, _buildId = "", _requestInvalidationScope, _globalPendingInvalidations, _cachePurger = null, _cacheInvalidators;
1383
1455
  var init_cache = __esm(() => {
1384
1456
  init_context_logger();
1385
- isrCache = new Map;
1386
- ssgCache = new Map;
1457
+ isrRouteCache = createRouteCache({
1458
+ maxSize: MAX_ISR_CACHE_SIZE,
1459
+ name: "render:isr-html"
1460
+ });
1461
+ ssgRouteCache = createRouteCache({
1462
+ maxSize: MAX_SSG_CACHE_SIZE,
1463
+ name: "render:ssg-html"
1464
+ });
1465
+ isrCache = isrRouteCache.store;
1466
+ ssgCache = ssgRouteCache.store;
1387
1467
  _requestInvalidationScope = new AsyncLocalStorage3;
1388
1468
  _globalPendingInvalidations = new Set;
1469
+ _cacheInvalidators = new Map;
1470
+ registerCacheInvalidator(isrRouteCache);
1471
+ registerCacheInvalidator(ssgRouteCache);
1389
1472
  });
1390
1473
 
1391
- // src/error.ts
1392
- function getPublicErrorMessage(error) {
1393
- const branded = error;
1394
- if (branded?.__furinBrand === "FURIN_NOT_FOUND") {
1395
- return error.message;
1396
- }
1397
- return "Something went wrong";
1398
- }
1399
-
1400
1474
  // src/not-found.ts
1401
1475
  function notFound(options) {
1402
1476
  throw new FurinNotFoundError(options);
@@ -1416,6 +1490,209 @@ var init_not_found = __esm(() => {
1416
1490
  };
1417
1491
  });
1418
1492
 
1493
+ // src/error.ts
1494
+ function getPublicErrorMessage(error) {
1495
+ const branded = error;
1496
+ if (branded?.__furinBrand === "FURIN_NOT_FOUND") {
1497
+ return error.message;
1498
+ }
1499
+ return "Something went wrong";
1500
+ }
1501
+
1502
+ // src/link.tsx
1503
+ import { createElement, useCallback, useEffect, useRef } from "react";
1504
+ function computeLinkView({
1505
+ to,
1506
+ search,
1507
+ hash,
1508
+ children,
1509
+ activeProps,
1510
+ inactiveProps
1511
+ }, router) {
1512
+ const logicalHref = buildHref(to, search, hash);
1513
+ const logicalHrefWithoutHash = buildHref(to, search, undefined);
1514
+ const isAbsolute = logicalHref.startsWith("http://") || logicalHref.startsWith("https://") || logicalHref.startsWith("//");
1515
+ const href = isAbsolute ? logicalHref : router.basePath + logicalHref;
1516
+ const isActive = !isAbsolute && router.currentHref === normalizeHref(logicalHrefWithoutHash);
1517
+ const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
1518
+ const extraProps = {
1519
+ ...inactiveProps && !isActive ? inactiveProps() : {},
1520
+ ...activeProps ? activeProps({ isActive }) : {}
1521
+ };
1522
+ return { logicalHref, href, isActive, resolvedChildren, extraProps };
1523
+ }
1524
+ function LinkInteractive({
1525
+ to,
1526
+ search,
1527
+ hash,
1528
+ preload,
1529
+ preloadDelay,
1530
+ preloadStaleTime,
1531
+ replace,
1532
+ disabled,
1533
+ resetScroll,
1534
+ activeProps,
1535
+ inactiveProps,
1536
+ onClick,
1537
+ onMouseEnter,
1538
+ onMouseLeave,
1539
+ onFocus,
1540
+ children,
1541
+ href: _href,
1542
+ ...anchorProps
1543
+ }) {
1544
+ const router = useRouter();
1545
+ const anchorRef = useRef(null);
1546
+ const intentTimerRef = useRef(null);
1547
+ const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
1548
+ const effectivePreload = preload ?? router.defaultPreload;
1549
+ const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
1550
+ const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
1551
+ const triggerPrefetch = useCallback(() => {
1552
+ router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
1553
+ }, [router, logicalHref, effectiveStaleTime]);
1554
+ useEffect(() => {
1555
+ if (effectivePreload === "render") {
1556
+ triggerPrefetch();
1557
+ }
1558
+ }, [effectivePreload, triggerPrefetch]);
1559
+ useEffect(() => {
1560
+ if (effectivePreload !== "viewport" || !anchorRef.current) {
1561
+ return;
1562
+ }
1563
+ const observer = new IntersectionObserver(([entry]) => {
1564
+ if (entry?.isIntersecting) {
1565
+ triggerPrefetch();
1566
+ observer.disconnect();
1567
+ }
1568
+ }, { rootMargin: "200px" });
1569
+ observer.observe(anchorRef.current);
1570
+ return () => observer.disconnect();
1571
+ }, [effectivePreload, triggerPrefetch]);
1572
+ useEffect(() => () => {
1573
+ if (intentTimerRef.current !== null) {
1574
+ clearTimeout(intentTimerRef.current);
1575
+ intentTimerRef.current = null;
1576
+ }
1577
+ }, []);
1578
+ const isInternal = (url) => {
1579
+ try {
1580
+ return new URL(url, window.location.origin).origin === window.location.origin;
1581
+ } catch {
1582
+ return false;
1583
+ }
1584
+ };
1585
+ const handleClick = (e) => {
1586
+ onClick?.(e);
1587
+ if (e.defaultPrevented) {
1588
+ return;
1589
+ }
1590
+ if (disabled) {
1591
+ e.preventDefault();
1592
+ return;
1593
+ }
1594
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
1595
+ return;
1596
+ }
1597
+ if (anchorProps.target && anchorProps.target !== "_self") {
1598
+ return;
1599
+ }
1600
+ if (!isInternal(href)) {
1601
+ return;
1602
+ }
1603
+ e.preventDefault();
1604
+ router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
1605
+ };
1606
+ const handleMouseEnter = (e) => {
1607
+ onMouseEnter?.(e);
1608
+ if (!disabled && effectivePreload === "intent" && isInternal(href)) {
1609
+ intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
1610
+ }
1611
+ };
1612
+ const handleMouseLeave = (e) => {
1613
+ onMouseLeave?.(e);
1614
+ if (intentTimerRef.current !== null) {
1615
+ clearTimeout(intentTimerRef.current);
1616
+ intentTimerRef.current = null;
1617
+ }
1618
+ };
1619
+ const handleFocus = (e) => {
1620
+ onFocus?.(e);
1621
+ if (!disabled && effectivePreload === "intent" && isInternal(href)) {
1622
+ triggerPrefetch();
1623
+ }
1624
+ };
1625
+ return createElement("a", {
1626
+ ref: anchorRef,
1627
+ href,
1628
+ "data-furin-link": true,
1629
+ onClick: handleClick,
1630
+ onMouseEnter: handleMouseEnter,
1631
+ onMouseLeave: handleMouseLeave,
1632
+ onFocus: handleFocus,
1633
+ ...isActive ? { "data-status": "active" } : {},
1634
+ ...anchorProps,
1635
+ ...extraProps,
1636
+ ...disabled ? { "aria-disabled": true } : {}
1637
+ }, resolvedChildren);
1638
+ }
1639
+ function renderLinkElement(props, router) {
1640
+ const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
1641
+ const {
1642
+ to: _to,
1643
+ search: _search,
1644
+ hash: _hash,
1645
+ children: _children,
1646
+ activeProps: _ap,
1647
+ inactiveProps: _ip,
1648
+ disabled,
1649
+ preload: _p,
1650
+ preloadDelay: _pd,
1651
+ preloadStaleTime: _ps,
1652
+ replace: _r,
1653
+ resetScroll: _rs,
1654
+ onClick: _oc,
1655
+ onMouseEnter: _ome,
1656
+ onMouseLeave: _oml,
1657
+ onFocus: _of,
1658
+ href: _href,
1659
+ ...anchorProps
1660
+ } = props;
1661
+ return createElement("a", {
1662
+ href,
1663
+ "data-furin-link": true,
1664
+ ...isActive ? { "data-status": "active" } : {},
1665
+ ...anchorProps,
1666
+ ...extraProps,
1667
+ ...disabled ? { "aria-disabled": true } : {}
1668
+ }, resolvedChildren);
1669
+ }
1670
+ function Link(props) {
1671
+ if (typeof window === "undefined") {
1672
+ return createElement(RouterContext.Consumer, {
1673
+ children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
1674
+ });
1675
+ }
1676
+ return createElement(LinkInteractive, props);
1677
+ }
1678
+ var SSR_FALLBACK_ROUTER;
1679
+ var init_link = __esm(() => {
1680
+ init_router_provider();
1681
+ init_router_provider();
1682
+ SSR_FALLBACK_ROUTER = {
1683
+ basePath: "",
1684
+ currentHref: "/",
1685
+ navigate: () => Promise.resolve(),
1686
+ prefetch: () => {},
1687
+ invalidatePrefetch: () => {},
1688
+ refresh: () => Promise.resolve(),
1689
+ isNavigating: false,
1690
+ defaultPreload: "intent",
1691
+ defaultPreloadDelay: 50,
1692
+ defaultPreloadStaleTime: 30000
1693
+ };
1694
+ });
1695
+
1419
1696
  // src/render/default-screens.tsx
1420
1697
  import { jsxDEV } from "react/jsx-dev-runtime";
1421
1698
  function CornerBracket({ corner }) {
@@ -1797,15 +2074,16 @@ var init_boundaries = __esm(() => {
1797
2074
  };
1798
2075
  });
1799
2076
 
1800
- // src/link.tsx
2077
+ // src/router-provider.tsx
1801
2078
  import {
1802
2079
  createContext,
1803
- createElement,
1804
- useCallback,
2080
+ createElement as createElement2,
2081
+ useCallback as useCallback2,
1805
2082
  useContext,
1806
- useEffect,
2083
+ useEffect as useEffect2,
2084
+ useLayoutEffect,
1807
2085
  useMemo,
1808
- useRef,
2086
+ useRef as useRef2,
1809
2087
  useState
1810
2088
  } from "react";
1811
2089
  import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
@@ -1829,7 +2107,8 @@ function buildHref(to, search, hash) {
1829
2107
  return url;
1830
2108
  }
1831
2109
  function useRouter() {
1832
- return useContext(RouterContext) ?? {
2110
+ const ctx = useContext(RouterContext);
2111
+ return ctx ?? {
1833
2112
  basePath: "",
1834
2113
  currentHref: "/",
1835
2114
  navigate: (href) => {
@@ -1848,182 +2127,17 @@ function useRouter() {
1848
2127
  defaultPreloadStaleTime: 30000
1849
2128
  };
1850
2129
  }
1851
- function computeLinkView({
1852
- to,
1853
- search,
1854
- hash,
1855
- children,
1856
- activeProps,
1857
- inactiveProps
1858
- }, router) {
1859
- const logicalHref = buildHref(to, search, hash);
1860
- const logicalHrefWithoutHash = buildHref(to, search, undefined);
1861
- const href = router.basePath + logicalHref;
1862
- const isActive = router.currentHref === logicalHrefWithoutHash;
1863
- const resolvedChildren = typeof children === "function" ? children({ isActive }) : children;
1864
- const extraProps = {
1865
- ...inactiveProps && !isActive ? inactiveProps() : {},
1866
- ...activeProps ? activeProps({ isActive }) : {}
1867
- };
1868
- return { logicalHref, href, isActive, resolvedChildren, extraProps };
1869
- }
1870
- function LinkInteractive({
1871
- to,
1872
- search,
1873
- hash,
1874
- preload,
1875
- preloadDelay,
1876
- preloadStaleTime,
1877
- replace,
1878
- disabled,
1879
- resetScroll,
1880
- activeProps,
1881
- inactiveProps,
1882
- onClick,
1883
- onMouseEnter,
1884
- onMouseLeave,
1885
- onFocus,
1886
- children,
1887
- ...anchorProps
1888
- }) {
1889
- const router = useRouter();
1890
- const anchorRef = useRef(null);
1891
- const intentTimerRef = useRef(null);
1892
- const { logicalHref, href, isActive, resolvedChildren, extraProps } = computeLinkView({ to, search, hash, children, activeProps, inactiveProps }, router);
1893
- const effectivePreload = preload ?? router.defaultPreload;
1894
- const effectiveDelay = preloadDelay ?? router.defaultPreloadDelay;
1895
- const effectiveStaleTime = preloadStaleTime ?? router.defaultPreloadStaleTime;
1896
- const triggerPrefetch = useCallback(() => {
1897
- router.prefetch(logicalHref, { staleTime: effectiveStaleTime });
1898
- }, [router, logicalHref, effectiveStaleTime]);
1899
- useEffect(() => {
1900
- if (effectivePreload === "render") {
1901
- triggerPrefetch();
1902
- }
1903
- }, [effectivePreload, triggerPrefetch]);
1904
- useEffect(() => {
1905
- if (effectivePreload !== "viewport" || !anchorRef.current) {
1906
- return;
1907
- }
1908
- const observer = new IntersectionObserver(([entry]) => {
1909
- if (entry?.isIntersecting) {
1910
- triggerPrefetch();
1911
- observer.disconnect();
1912
- }
1913
- }, { rootMargin: "200px" });
1914
- observer.observe(anchorRef.current);
1915
- return () => observer.disconnect();
1916
- }, [effectivePreload, triggerPrefetch]);
1917
- const isInternal = (url) => {
1918
- try {
1919
- return new URL(url, window.location.origin).origin === window.location.origin;
1920
- } catch {
1921
- return false;
1922
- }
1923
- };
1924
- const handleClick = (e) => {
1925
- onClick?.(e);
1926
- if (e.defaultPrevented || disabled) {
1927
- return;
1928
- }
1929
- if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
1930
- return;
1931
- }
1932
- if (anchorProps.target && anchorProps.target !== "_self") {
1933
- return;
1934
- }
1935
- if (!isInternal(href)) {
1936
- return;
1937
- }
1938
- e.preventDefault();
1939
- router.navigate(logicalHref, { replace, resetScroll: resetScroll ?? true });
1940
- };
1941
- const handleMouseEnter = (e) => {
1942
- onMouseEnter?.(e);
1943
- if (!disabled && effectivePreload === "intent" && isInternal(href)) {
1944
- intentTimerRef.current = setTimeout(triggerPrefetch, effectiveDelay);
1945
- }
1946
- };
1947
- const handleMouseLeave = (e) => {
1948
- onMouseLeave?.(e);
1949
- if (intentTimerRef.current !== null) {
1950
- clearTimeout(intentTimerRef.current);
1951
- intentTimerRef.current = null;
1952
- }
1953
- };
1954
- const handleFocus = (e) => {
1955
- onFocus?.(e);
1956
- if (!disabled && effectivePreload === "intent" && isInternal(href)) {
1957
- triggerPrefetch();
1958
- }
1959
- };
1960
- return createElement("a", {
1961
- ref: anchorRef,
1962
- href,
1963
- onClick: handleClick,
1964
- onMouseEnter: handleMouseEnter,
1965
- onMouseLeave: handleMouseLeave,
1966
- onFocus: handleFocus,
1967
- ...isActive ? { "data-status": "active" } : {},
1968
- ...anchorProps,
1969
- ...extraProps,
1970
- ...disabled ? { "aria-disabled": true } : {}
1971
- }, resolvedChildren);
1972
- }
1973
- function renderLinkElement(props, router) {
1974
- const { href, isActive, resolvedChildren, extraProps } = computeLinkView(props, router);
1975
- const {
1976
- to: _to,
1977
- search: _search,
1978
- hash: _hash,
1979
- children: _children,
1980
- activeProps: _ap,
1981
- inactiveProps: _ip,
1982
- disabled,
1983
- preload: _p,
1984
- preloadDelay: _pd,
1985
- preloadStaleTime: _ps,
1986
- replace: _r,
1987
- resetScroll: _rs,
1988
- onClick: _oc,
1989
- onMouseEnter: _ome,
1990
- onMouseLeave: _oml,
1991
- onFocus: _of,
1992
- ...anchorProps
1993
- } = props;
1994
- return createElement("a", {
1995
- href,
1996
- ...isActive ? { "data-status": "active" } : {},
1997
- ...anchorProps,
1998
- ...extraProps,
1999
- ...disabled ? { "aria-disabled": true } : {}
2000
- }, resolvedChildren);
2001
- }
2002
- function Link(props) {
2003
- if (typeof window === "undefined") {
2004
- return createElement(RouterContext.Consumer, {
2005
- children: (routerCtx) => renderLinkElement(props, routerCtx ?? SSR_FALLBACK_ROUTER)
2006
- });
2130
+ function normalizeHref(href) {
2131
+ const url = new URL(href, "http://localhost");
2132
+ let pathname = url.pathname;
2133
+ if (pathname !== "/") {
2134
+ pathname = pathname.replace(/\/+$/g, "");
2007
2135
  }
2008
- return createElement(LinkInteractive, props);
2136
+ return pathname + url.search + url.hash;
2009
2137
  }
2010
- var RouterContext, SSR_FALLBACK_ROUTER;
2011
- var init_link = __esm(() => {
2012
- init_boundaries();
2013
- init_default_screens();
2138
+ var RouterContext;
2139
+ var init_router_provider = __esm(() => {
2014
2140
  RouterContext = createContext(null);
2015
- SSR_FALLBACK_ROUTER = {
2016
- basePath: "",
2017
- currentHref: "/",
2018
- navigate: () => Promise.resolve(),
2019
- prefetch: () => {},
2020
- invalidatePrefetch: () => {},
2021
- refresh: () => Promise.resolve(),
2022
- isNavigating: false,
2023
- defaultPreload: "intent",
2024
- defaultPreloadDelay: 50,
2025
- defaultPreloadStaleTime: 30000
2026
- };
2027
2141
  });
2028
2142
 
2029
2143
  // src/render/shell.ts
@@ -2361,10 +2475,10 @@ var init_template = () => {};
2361
2475
  var IS_DEV = true;
2362
2476
 
2363
2477
  // src/render/index.ts
2364
- import { createElement as createElement2 } from "react";
2478
+ import { createElement as createElement3 } from "react";
2365
2479
  import { renderToReadableStream } from "react-dom/server";
2366
2480
  function withSSRRouterContext(element, contextValue) {
2367
- return createElement2(RouterContext.Provider, { value: contextValue }, element);
2481
+ return createElement3(RouterContext.Provider, { value: contextValue }, element);
2368
2482
  }
2369
2483
  async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomputedLoaderResult) {
2370
2484
  const loaderStart = Date.now();
@@ -2407,7 +2521,7 @@ async function prepareRender(route, ctx, root, basePath, throwOnFailure, precomp
2407
2521
  }
2408
2522
  const ssrContext = {
2409
2523
  basePath: basePath ?? "",
2410
- currentHref: ctx.path,
2524
+ currentHref: normalizeHref(ctx.path),
2411
2525
  navigate: () => Promise.resolve(),
2412
2526
  prefetch: () => {},
2413
2527
  invalidatePrefetch: () => {},
@@ -2577,7 +2691,7 @@ async function renderRootNotFound(root, request) {
2577
2691
  const notFoundError = new FurinNotFoundError(undefined);
2578
2692
  const notFoundContext = {
2579
2693
  basePath: "",
2580
- currentHref: request ? new URL(request.url).pathname : "/",
2694
+ currentHref: request ? normalizeHref(new URL(request.url).pathname) : "/",
2581
2695
  navigate: () => Promise.resolve(),
2582
2696
  prefetch: () => {},
2583
2697
  invalidatePrefetch: () => {},
@@ -2834,16 +2948,14 @@ function revalidateInBackground(route, params, cacheKey, revalidate, root, origi
2834
2948
  }
2835
2949
  var SSG_WARM_CONCURRENCY = 4, pendingRevalidations;
2836
2950
  var init_render = __esm(() => {
2837
- init_link();
2838
2951
  init_not_found();
2952
+ init_router_provider();
2839
2953
  init_assemble();
2840
2954
  init_cache();
2841
2955
  init_element();
2842
2956
  init_loaders();
2843
2957
  init_shell();
2844
2958
  init_template();
2845
- init_assemble();
2846
- init_element();
2847
2959
  init_loaders();
2848
2960
  init_context_logger();
2849
2961
  init_shell();
@@ -2874,13 +2986,23 @@ function unindexEntryDependencies(cacheKey, deps) {
2874
2986
  }
2875
2987
  }
2876
2988
  }
2989
+ function createDevLoaderCache(name) {
2990
+ return createRouteCache({
2991
+ name,
2992
+ onDelete: (key, entry) => {
2993
+ unindexEntryDependencies(key, entry.dependencies);
2994
+ },
2995
+ onSet: (key, entry, previous) => {
2996
+ if (previous) {
2997
+ unindexEntryDependencies(key, previous.dependencies);
2998
+ }
2999
+ indexEntryDependencies(key, entry.dependencies);
3000
+ },
3001
+ pathFromKey: urlPathFromCacheKey
3002
+ });
3003
+ }
2877
3004
  function setEntry(handle, key, entry) {
2878
- const previous = handle.cache.get(key);
2879
- if (previous) {
2880
- unindexEntryDependencies(key, previous.dependencies);
2881
- }
2882
3005
  handle.cache.set(key, entry);
2883
- indexEntryDependencies(key, entry.dependencies);
2884
3006
  }
2885
3007
  function getDevISRLoaderCache(key) {
2886
3008
  return devISRLoaderCache.get(key);
@@ -2894,6 +3016,13 @@ function getDevSSGLoaderCache(key) {
2894
3016
  function setDevSSGLoaderCache(key, entry) {
2895
3017
  setEntry(ssgHandle, key, entry);
2896
3018
  }
3019
+ function urlPathFromCacheKey(key) {
3020
+ const sep = key.lastIndexOf(":/");
3021
+ if (sep === -1) {
3022
+ return null;
3023
+ }
3024
+ return key.slice(sep + 1);
3025
+ }
2897
3026
  function invalidateDevLoaderCacheBySource(filePath) {
2898
3027
  const keys = sourceFileToCacheKeys.get(filePath);
2899
3028
  if (!keys || keys.size === 0) {
@@ -2907,7 +3036,6 @@ function invalidateDevLoaderCacheBySource(filePath) {
2907
3036
  const isrEntry = devISRLoaderCache.get(key);
2908
3037
  if (isrEntry) {
2909
3038
  devISRLoaderCache.delete(key);
2910
- unindexEntryDependencies(key, isrEntry.dependencies);
2911
3039
  cleared.push(key);
2912
3040
  isr++;
2913
3041
  continue;
@@ -2915,7 +3043,6 @@ function invalidateDevLoaderCacheBySource(filePath) {
2915
3043
  const ssgEntry = devSSGLoaderCache.get(key);
2916
3044
  if (ssgEntry) {
2917
3045
  devSSGLoaderCache.delete(key);
2918
- unindexEntryDependencies(key, ssgEntry.dependencies);
2919
3046
  cleared.push(key);
2920
3047
  ssg++;
2921
3048
  }
@@ -2948,13 +3075,16 @@ function getAllDevISRLoaderEntries() {
2948
3075
  function getAllDevSSGLoaderEntries() {
2949
3076
  return [...devSSGLoaderCache.entries()];
2950
3077
  }
2951
- var devISRLoaderCache, devSSGLoaderCache, sourceFileToCacheKeys, isrHandle, ssgHandle;
3078
+ var sourceFileToCacheKeys, devISRLoaderCache, devSSGLoaderCache, isrHandle, ssgHandle;
2952
3079
  var init_dev_cache = __esm(() => {
2953
- devISRLoaderCache = new Map;
2954
- devSSGLoaderCache = new Map;
3080
+ init_cache();
2955
3081
  sourceFileToCacheKeys = new Map;
3082
+ devISRLoaderCache = createDevLoaderCache("render:dev-isr-loader");
3083
+ devSSGLoaderCache = createDevLoaderCache("render:dev-ssg-loader");
2956
3084
  isrHandle = { cache: devISRLoaderCache, kind: "isr" };
2957
3085
  ssgHandle = { cache: devSSGLoaderCache, kind: "ssg" };
3086
+ registerCacheInvalidator(devISRLoaderCache);
3087
+ registerCacheInvalidator(devSSGLoaderCache);
2958
3088
  });
2959
3089
 
2960
3090
  // src/utils.ts
@@ -3696,6 +3826,10 @@ function transformDevSource(raw, filePath, options) {
3696
3826
  return injectJsxHelperImports(result);
3697
3827
  }
3698
3828
  function registerDevPagePlugin() {
3829
+ if (_pluginRegistered) {
3830
+ return;
3831
+ }
3832
+ _pluginRegistered = true;
3699
3833
  Bun.plugin({
3700
3834
  name: "furin-dev-page-loader",
3701
3835
  setup(build) {
@@ -3742,7 +3876,7 @@ function registerDevPagePlugin() {
3742
3876
  }
3743
3877
  });
3744
3878
  }
3745
- var FURIN_SERVER_FILTER, ANY_FILTER, WORKSPACE_SOURCE_FILTER, T_PARAM_RE, STRIP_FURIN_SERVER_RE, STRIP_T_PARAM_RE, SINGLETON_PKGS, SINGLETON_PATHS, RELATIVE_SPECIFIER_RE;
3879
+ var FURIN_SERVER_FILTER, ANY_FILTER, WORKSPACE_SOURCE_FILTER, T_PARAM_RE, STRIP_FURIN_SERVER_RE, STRIP_T_PARAM_RE, _pluginRegistered = false, SINGLETON_PKGS, SINGLETON_PATHS, RELATIVE_SPECIFIER_RE;
3746
3880
  var init_dev_page_plugin = __esm(() => {
3747
3881
  init_dev_cache();
3748
3882
  FURIN_SERVER_FILTER = /\?furin-server(?:&t=\d+)?$/;
@@ -3906,10 +4040,15 @@ function generateHydrateEntry(routes, rootLayout, basePath) {
3906
4040
  const conventionImportLines = [...conventionIdents.entries()].map(([filePath, ident]) => `import ${ident} from "${filePath.replace(/\\/g, "/")}";`).join(`
3907
4041
  `);
3908
4042
  const basePathLiteral = JSON.stringify(basePath);
3909
- 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";
4043
+ 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(/\\/+$/, "") || "/"`;
3910
4044
  const logEndpoint = basePath ? `${JSON.stringify(basePath)} + "/_furin/ingest"` : `"/_furin/ingest"`;
3911
- const basePathProp = basePath ? `
3912
- basePath: ${basePathLiteral},` : "";
4045
+ const routerProviderDefaults = `
4046
+ autoRefresh: true,
4047
+ basePath: ${basePathLiteral},
4048
+ defaultPreload: "intent",
4049
+ defaultPreloadDelay: 50,
4050
+ defaultPreloadStaleTime: 30000,
4051
+ prefetchCacheSize: 50,`;
3913
4052
  const conventionImportsBlock = conventionImportLines ? `
3914
4053
  ${conventionImportLines}` : "";
3915
4054
  return `import { hydrateRoot, createRoot } from "react-dom/client";
@@ -3958,7 +4097,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
3958
4097
  initialMatch: match,
3959
4098
  initialData: loaderData,
3960
4099
  initialDigest: loaderData.__furinError?.digest,
3961
- initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${basePathProp}
4100
+ initialNotFound: isNotFound ? (loaderData.__furinNotFound ?? loaderData) : undefined,${routerProviderDefaults}
3962
4101
  } as any);
3963
4102
  } else if (loaderData.__furinStatus === 404) {
3964
4103
  // Direct load to an unknown URL. The server sent the root not-found UI
@@ -3975,7 +4114,7 @@ const rootEl = document.getElementById("root") as HTMLElement;
3975
4114
  initialMatch: null,
3976
4115
  initialData: cleanData,
3977
4116
  initialDigest: loaderData.__furinError?.digest,
3978
- initialNotFound: loaderData.__furinNotFound ?? {},${basePathProp}
4117
+ initialNotFound: loaderData.__furinNotFound ?? {},${routerProviderDefaults}
3979
4118
  } as any);
3980
4119
  } else {
3981
4120
  // No match and no 404 signal \u2014 either the client bundle is out of sync