fimo-react-router 2.9.0-staging.4 → 2.9.0-staging.5
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/FimoScripts.js +3 -24
- package/dist/seo.d.ts +1 -0
- package/dist/seo.js +13 -21
- package/package.json +6 -6
package/dist/FimoScripts.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { buildSiteSchemas, serializeJsonLd } from 'fimo/seo';
|
|
2
3
|
// @ts-ignore - virtual module provided by fimoConfigPlugin in fimo-vite
|
|
3
4
|
import rawConfig from 'virtual:fimo-config';
|
|
4
5
|
// @ts-ignore - side-effect import; vite-served so import.meta.hot works inside
|
|
@@ -7,28 +8,6 @@ import 'virtual:fimo-overlay-hmr';
|
|
|
7
8
|
import overlayRuntime from 'virtual:fimo-overlay-runtime';
|
|
8
9
|
const config = rawConfig;
|
|
9
10
|
const runtime = overlayRuntime;
|
|
10
|
-
function buildSiteSchemas() {
|
|
11
|
-
const seo = config.seo;
|
|
12
|
-
if (!seo?.siteName || !seo?.url) {
|
|
13
|
-
return [];
|
|
14
|
-
}
|
|
15
|
-
const organization = {
|
|
16
|
-
'@context': 'https://schema.org',
|
|
17
|
-
'@type': 'Organization',
|
|
18
|
-
name: seo.siteName,
|
|
19
|
-
url: seo.url,
|
|
20
|
-
};
|
|
21
|
-
if (seo.favicon) {
|
|
22
|
-
organization.logo = seo.favicon;
|
|
23
|
-
}
|
|
24
|
-
const website = {
|
|
25
|
-
'@context': 'https://schema.org',
|
|
26
|
-
'@type': 'WebSite',
|
|
27
|
-
name: seo.siteName,
|
|
28
|
-
url: seo.url,
|
|
29
|
-
};
|
|
30
|
-
return [organization, website];
|
|
31
|
-
}
|
|
32
11
|
/**
|
|
33
12
|
* Renders extra <script> tags in <head>:
|
|
34
13
|
* - Dev overlay runtime (window.error / unhandledrejection bridge to parent)
|
|
@@ -40,6 +19,6 @@ function buildSiteSchemas() {
|
|
|
40
19
|
* since framework mode bypasses `index.html` entirely.
|
|
41
20
|
*/
|
|
42
21
|
export function FimoScripts() {
|
|
43
|
-
const siteSchemas = buildSiteSchemas();
|
|
44
|
-
return (_jsxs(_Fragment, { children: [runtime ? _jsx("script", { type: "module", dangerouslySetInnerHTML: { __html: runtime } }) : null, siteSchemas.map((schema, index) => (_jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html:
|
|
22
|
+
const siteSchemas = buildSiteSchemas(config.seo);
|
|
23
|
+
return (_jsxs(_Fragment, { children: [runtime ? _jsx("script", { type: "module", dangerouslySetInnerHTML: { __html: runtime } }) : null, siteSchemas.map((schema, index) => (_jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: serializeJsonLd(schema) } }, index)))] }));
|
|
45
24
|
}
|
package/dist/seo.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export declare function loadFimoMetaData({ request, url }: {
|
|
|
99
99
|
}): Promise<{
|
|
100
100
|
fimoMetaData: Record<string, unknown> | undefined;
|
|
101
101
|
fimoLocale: import("fimo-react").FimoLocaleResolution;
|
|
102
|
+
fimoSpaShell: boolean;
|
|
102
103
|
}>;
|
|
103
104
|
export {};
|
|
104
105
|
//# sourceMappingURL=seo.d.ts.map
|
package/dist/seo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getFimoTextDirection, toHtmlLang } from 'fimo/i18n';
|
|
2
|
-
import {
|
|
2
|
+
import { buildCanonicalUrl, resolveSeoForPath } from 'fimo/seo';
|
|
3
3
|
// @ts-ignore - virtual module provided by fimoConfigPlugin in fimo-vite
|
|
4
4
|
import rawConfig from 'virtual:fimo-config';
|
|
5
5
|
import { resolveFimoLocaleForUrl, resolveMetaEntries } from './prefetch.js';
|
|
@@ -8,19 +8,7 @@ const config = rawConfig;
|
|
|
8
8
|
export function getSeoForPath(pathname, routeData) {
|
|
9
9
|
return resolveSeoForPath(pathname, config, routeData);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
if (!seoUrl) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
return new URL(normalizePathname(pathname), seoUrl).toString();
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function seoToMeta(seo, pathname) {
|
|
23
|
-
const canonical = buildCanonicalUrl(seo.url, pathname);
|
|
11
|
+
function seoToMeta(seo, canonical) {
|
|
24
12
|
return [
|
|
25
13
|
...(seo.title ? [{ title: seo.title }] : []),
|
|
26
14
|
...(seo.description ? [{ name: 'description', content: seo.description }] : []),
|
|
@@ -52,20 +40,23 @@ export function buildMetaForPath(pathname, routeData) {
|
|
|
52
40
|
if (!seo) {
|
|
53
41
|
return [];
|
|
54
42
|
}
|
|
55
|
-
return seoToMeta(seo, pathname);
|
|
43
|
+
return seoToMeta(seo, buildCanonicalUrl(seo.url, pathname));
|
|
56
44
|
}
|
|
57
45
|
export function buildFimoMeta(args) {
|
|
58
46
|
const pathname = args.location.pathname;
|
|
59
47
|
const firstMatch = args.matches[0];
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
// React Router 8 names a match's loader result `loaderData`; React Router 7 calls it `data`.
|
|
49
|
+
const rootData = firstMatch && typeof firstMatch === 'object'
|
|
50
|
+
? (firstMatch.loaderData ?? firstMatch.data)
|
|
62
51
|
: undefined;
|
|
63
|
-
const
|
|
64
|
-
const seo = getSeoForPath(pathname,
|
|
52
|
+
const rootRecord = rootData && typeof rootData === 'object' ? rootData : undefined;
|
|
53
|
+
const seo = getSeoForPath(pathname, rootRecord?.fimoMetaData);
|
|
65
54
|
if (!seo) {
|
|
66
55
|
return [];
|
|
67
56
|
}
|
|
68
|
-
|
|
57
|
+
// The SPA shell is one HTML file served for every path, so only the browser knows which page it shows.
|
|
58
|
+
const isSpaShellRender = rootRecord?.fimoSpaShell === true && typeof document === 'undefined';
|
|
59
|
+
return seoToMeta(seo, isSpaShellRender ? undefined : buildCanonicalUrl(seo.url, pathname));
|
|
69
60
|
}
|
|
70
61
|
/**
|
|
71
62
|
* Returns the attributes Fimo injects onto the root `<html>` element.
|
|
@@ -91,5 +82,6 @@ export async function loadFimoMetaData({ request, url }) {
|
|
|
91
82
|
const target = normalizeLoaderUrl(request, url);
|
|
92
83
|
const fimoMetaData = await resolveMetaEntries(target);
|
|
93
84
|
const fimoLocale = resolveFimoLocaleForUrl(target);
|
|
94
|
-
|
|
85
|
+
const fimoSpaShell = request.headers.get('X-React-Router-SPA-Mode') === 'yes' || new URL(target).pathname === '/__spa-fallback.html';
|
|
86
|
+
return { fimoMetaData, fimoLocale, fimoSpaShell };
|
|
95
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fimo-react-router",
|
|
3
|
-
"version": "2.9.0-staging.
|
|
3
|
+
"version": "2.9.0-staging.5",
|
|
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,14 +42,14 @@
|
|
|
42
42
|
"react-error-boundary": "^6.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@fimo/tsconfig": "2.9.0-staging.
|
|
45
|
+
"@fimo/tsconfig": "2.9.0-staging.5",
|
|
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.9.0-staging.
|
|
51
|
-
"fimo-react": "2.9.0-staging.
|
|
52
|
-
"fimo-vite": "2.9.0-staging.
|
|
50
|
+
"fimo": "2.9.0-staging.5",
|
|
51
|
+
"fimo-react": "2.9.0-staging.5",
|
|
52
|
+
"fimo-vite": "2.9.0-staging.5",
|
|
53
53
|
"react": "19.2.4",
|
|
54
54
|
"react-dom": "19.2.4",
|
|
55
55
|
"react-router": "7.18.4",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@tanstack/react-query": "^5.80.6",
|
|
62
|
-
"fimo": "2.9.0-staging.
|
|
62
|
+
"fimo": "2.9.0-staging.5",
|
|
63
63
|
"fimo-react": ">=2.0.1",
|
|
64
64
|
"fimo-vite": ">=2.0.1",
|
|
65
65
|
"react": "^18.2.0 || ^19.0.0",
|