cloudflare-next-intl 0.9.32 → 0.9.34
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.
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { extractImportSpecifiers, resolveLocalImport } from './resolve_local_imports.js';
|
|
2
2
|
export const MAX_FILES_VISITED = 300;
|
|
3
|
-
const USE_SERVER_DIRECTIVE = /^(?:\s*['"]use \w[\w-]*['"]\s*;?\s*)*['"]use server['"]\s*;?/;
|
|
4
|
-
function hasLeadingUseServerDirective(source) {
|
|
5
|
-
return USE_SERVER_DIRECTIVE.test(source);
|
|
6
|
-
}
|
|
7
3
|
export function collectReachableFiles(entryFile, entrySource, aliases, io) {
|
|
8
4
|
const isFile = io.isFile ?? (() => false);
|
|
9
5
|
const files = new Map([[entryFile, entrySource]]);
|
|
@@ -26,8 +22,6 @@ export function collectReachableFiles(entryFile, entrySource, aliases, io) {
|
|
|
26
22
|
catch {
|
|
27
23
|
continue;
|
|
28
24
|
}
|
|
29
|
-
if (hasLeadingUseServerDirective(importedSource))
|
|
30
|
-
continue;
|
|
31
25
|
files.set(resolved, importedSource);
|
|
32
26
|
queue.push(resolved);
|
|
33
27
|
}
|
|
@@ -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
|
-
|
|
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 ??
|
|
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
|
-
|
|
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);
|