@farm.js/plugin 0.1.62 → 0.1.64
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/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +4 -2
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +23 -7
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +20 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAahD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAahD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAmgD1D"}
|
package/dist/rsc/entries/rsc.js
CHANGED
|
@@ -98,7 +98,7 @@ ${ctx.mobileClient === "entry" ? "import { _applyFarmMobileShellClient } from '@
|
|
|
98
98
|
matchAPIRouteAtBasePath,
|
|
99
99
|
} from '@farm.js/core/api/runtime';
|
|
100
100
|
import { _runWithAfterRequest } from '@farm.js/core/after';
|
|
101
|
-
import { _runWithAPIRequestRuntime, _runWithCurrentRequest, searchParamsToObject } from '@farm.js/core/internal/production-runtime';
|
|
101
|
+
import { _runWithAPIRequestRuntime, _runWithCurrentRequest, cloneFarmRequestWithContext, searchParamsToObject } from '@farm.js/core/internal/production-runtime';
|
|
102
102
|
import { getFarmRedirectError, isFarmNotFoundError } from '@farm.js/core/internal/production-runtime';
|
|
103
103
|
import {
|
|
104
104
|
parseRoutePath,
|
|
@@ -863,7 +863,9 @@ async function resolveFarmRequest(farmCacheGuard, request, context) {
|
|
|
863
863
|
if (imageResponse) return imageResponse;
|
|
864
864
|
}
|
|
865
865
|
|
|
866
|
-
|
|
866
|
+
// A plain clone of the request would let some undici versions cancel the original's body when the
|
|
867
|
+
// declined clone is collected, before a server action reads it.
|
|
868
|
+
const apiResponse = await handleAPIRequest(cloneFarmRequestWithContext(request));
|
|
867
869
|
if (apiResponse) {
|
|
868
870
|
return applyProductionMiddlewareHeaders(apiResponse, middlewareHeaders);
|
|
869
871
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/ssr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ssr.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/ssr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAgO1D"}
|
package/dist/rsc/entries/ssr.js
CHANGED
|
@@ -40,17 +40,26 @@ const cssLinkTag = resolvedCssHref
|
|
|
40
40
|
: '';
|
|
41
41
|
|
|
42
42
|
// Work on bytes: chunk boundaries need not align with UTF-8 code points.
|
|
43
|
-
function injectBeforeStream(markerText,
|
|
43
|
+
function injectBeforeStream(markerText, tagOrResolve) {
|
|
44
44
|
const encoder = new TextEncoder();
|
|
45
45
|
const marker = encoder.encode(markerText);
|
|
46
|
-
|
|
46
|
+
// A function is read when the marker passes, after the shell rendered.
|
|
47
|
+
let tag = typeof tagOrResolve === 'function' ? undefined : tagOrResolve;
|
|
48
|
+
let insertion = tag === undefined ? undefined : encoder.encode(tag);
|
|
49
|
+
const resolveTag = () => {
|
|
50
|
+
if (tag === undefined) {
|
|
51
|
+
tag = tagOrResolve();
|
|
52
|
+
insertion = encoder.encode(tag);
|
|
53
|
+
}
|
|
54
|
+
return tag;
|
|
55
|
+
};
|
|
47
56
|
let buffer = new Uint8Array(0);
|
|
48
57
|
let injected = false;
|
|
49
58
|
|
|
50
59
|
return new TransformStream({
|
|
51
60
|
transform(chunk, controller) {
|
|
52
61
|
const bytes = typeof chunk === 'string' ? encoder.encode(chunk) : chunk;
|
|
53
|
-
if (injected || !tag) {
|
|
62
|
+
if (injected || (typeof tagOrResolve !== 'function' && !tag)) {
|
|
54
63
|
controller.enqueue(bytes);
|
|
55
64
|
return;
|
|
56
65
|
}
|
|
@@ -68,7 +77,7 @@ function injectBeforeStream(markerText, tag) {
|
|
|
68
77
|
}
|
|
69
78
|
if (index >= 0) {
|
|
70
79
|
if (index) controller.enqueue(pending.subarray(0, index));
|
|
71
|
-
controller.enqueue(insertion);
|
|
80
|
+
if (resolveTag()) controller.enqueue(insertion);
|
|
72
81
|
controller.enqueue(pending.subarray(index));
|
|
73
82
|
buffer = new Uint8Array(0);
|
|
74
83
|
injected = true;
|
|
@@ -172,7 +181,12 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
172
181
|
passThrough.on('error', (e) => controller.error(e));
|
|
173
182
|
}
|
|
174
183
|
});
|
|
175
|
-
|
|
184
|
+
// In development, the stylesheets the shell's client components import (CSS modules come from
|
|
185
|
+
// JavaScript in the browser, so without links their HTML is unstyled until scripts run).
|
|
186
|
+
const devStyles = globalThis.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
187
|
+
let out = webStream.pipeThrough(
|
|
188
|
+
injectIntoHeadStream(typeof devStyles === 'function' ? () => headTags + devStyles() : headTags),
|
|
189
|
+
);
|
|
176
190
|
out = out.pipeThrough(injectRSCPayload(s2));
|
|
177
191
|
out = out.pipeThrough(streamingClientScriptInjector);
|
|
178
192
|
return out;
|
|
@@ -182,8 +196,10 @@ export async function renderHTML(firstArg, options = {}) {
|
|
|
182
196
|
debug('Rendering to HTML stream (then buffering)');
|
|
183
197
|
const fullHtmlRaw = await pipeableStreamToString(passThrough);
|
|
184
198
|
let fullHtml = fullHtmlRaw;
|
|
185
|
-
|
|
186
|
-
|
|
199
|
+
const bufferedDevStyles = globalThis.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
200
|
+
const bufferedHeadTags = headTags + (typeof bufferedDevStyles === 'function' ? bufferedDevStyles() : '');
|
|
201
|
+
if (bufferedHeadTags && fullHtml.includes("</head>")) {
|
|
202
|
+
fullHtml = fullHtml.replace("</head>", () => bufferedHeadTags + "</head>");
|
|
187
203
|
}
|
|
188
204
|
${ctx.actionsEnabled
|
|
189
205
|
? `// Ensure __viteRscCallServer is set before any module runs (fixes "is not a function" when form submits)
|
package/dist/rsc/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rsc/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAIL,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AACpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,oBAAoB,E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gH;IAChH,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB;;;;OAIG;IACH,EAAE,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACtC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAA;KAAE,CAAC;IACtD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,iBAAiB,CAAC;IACxB,6FAA6F;IAC7F,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,aAAkB,GAAG,UAAU,CA0EnE;AAsbD;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,EAAE,CAouC5E"}
|
package/dist/rsc/index.js
CHANGED
|
@@ -25,7 +25,7 @@ import { loadFarmDevModule, FarmDevEnvironmentError } from "@farm.js/core/plugin
|
|
|
25
25
|
import { parseAst, version as viteVersion, } from "vite";
|
|
26
26
|
import { init as initModuleLexer, parse as parseModuleImports } from "es-module-lexer";
|
|
27
27
|
import { farmEnvironmentFunctionsPlugin } from "@farm.js/core/environment/vite";
|
|
28
|
-
import {
|
|
28
|
+
import { collectDevStylesheetUrls, farmFontImportsPlugin, farmImageImportsPlugin, generateClientCachePersistenceCode, getPublicFarmImageConfig, resolveFarmClientCacheAdapterEntry, resolveFarmClientOptimizeDeps, resolveFarmImageConfig, resolveFarmImageProviderForRuntime, resolveFarmImageServerRuntime, readRouteRenderingDirectiveFromFile, } from "@farm.js/core/vite";
|
|
29
29
|
import { generateRscEntry } from "./entries/rsc.js";
|
|
30
30
|
import { resolveMarkdownConfig } from "@farm.js/core/markdown";
|
|
31
31
|
import { generateSsrEntry } from "./entries/ssr.js";
|
|
@@ -770,6 +770,7 @@ export default function farmRsc(options = {}) {
|
|
|
770
770
|
env: getResolvedEnv(),
|
|
771
771
|
});
|
|
772
772
|
const srcDir = c.srcDir ?? "src";
|
|
773
|
+
const clientOptimizeDeps = resolveFarmClientOptimizeDeps(path.resolve(root, srcDir), root);
|
|
773
774
|
const outDir = c.outDir ?? "dist";
|
|
774
775
|
const deploymentId = normalizeFarmDeploymentId(options.deploymentId ||
|
|
775
776
|
c.deploymentId ||
|
|
@@ -1076,8 +1077,11 @@ export default function farmRsc(options = {}) {
|
|
|
1076
1077
|
"rsc-html-stream/client",
|
|
1077
1078
|
// Client components and the packages they use load only once a page renders
|
|
1078
1079
|
// (client references), so they would be found late too.
|
|
1079
|
-
...
|
|
1080
|
+
...clientOptimizeDeps.include,
|
|
1080
1081
|
],
|
|
1082
|
+
// Packages whose react-server build re-exports a "use client" module: the plugin
|
|
1083
|
+
// loads that module from the package, so pre-bundling them would add a copy.
|
|
1084
|
+
exclude: clientOptimizeDeps.exclude,
|
|
1081
1085
|
},
|
|
1082
1086
|
},
|
|
1083
1087
|
},
|
|
@@ -1359,6 +1363,20 @@ if (document.readyState === 'loading') {
|
|
|
1359
1363
|
return;
|
|
1360
1364
|
}
|
|
1361
1365
|
logInfo("Dev server middleware ready");
|
|
1366
|
+
// The stylesheets the SSR environment's modules import, for entries/ssr.ts to link in the
|
|
1367
|
+
// head: a client component's CSS module otherwise arrives with its JavaScript, so its
|
|
1368
|
+
// server HTML is unstyled until scripts run. Removed when this server closes.
|
|
1369
|
+
const devStyles = () => collectDevStylesheetUrls(server.environments.ssr?.moduleGraph.idToModuleMap.values() ?? [], undefined, {
|
|
1370
|
+
cssModules: true,
|
|
1371
|
+
})
|
|
1372
|
+
.map((href) => `<link rel="stylesheet" href="${href.replace(/"/g, """)}" data-farm-dev-style>`)
|
|
1373
|
+
.join("");
|
|
1374
|
+
globalThis.__FARM_RSC_DEV_CLIENT_STYLES__ = devStyles;
|
|
1375
|
+
server.httpServer?.once("close", () => {
|
|
1376
|
+
const scope = globalThis;
|
|
1377
|
+
if (scope.__FARM_RSC_DEV_CLIENT_STYLES__ === devStyles)
|
|
1378
|
+
delete scope.__FARM_RSC_DEV_CLIENT_STYLES__;
|
|
1379
|
+
});
|
|
1362
1380
|
const serverStartTime = Date.now();
|
|
1363
1381
|
let bannerPrinted = false;
|
|
1364
1382
|
server.httpServer?.once("listening", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.64",
|
|
4
4
|
"description": "Official plugins for Farm.js framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Farm.js Team",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"nitro": "3.0.260903-beta",
|
|
64
64
|
"picocolors": "^1.0.0",
|
|
65
65
|
"rsc-html-stream": "^0.0.4",
|
|
66
|
-
"@farm.js/core": "0.1.
|
|
66
|
+
"@farm.js/core": "0.1.64"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/node": "^22.20.5",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"react-dom": "19.2.8",
|
|
85
85
|
"react-server-dom-webpack": "19.2.8",
|
|
86
86
|
"vite": ">=6.0.0",
|
|
87
|
-
"@farm.js/core": "0.1.
|
|
87
|
+
"@farm.js/core": "0.1.64"
|
|
88
88
|
},
|
|
89
89
|
"peerDependenciesMeta": {
|
|
90
90
|
"@vitejs/plugin-rsc": {
|