cloudflare-next-intl 0.9.32 → 0.9.33

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.
@@ -3,7 +3,7 @@ import { type ComponentProps } from 'react';
3
3
  export type PrefetchType = 'custom' | 'eager' | 'default';
4
4
  type NextLinkProps = Omit<ComponentProps<'a'>, keyof LinkProps> & Omit<LinkProps, 'locale'> & {
5
5
  prefetchType?: PrefetchType;
6
+ hoverPrefetchDelayMs?: number;
6
7
  };
7
- export declare const PENDING_NAVIGATION_EVENT = "cloudflare-next-intl:pending-navigation";
8
8
  declare const Link: import("react").ForwardRefExoticComponent<Omit<NextLinkProps, "ref"> & import("react").RefAttributes<HTMLAnchorElement>>;
9
9
  export default Link;
@@ -6,11 +6,10 @@ import config from '../../config/intl_config.js';
6
6
  import { getLocaleCache } from '../../general/cache_variables.js';
7
7
  import { usePathname, useRouter } from 'next/navigation.js';
8
8
  const prefetchedRoutes = new Set();
9
- export const PENDING_NAVIGATION_EVENT = 'cloudflare-next-intl:pending-navigation';
10
- function CustomLinkFunction({ href, prefetch, prefetchType = 'custom', onClick, onMouseEnter, onMouseLeave, onPointerDown, ...rest }, ref) {
9
+ function CustomLinkFunction({ href, prefetch, prefetchType = 'custom', hoverPrefetchDelayMs = 100, onClick, onMouseEnter, onMouseLeave, onPointerDown, ...rest }, ref) {
11
10
  const localeValue = getLocaleCache();
12
11
  const router = useRouter();
13
- prefetch ?? (prefetch = config.link?.defaultPrefetch ?? false);
12
+ prefetch ?? (prefetch = config.link?.defaultPrefetch ?? true);
14
13
  const needsLangPath = localeValue !== config.defaultLocale || !localeValue;
15
14
  let pathnames;
16
15
  let urlString;
@@ -28,7 +27,6 @@ function CustomLinkFunction({ href, prefetch, prefetchType = 'custom', onClick,
28
27
  const [isNavigating, setIsNavigating] = useState(false);
29
28
  useEffect(() => {
30
29
  setIsNavigating(false);
31
- window.dispatchEvent(new CustomEvent(PENDING_NAVIGATION_EVENT, { detail: null }));
32
30
  }, [pathname]);
33
31
  useEffect(() => {
34
32
  if (!isNavigating)
@@ -72,7 +70,11 @@ function CustomLinkFunction({ href, prefetch, prefetchType = 'custom', onClick,
72
70
  if (!prefetchEnabled)
73
71
  return;
74
72
  clearHoverTimer();
75
- hoverTimerRef.current = setTimeout(doPrefetch, 100);
73
+ if (hoverPrefetchDelayMs <= 0) {
74
+ doPrefetch();
75
+ return;
76
+ }
77
+ hoverTimerRef.current = setTimeout(doPrefetch, hoverPrefetchDelayMs);
76
78
  };
77
79
  const handleHoverEnd = () => {
78
80
  clearHoverTimer();
@@ -90,12 +92,6 @@ function CustomLinkFunction({ href, prefetch, prefetchType = 'custom', onClick,
90
92
  const targetPath = typeof pathnames === 'string' ? pathnames : urlString;
91
93
  if (pathname !== targetPath) {
92
94
  setIsNavigating(true);
93
- try {
94
- window.history.replaceState(window.history.state, '', targetPath);
95
- window.dispatchEvent(new CustomEvent(PENDING_NAVIGATION_EVENT, { detail: targetPath }));
96
- }
97
- catch {
98
- }
99
95
  }
100
96
  startTransition(() => {
101
97
  router.push(targetPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudflare-next-intl",
3
- "version": "0.9.32",
3
+ "version": "0.9.33",
4
4
  "description": "Optimized Next Intl Package Special for App Router and Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",