fimo-next 2.8.0-staging.1 → 2.8.0-staging.3
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/runtime/next/provider.js +25 -11
- package/package.json +5 -5
|
@@ -4,7 +4,7 @@ import { QueryClient, QueryClientContext, QueryClientProvider } from '@tanstack/
|
|
|
4
4
|
import { createLabels } from 'fimo/labels';
|
|
5
5
|
import { ensurePreviewScript } from 'fimo/preview';
|
|
6
6
|
import { useRouter as usePagesRouter } from 'next/compat/router.js';
|
|
7
|
-
import { usePathname } from 'next/navigation.js';
|
|
7
|
+
import { usePathname, useRouter } from 'next/navigation.js';
|
|
8
8
|
import { createContext, Suspense, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
9
9
|
import { resolveConnection } from '#connection';
|
|
10
10
|
import { connectClientRuntime } from './client-runtime.js';
|
|
@@ -40,23 +40,37 @@ export function FimoProvider({ children, ...props }) {
|
|
|
40
40
|
const [connection] = useState(resolveConnection);
|
|
41
41
|
return (_jsxs(_Fragment, { children: [_jsx("script", { id: FIMO_CONNECTION_SCRIPT_ID, type: "application/json", dangerouslySetInnerHTML: { __html: serializeConnection(connection) } }), _jsx(FimoClientProvider, { connection: connection, ...props, children: children })] }));
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* `next/compat/router` answers only under the Pages Router, and
|
|
45
|
+
* `next/navigation`'s router hook only under the App Router, so each router
|
|
46
|
+
* gets its own bridge rather than one component calling a hook that may not
|
|
47
|
+
* exist.
|
|
48
|
+
*/
|
|
43
49
|
function FimoPreviewRuntime({ previewScriptUrl }) {
|
|
50
|
+
const pagesRouter = usePagesRouter();
|
|
51
|
+
return pagesRouter ? (_jsx(PagesRouterPreview, { router: pagesRouter, previewScriptUrl: previewScriptUrl })) : (_jsx(AppRouterPreview, { previewScriptUrl: previewScriptUrl }));
|
|
52
|
+
}
|
|
53
|
+
function AppRouterPreview({ previewScriptUrl }) {
|
|
54
|
+
const router = useRouter();
|
|
55
|
+
// The router fetches and renders the picked route; a raw history.pushState
|
|
56
|
+
// only moved the URL and left the previous page on screen.
|
|
57
|
+
const navigate = useCallback((to) => router.push(to), [router]);
|
|
58
|
+
usePreviewBridge(previewScriptUrl, usePathname() ?? '/', navigate);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
function PagesRouterPreview({ router, previewScriptUrl, }) {
|
|
62
|
+
const pathname = usePathname() ?? router.asPath.split(/[?#]/, 1)[0] ?? '/';
|
|
63
|
+
const navigate = useCallback((to) => router.push(to), [router]);
|
|
64
|
+
usePreviewBridge(previewScriptUrl, pathname, navigate);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function usePreviewBridge(previewScriptUrl, pathname, navigate) {
|
|
44
68
|
const context = useContext(FimoNextContext);
|
|
45
69
|
const locale = context.locale ?? context.connection?.defaultLocale ?? 'en';
|
|
46
|
-
const appPathname = usePathname();
|
|
47
|
-
const pagesRouter = usePagesRouter();
|
|
48
|
-
const pathname = appPathname ?? pagesRouter?.asPath.split(/[?#]/, 1)[0] ?? '/';
|
|
49
|
-
const navigate = useCallback((to) => {
|
|
50
|
-
if (pagesRouter) {
|
|
51
|
-
return pagesRouter.push(to);
|
|
52
|
-
}
|
|
53
|
-
window.history.pushState(null, '', to);
|
|
54
|
-
}, [pagesRouter]);
|
|
55
70
|
useEffect(() => {
|
|
56
71
|
ensurePreviewScript(previewScriptUrl);
|
|
57
72
|
return connectNextPreview({ locale, navigate, pathname, previewScriptUrl });
|
|
58
73
|
}, [locale, navigate, pathname, previewScriptUrl]);
|
|
59
|
-
return null;
|
|
60
74
|
}
|
|
61
75
|
export function useNextContentLocale(requestedLocale, defaultLocale) {
|
|
62
76
|
const context = useContext(FimoNextContext);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fimo-next",
|
|
3
|
-
"version": "2.8.0-staging.
|
|
3
|
+
"version": "2.8.0-staging.3",
|
|
4
4
|
"description": "Fimo runtime for Next.js projects.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"test:watch": "vitest"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@fimo/tsconfig": "2.8.0-staging.
|
|
52
|
+
"@fimo/tsconfig": "2.8.0-staging.3",
|
|
53
53
|
"@tanstack/react-query": "^5.80.6",
|
|
54
54
|
"@types/node": "22.18.6",
|
|
55
55
|
"@types/react": "19.2.14",
|
|
56
56
|
"@types/react-dom": "19.2.3",
|
|
57
|
-
"fimo": "2.8.0-staging.
|
|
58
|
-
"fimo-react": "2.8.0-staging.
|
|
57
|
+
"fimo": "2.8.0-staging.3",
|
|
58
|
+
"fimo-react": "2.8.0-staging.3",
|
|
59
59
|
"next": "16.3.3",
|
|
60
60
|
"react": "19.2.4",
|
|
61
61
|
"react-dom": "19.2.4",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@tanstack/react-query": "^5.80.6",
|
|
67
|
-
"fimo": "2.8.0-staging.
|
|
67
|
+
"fimo": "2.8.0-staging.3",
|
|
68
68
|
"fimo-react": ">=2.0.1",
|
|
69
69
|
"next": "^15.0.0 || ^16.0.0",
|
|
70
70
|
"react": "^18.2.0 || ^19.0.0",
|