@farm.js/plugin 0.1.67 → 0.1.69
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rsc/entries/client.d.ts +2 -0
- package/dist/rsc/entries/client.d.ts.map +1 -1
- package/dist/rsc/entries/client.js +59 -5
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +428 -50
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +18 -6
- package/dist/rsc/index.d.ts +17 -5
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +109 -25
- package/dist/rsc/middleware-config-module.d.ts +15 -3
- package/dist/rsc/middleware-config-module.d.ts.map +1 -1
- package/dist/rsc/middleware-config-module.js +22 -6
- package/dist/rsc/nitro-build.d.ts.map +1 -1
- package/dist/rsc/nitro-build.js +31 -4
- package/dist/rsc/presets.d.ts +6 -0
- package/dist/rsc/presets.d.ts.map +1 -0
- package/dist/rsc/presets.js +7 -0
- package/dist/rsc/types.d.ts +39 -2
- package/dist/rsc/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { EntryContext } from "../types.js";
|
|
2
2
|
export declare const CLIENT_ENTRY_CORE_IMPORTS: readonly ["@farm.js/core/client", "@farm.js/core/deployment", "@farm.js/core/internal/client-runtime", "@farm.js/core/server-query/client"];
|
|
3
|
+
/** What the browser entry of an app with i18n imports as well. */
|
|
4
|
+
export declare const CLIENT_ENTRY_I18N_IMPORTS: readonly ["@farm.js/core/i18n", "@farm.js/core/i18n/client"];
|
|
3
5
|
export declare const serverFnTransportErrorClientRuntime = "function createFarmServerFnTransportError(value) {\n const message = value && typeof value === 'object' && typeof value.message === 'string'\n ? value.message\n : 'Server function failed';\n const error = new Error(message);\n\n if (\n value &&\n typeof value === 'object' &&\n value.name === 'ServerFnFailure' &&\n typeof value.code === 'string' &&\n Number.isInteger(value.status) &&\n value.status >= 400 &&\n value.status <= 599 &&\n Object.prototype.hasOwnProperty.call(value, 'data')\n ) {\n error.name = 'ServerFnFailure';\n error.code = value.code;\n error.status = value.status;\n error.data = value.data;\n Object.defineProperty(error, Symbol.for('farm.server-fn.failure'), {\n value: true,\n enumerable: false,\n });\n return error;\n }\n\n error.name = 'ServerActionError';\n return error;\n}";
|
|
4
6
|
/**
|
|
5
7
|
* Generates the browser entry file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,eAAO,MAAM,yBAAyB,6IAK5B,CAAC;AAEX,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD,eAAO,MAAM,yBAAyB,6IAK5B,CAAC;AAEX,kEAAkE;AAClE,eAAO,MAAM,yBAAyB,8DAG5B,CAAC;AAEX,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAmkB7D"}
|
|
@@ -6,6 +6,11 @@ export const CLIENT_ENTRY_CORE_IMPORTS = [
|
|
|
6
6
|
"@farm.js/core/internal/client-runtime",
|
|
7
7
|
"@farm.js/core/server-query/client",
|
|
8
8
|
];
|
|
9
|
+
/** What the browser entry of an app with i18n imports as well. */
|
|
10
|
+
export const CLIENT_ENTRY_I18N_IMPORTS = [
|
|
11
|
+
"@farm.js/core/i18n",
|
|
12
|
+
"@farm.js/core/i18n/client",
|
|
13
|
+
];
|
|
9
14
|
export const serverFnTransportErrorClientRuntime = `function createFarmServerFnTransportError(value) {
|
|
10
15
|
const message = value && typeof value === 'object' && typeof value.message === 'string'
|
|
11
16
|
? value.message
|
|
@@ -70,6 +75,43 @@ import {
|
|
|
70
75
|
} from '@farm.js/core/deployment';
|
|
71
76
|
import { createFarmRouteAnnouncer, runFarmNavigationDelegates } from '@farm.js/core/internal/client-runtime';
|
|
72
77
|
`;
|
|
78
|
+
// <Link href="/about"> renders /console/about under basePath "/console", as the RSC server
|
|
79
|
+
// rendered it, so the page hydrates with the same href.
|
|
80
|
+
if (!["", "/"].includes(ctx.basePath.trim())) {
|
|
81
|
+
imports += `import { setFarmBasePath } from '@farm.js/core/internal/client-runtime';
|
|
82
|
+
setFarmBasePath(${JSON.stringify(ctx.basePath)});
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
// trailingSlash: <Link href="/about"> renders /about/, as the RSC server rendered it.
|
|
86
|
+
if (ctx.trailingSlash) {
|
|
87
|
+
imports += `import { setFarmTrailingSlashPreference } from '@farm.js/core/internal/client-runtime';
|
|
88
|
+
setFarmTrailingSlashPreference(true);
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
const i18n = ctx.i18n?.enabled === true;
|
|
92
|
+
if (i18n) {
|
|
93
|
+
imports += `import { localizeFarmHref, resolveFarmLocalePath } from '@farm.js/core/i18n';
|
|
94
|
+
import { _setFarmI18nClientSnapshot } from '@farm.js/core/i18n/client';
|
|
95
|
+
|
|
96
|
+
// A link to another locale loads as a document, as Farm's <Link> does in other apps, so the page
|
|
97
|
+
// and the catalog its client components read change together.
|
|
98
|
+
function farmIsLocaleChange(url) {
|
|
99
|
+
const snapshot = window.__FARM_I18N__;
|
|
100
|
+
if (!snapshot || snapshot.routing === 'none') return false;
|
|
101
|
+
const target = resolveFarmLocalePath(url.pathname, snapshot);
|
|
102
|
+
return (target.locale || snapshot.defaultLocale) !== snapshot.locale;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// A redirect() thrown while a navigation renders goes to its target in the page's locale, as the
|
|
106
|
+
// server localizes the redirects it answers.
|
|
107
|
+
function farmLocalizeRedirect(url) {
|
|
108
|
+
const snapshot = window.__FARM_I18N__;
|
|
109
|
+
return snapshot && url.startsWith('/') && !url.startsWith('//')
|
|
110
|
+
? localizeFarmHref(url, snapshot.locale, snapshot)
|
|
111
|
+
: url;
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
}
|
|
73
115
|
// farm dev --mobile: every page runs in the shell's WebView, so this entry is the mobile client.
|
|
74
116
|
if (ctx.mobileClient === "inline") {
|
|
75
117
|
imports += generateMobileShellNavigation();
|
|
@@ -264,7 +306,7 @@ class FarmNavigationErrorBoundary extends React.Component {
|
|
|
264
306
|
componentDidCatch(error) {
|
|
265
307
|
const digest = error && typeof error.digest === 'string' ? error.digest : '';
|
|
266
308
|
if (digest.startsWith('FARM_REDIRECT;')) {
|
|
267
|
-
farmNavigateRef.current?.(digest.split(';').slice(2).join(';'), 'replace');
|
|
309
|
+
farmNavigateRef.current?.(${i18n ? "farmLocalizeRedirect(digest.split(';').slice(2).join(';'))" : "digest.split(';').slice(2).join(';')"}, 'replace');
|
|
268
310
|
return;
|
|
269
311
|
}
|
|
270
312
|
location.reload();
|
|
@@ -299,10 +341,14 @@ async function main() {
|
|
|
299
341
|
console.error('[Farm.js] Failed to deserialize RSC payload:', e);
|
|
300
342
|
return;
|
|
301
343
|
}
|
|
302
|
-
|
|
344
|
+
|
|
303
345
|
// The page the document loaded with is the baseline: it is never announced.
|
|
304
346
|
const announceRoute = createFarmRouteAnnouncer();
|
|
305
|
-
|
|
347
|
+
${i18n
|
|
348
|
+
? ` // The locale the server rendered with, before anything hydrates (window.__FARM_I18N__).
|
|
349
|
+
if (initial.i18n) _setFarmI18nClientSnapshot(initial.i18n);
|
|
350
|
+
`
|
|
351
|
+
: ""}
|
|
306
352
|
// Root component that manages RSC state
|
|
307
353
|
function BrowserRoot() {
|
|
308
354
|
const [payload, set] = React.useState(initial);
|
|
@@ -337,7 +383,15 @@ async function main() {
|
|
|
337
383
|
description?.remove();
|
|
338
384
|
}
|
|
339
385
|
}, [payload.metadata?.title, payload.metadata?.description]);
|
|
340
|
-
|
|
386
|
+
${i18n
|
|
387
|
+
? `
|
|
388
|
+
// A payload from back/forward or a refresh carries its locale (and, in development, edited
|
|
389
|
+
// messages): client components re-read it before the browser paints.
|
|
390
|
+
React.useLayoutEffect(() => {
|
|
391
|
+
if (payload !== initial && payload.i18n) _setFarmI18nClientSnapshot(payload.i18n);
|
|
392
|
+
}, [payload]);
|
|
393
|
+
`
|
|
394
|
+
: ""}
|
|
341
395
|
// Announce a client navigation to screen readers once its page and title are in place.
|
|
342
396
|
React.useEffect(() => {
|
|
343
397
|
if (payload !== initial) announceRoute();
|
|
@@ -411,7 +465,7 @@ ${withPlugins(`
|
|
|
411
465
|
// Back/forward, refreshes and same-page moves are not offered; other origins load as documents.
|
|
412
466
|
async function navigate(href, action) {
|
|
413
467
|
const url = new URL(href, location.href);
|
|
414
|
-
if (url.origin !== location.origin) {
|
|
468
|
+
if (url.origin !== location.origin${i18n ? " || farmIsLocaleChange(url)" : ""}) {
|
|
415
469
|
location.assign(url.href);
|
|
416
470
|
return;
|
|
417
471
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+HhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAu4D1D"}
|