fimo-react-router 2.7.1 → 2.8.0-staging.10
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/AppRoutesProvider.js +1 -2
- package/dist/FimoProviders.js +1 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +9 -9
- package/dist/OptionalTracking.d.ts +0 -13
- package/dist/OptionalTracking.js +0 -28
- package/dist/Pageview.d.ts +0 -9
- package/dist/Pageview.js +0 -118
|
@@ -6,7 +6,6 @@ import { useCallback, useEffect, useMemo } from 'react';
|
|
|
6
6
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
7
7
|
import { useLocation, useNavigate, useRoutes } from 'react-router';
|
|
8
8
|
import { AppResetScrollOnNavigate } from './AppResetScrollOnNavigate.js';
|
|
9
|
-
import { OptionalTracking } from './OptionalTracking.js';
|
|
10
9
|
const titleCase = (seg) => seg
|
|
11
10
|
.replace(/[_-]+/g, ' ')
|
|
12
11
|
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
@@ -104,5 +103,5 @@ export function AppRoutesProvider({ appRoutes, children }) {
|
|
|
104
103
|
window.removeEventListener('message', handleMessage);
|
|
105
104
|
};
|
|
106
105
|
}, [navigate, previewEnabled, sendRoutes, sendLocationChange]);
|
|
107
|
-
return (_jsx(ErrorBoundary, { FallbackComponent: AppErrorBoundary, onError: onError, children: _jsx(DataSourcesProvider, { children: _jsx(ScreenshotProvider, { children: _jsx(ViteLifecycles, { children: _jsxs(RefreshContentProvider, { children: [_jsx(
|
|
106
|
+
return (_jsx(ErrorBoundary, { FallbackComponent: AppErrorBoundary, onError: onError, children: _jsx(DataSourcesProvider, { children: _jsx(ScreenshotProvider, { children: _jsx(ViteLifecycles, { children: _jsxs(RefreshContentProvider, { children: [_jsx(AppResetScrollOnNavigate, {}), appRoutes?.length ? routing : children] }) }) }) }) }));
|
|
108
107
|
}
|
package/dist/FimoProviders.js
CHANGED
|
@@ -11,7 +11,6 @@ import { UNSAFE_FrameworkContext, useLocation, useNavigate } from 'react-router'
|
|
|
11
11
|
// @ts-ignore - virtual module provided by fimoConfigPlugin in fimo-vite
|
|
12
12
|
import fimoConfig from 'virtual:fimo-config';
|
|
13
13
|
import { getActiveRouterRoutes } from './active-routes.js';
|
|
14
|
-
import { OptionalTracking } from './OptionalTracking.js';
|
|
15
14
|
export { getPreviewLocationChange, getPreviewLocationPath } from 'fimo/preview';
|
|
16
15
|
const titleCase = (seg) => seg
|
|
17
16
|
.replace(/[_-]+/g, ' ')
|
|
@@ -159,7 +158,6 @@ export function FimoProviders({ children, locale }) {
|
|
|
159
158
|
// of caching. A different framework runtime would swap this reader only.
|
|
160
159
|
const frameworkContext = useContext(UNSAFE_FrameworkContext);
|
|
161
160
|
const readRoutes = useCallback(() => getDisplayRoutes(frameworkContext?.manifest), [frameworkContext?.manifest]);
|
|
162
|
-
const routes = readRoutes();
|
|
163
161
|
const localeResolution = useMemo(() => resolveFimoLocale({ pathname: location.pathname }, fimoConfig), [location.pathname]);
|
|
164
162
|
// The app is authoritative: an explicit `locale` wins over anything Fimo can
|
|
165
163
|
// infer, and inference itself goes through the declared route contract.
|
|
@@ -184,5 +182,5 @@ export function FimoProviders({ children, locale }) {
|
|
|
184
182
|
...localeResolution,
|
|
185
183
|
locale: activeLocale,
|
|
186
184
|
dir: activeDir,
|
|
187
|
-
}, children: _jsx(DataSourcesProvider, { children: _jsx(ScreenshotProvider, { children: _jsx(ViteLifecycles, { children: _jsxs(RefreshContentProvider, { children: [previewEnabled ? _jsx(PreviewBridge, { readRoutes: readRoutes, locale: activeLocale }) : null, _jsx(
|
|
185
|
+
}, children: _jsx(DataSourcesProvider, { children: _jsx(ScreenshotProvider, { children: _jsx(ViteLifecycles, { children: _jsxs(RefreshContentProvider, { children: [previewEnabled ? _jsx(PreviewBridge, { readRoutes: readRoutes, locale: activeLocale }) : null, _jsx(Suspense, { children: children })] }) }) }) }) }) }) }));
|
|
188
186
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export type { DisplayRoute, FimoProvidersProps, ParamInfo } from './FimoProvider
|
|
|
10
10
|
export type { FimoLocaleContextValue } from 'fimo-react';
|
|
11
11
|
export type { FimoLocaleResolution } from 'fimo/i18n';
|
|
12
12
|
export type { FimoLinkProps, FimoNavigationOptions } from './navigation.js';
|
|
13
|
-
export { Pageview } from './Pageview.js';
|
|
14
13
|
export * from './seo.js';
|
|
15
14
|
export * from 'fimo/seo';
|
|
16
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,5 @@ export { localizeFimoPath, resolveFimoLocale } from 'fimo/i18n';
|
|
|
11
11
|
export { FimoLink, useFimoHref, useFimoNavigate } from './navigation.js';
|
|
12
12
|
export { localizeFimoTo } from './navigation-utils.js';
|
|
13
13
|
export { AppRoutesProvider } from './AppRoutesProvider.js';
|
|
14
|
-
export { Pageview } from './Pageview.js';
|
|
15
14
|
export * from './seo.js';
|
|
16
15
|
export * from 'fimo/seo';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fimo-react-router",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0-staging.10",
|
|
4
4
|
"description": "Fimo runtime, routing and build integration for React Router projects. Pairs with the fimo package at the same version.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
@@ -42,24 +42,24 @@
|
|
|
42
42
|
"react-error-boundary": "^6.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@fimo/tsconfig": "2.
|
|
45
|
+
"@fimo/tsconfig": "2.8.0-staging.10",
|
|
46
46
|
"@tanstack/react-query": "^5.80.6",
|
|
47
47
|
"@types/node": "22.18.6",
|
|
48
48
|
"@types/react": "19.2.14",
|
|
49
49
|
"@types/react-dom": "19.2.3",
|
|
50
|
-
"fimo": "2.
|
|
51
|
-
"fimo-react": "2.
|
|
52
|
-
"fimo-vite": "2.
|
|
50
|
+
"fimo": "2.8.0-staging.10",
|
|
51
|
+
"fimo-react": "2.8.0-staging.10",
|
|
52
|
+
"fimo-vite": "2.8.0-staging.10",
|
|
53
53
|
"react": "19.2.4",
|
|
54
54
|
"react-dom": "19.2.4",
|
|
55
|
-
"react-router": "7.18.
|
|
55
|
+
"react-router": "7.18.4",
|
|
56
56
|
"typescript": "7.0.2",
|
|
57
|
-
"vite": "8.
|
|
58
|
-
"vitest": "5.0.
|
|
57
|
+
"vite": "8.3.3",
|
|
58
|
+
"vitest": "5.0.3"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@tanstack/react-query": "^5.80.6",
|
|
62
|
-
"fimo": "
|
|
62
|
+
"fimo": "2.8.0-staging.10",
|
|
63
63
|
"fimo-react": ">=2.0.1",
|
|
64
64
|
"fimo-vite": ">=2.0.1",
|
|
65
65
|
"react": "^18.2.0 || ^19.0.0",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Pageview } from './Pageview.js';
|
|
2
|
-
type PageviewComponent = typeof Pageview;
|
|
3
|
-
type PageviewModule = {
|
|
4
|
-
Pageview: PageviewComponent;
|
|
5
|
-
};
|
|
6
|
-
type PageviewLoader = () => Promise<PageviewModule>;
|
|
7
|
-
type DisplayRoute = Parameters<PageviewComponent>[0]['routes'][number];
|
|
8
|
-
export declare function loadPageviewComponent(loadPageview?: PageviewLoader): Promise<typeof Pageview | null>;
|
|
9
|
-
export declare function OptionalTracking({ routes }: {
|
|
10
|
-
routes: DisplayRoute[];
|
|
11
|
-
}): import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=OptionalTracking.d.ts.map
|
package/dist/OptionalTracking.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
const defaultLoadPageview = () => import('./Pageview.js');
|
|
4
|
-
export async function loadPageviewComponent(loadPageview = defaultLoadPageview) {
|
|
5
|
-
try {
|
|
6
|
-
return (await loadPageview()).Pageview;
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export function OptionalTracking({ routes }) {
|
|
13
|
-
const [PageviewComponent, setPageviewComponent] = useState(null);
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
let cancelled = false;
|
|
16
|
-
loadPageviewComponent()
|
|
17
|
-
.then((component) => {
|
|
18
|
-
if (!cancelled) {
|
|
19
|
-
setPageviewComponent(() => component);
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
.catch(() => { });
|
|
23
|
-
return () => {
|
|
24
|
-
cancelled = true;
|
|
25
|
-
};
|
|
26
|
-
}, []);
|
|
27
|
-
return PageviewComponent ? _jsx(PageviewComponent, { routes: routes }) : null;
|
|
28
|
-
}
|
package/dist/Pageview.d.ts
DELETED
package/dist/Pageview.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { useLocation } from 'react-router';
|
|
3
|
-
const VISITOR_ID_STORAGE_KEY = 'fimo.analytics.visitor-id';
|
|
4
|
-
const SESSION_ID_STORAGE_KEY = 'fimo.analytics.session-id';
|
|
5
|
-
const viteEnv = import.meta.env;
|
|
6
|
-
const API_BASE_URL = viteEnv?.VITE_API_URL?.replace(/\/$/, '');
|
|
7
|
-
const ENABLE_ANALYTICS = (viteEnv?.VITE_ENABLE_ANALYTICS ?? '').toLowerCase() === 'true';
|
|
8
|
-
function isPreviewContext() {
|
|
9
|
-
if (typeof window === 'undefined') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const search = new URLSearchParams(window.location.search);
|
|
13
|
-
return search.has('bl_preview_token');
|
|
14
|
-
}
|
|
15
|
-
function createId() {
|
|
16
|
-
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
17
|
-
return crypto.randomUUID();
|
|
18
|
-
}
|
|
19
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
20
|
-
}
|
|
21
|
-
function readOrCreateStoredId(storage, key) {
|
|
22
|
-
const existing = storage.getItem(key);
|
|
23
|
-
if (existing && existing.length > 0) {
|
|
24
|
-
return existing;
|
|
25
|
-
}
|
|
26
|
-
const generated = createId();
|
|
27
|
-
storage.setItem(key, generated);
|
|
28
|
-
return generated;
|
|
29
|
-
}
|
|
30
|
-
function getVisitorId() {
|
|
31
|
-
if (typeof window === 'undefined') {
|
|
32
|
-
return createId();
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
return readOrCreateStoredId(window.localStorage, VISITOR_ID_STORAGE_KEY);
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return createId();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function getSessionId() {
|
|
42
|
-
if (typeof window === 'undefined') {
|
|
43
|
-
return createId();
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
return readOrCreateStoredId(window.sessionStorage, SESSION_ID_STORAGE_KEY);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return createId();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function normalizePath(path) {
|
|
53
|
-
const trimmed = path.trim();
|
|
54
|
-
if (!trimmed) {
|
|
55
|
-
return '/';
|
|
56
|
-
}
|
|
57
|
-
if (trimmed === '/') {
|
|
58
|
-
return '/';
|
|
59
|
-
}
|
|
60
|
-
return trimmed.replace(/\/+$/, '');
|
|
61
|
-
}
|
|
62
|
-
function findRouteName(pathname, routes) {
|
|
63
|
-
const currentPath = normalizePath(pathname);
|
|
64
|
-
const exactMatch = routes.find((route) => normalizePath(route.path) === currentPath);
|
|
65
|
-
if (exactMatch) {
|
|
66
|
-
return exactMatch.name;
|
|
67
|
-
}
|
|
68
|
-
const dynamicMatch = routes.find((route) => {
|
|
69
|
-
const normalizedPattern = normalizePath(route.path);
|
|
70
|
-
const regex = new RegExp(`^${normalizedPattern.replace(/:\w+/g, '[^/]+')}$`);
|
|
71
|
-
return regex.test(currentPath);
|
|
72
|
-
});
|
|
73
|
-
if (dynamicMatch) {
|
|
74
|
-
return dynamicMatch.name;
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
function sendPageview(path, pageName) {
|
|
79
|
-
if (typeof window === 'undefined' || !API_BASE_URL || !ENABLE_ANALYTICS || isPreviewContext()) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const payload = new URLSearchParams({
|
|
83
|
-
p: path || '/',
|
|
84
|
-
n: pageName,
|
|
85
|
-
v: getVisitorId(),
|
|
86
|
-
s: getSessionId(),
|
|
87
|
-
});
|
|
88
|
-
if (document.referrer) {
|
|
89
|
-
payload.set('r', document.referrer);
|
|
90
|
-
}
|
|
91
|
-
if (navigator.userAgent) {
|
|
92
|
-
payload.set('u', navigator.userAgent);
|
|
93
|
-
}
|
|
94
|
-
void fetch(`${API_BASE_URL}/e/p`, {
|
|
95
|
-
method: 'POST',
|
|
96
|
-
body: payload,
|
|
97
|
-
keepalive: true,
|
|
98
|
-
mode: 'cors',
|
|
99
|
-
credentials: 'omit',
|
|
100
|
-
}).catch(() => {
|
|
101
|
-
// best-effort analytics
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
export function Pageview({ routes }) {
|
|
105
|
-
const location = useLocation();
|
|
106
|
-
const lastTrackedPath = useRef(null);
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
const currentPath = `${location.pathname}${location.search}`;
|
|
109
|
-
const routeName = findRouteName(location.pathname, routes);
|
|
110
|
-
const currentPageName = routeName ?? normalizePath(location.pathname);
|
|
111
|
-
if (currentPath === lastTrackedPath.current) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
lastTrackedPath.current = currentPath;
|
|
115
|
-
sendPageview(currentPath, currentPageName);
|
|
116
|
-
}, [location.pathname, location.search, routes]);
|
|
117
|
-
return null;
|
|
118
|
-
}
|