@farm.js/plugin 0.1.60 → 0.1.61
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/middleware/index.d.ts +1 -8
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +10 -16
- package/dist/middleware/matching.d.ts +2 -4
- package/dist/middleware/matching.d.ts.map +1 -1
- package/dist/middleware/matching.js +47 -7
- package/dist/rsc/entries/client.d.ts.map +1 -1
- package/dist/rsc/entries/client.js +15 -85
- package/dist/rsc/entries/rsc.d.ts.map +1 -1
- package/dist/rsc/entries/rsc.js +45 -563
- package/dist/rsc/entries/ssr.d.ts.map +1 -1
- package/dist/rsc/entries/ssr.js +6 -7
- package/dist/rsc/index.d.ts +3 -38
- package/dist/rsc/index.d.ts.map +1 -1
- package/dist/rsc/index.js +292 -279
- package/dist/rsc/middleware-config-module.d.ts +0 -3
- package/dist/rsc/middleware-config-module.d.ts.map +1 -1
- package/dist/rsc/middleware-config-module.js +28 -41
- package/dist/rsc/nitro-build.d.ts.map +1 -1
- package/dist/rsc/nitro-build.js +81 -268
- package/dist/rsc/server-fn-transform.d.ts +5 -1
- package/dist/rsc/server-fn-transform.d.ts.map +1 -1
- package/dist/rsc/server-fn-transform.js +338 -3
- package/dist/rsc/types.d.ts +0 -39
- package/dist/rsc/types.d.ts.map +1 -1
- package/dist/rsc/vite-plugin-nitro.d.ts +0 -2
- package/dist/rsc/vite-plugin-nitro.d.ts.map +1 -1
- package/dist/rsc/vite-plugin-nitro.js +2 -12
- package/package.json +3 -3
- package/dist/rsc/client-sourcemaps.d.ts +0 -13
- package/dist/rsc/client-sourcemaps.d.ts.map +0 -1
- package/dist/rsc/client-sourcemaps.js +0 -52
- package/dist/rsc/document-layouts.d.ts +0 -16
- package/dist/rsc/document-layouts.d.ts.map +0 -1
- package/dist/rsc/document-layouts.js +0 -82
- package/dist/rsc/mobile-client.d.ts +0 -67
- package/dist/rsc/mobile-client.d.ts.map +0 -1
- package/dist/rsc/mobile-client.js +0 -148
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ export interface CookieOptions {
|
|
|
40
40
|
export interface CookieJar {
|
|
41
41
|
get(name: string): string | undefined;
|
|
42
42
|
set(name: string, value: string, options?: CookieOptions): void;
|
|
43
|
-
delete(name: string
|
|
43
|
+
delete(name: string): void;
|
|
44
44
|
getAll(): Record<string, string>;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -50,14 +50,7 @@ export interface MiddlewareContext {
|
|
|
50
50
|
request: IncomingMessage;
|
|
51
51
|
response: ServerResponse;
|
|
52
52
|
url: URL;
|
|
53
|
-
/** Request pathname as received: still percent-encoded. */
|
|
54
53
|
pathname: string;
|
|
55
|
-
/**
|
|
56
|
-
* The pathname the router matches: each segment decoded once, as core's
|
|
57
|
-
* `ctx.routePathname`. `.when()` conditions and function matchers also see it,
|
|
58
|
-
* so `/%61dmin` cannot skip a check written for `/admin`. Updated by `rewrite()`.
|
|
59
|
-
*/
|
|
60
|
-
readonly routePathname: string;
|
|
61
54
|
searchParams: URLSearchParams;
|
|
62
55
|
method: string;
|
|
63
56
|
params: Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,KA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,EAAE,iBAAiB,EAAE,CAAA;SAAE,CAAC;QAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;IAC7F,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAuKD;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CAoUlF;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/middleware/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { _withAfterNodeMiddleware } from "@farm.js/core/after";
|
|
4
4
|
import { devServableFileExists } from "../dev-static.js";
|
|
5
5
|
import { resolveDevRequestURL, resolveViteHtmlFallbackUrl } from "../dev-request.js";
|
|
6
|
-
import {
|
|
6
|
+
import { matchesMiddlewareConfig } from "@farm.js/core/middleware";
|
|
7
7
|
import { middlewareMatchesPath, parseCookies, serializeCookie } from "./matching.js";
|
|
8
8
|
// Create require for ESM compatibility
|
|
9
9
|
const require_ = createRequire(import.meta.url);
|
|
@@ -37,27 +37,24 @@ const getColors = () => {
|
|
|
37
37
|
*/
|
|
38
38
|
function createCookieJar(req, res) {
|
|
39
39
|
const cookies = parseCookies(req.headers.cookie);
|
|
40
|
-
|
|
41
|
-
const existing = res.getHeader("Set-Cookie");
|
|
42
|
-
const setCookies = Array.isArray(existing)
|
|
43
|
-
? existing.map(String)
|
|
44
|
-
: existing === undefined
|
|
45
|
-
? []
|
|
46
|
-
: [String(existing)];
|
|
40
|
+
const setCookies = [];
|
|
47
41
|
return {
|
|
48
42
|
get(name) {
|
|
49
43
|
return cookies[name];
|
|
50
44
|
},
|
|
51
45
|
set(name, value, options = {}) {
|
|
52
46
|
cookies[name] = value;
|
|
53
|
-
|
|
47
|
+
const cookieString = serializeCookie(name, value, options);
|
|
48
|
+
setCookies.push(cookieString);
|
|
54
49
|
res.setHeader("Set-Cookie", setCookies);
|
|
55
50
|
},
|
|
56
|
-
delete(name
|
|
51
|
+
delete(name) {
|
|
57
52
|
delete cookies[name];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
const cookieString = serializeCookie(name, "", {
|
|
54
|
+
maxAge: 0,
|
|
55
|
+
expires: new Date(0),
|
|
56
|
+
});
|
|
57
|
+
setCookies.push(cookieString);
|
|
61
58
|
res.setHeader("Set-Cookie", setCookies);
|
|
62
59
|
},
|
|
63
60
|
getAll() {
|
|
@@ -94,8 +91,6 @@ function createContext(req, res, viteServer) {
|
|
|
94
91
|
response: res,
|
|
95
92
|
url,
|
|
96
93
|
pathname: url.pathname,
|
|
97
|
-
// Vite has already removed its base from the URL, so this is the app's path.
|
|
98
|
-
routePathname: canonicalizeRequestPathname(url.pathname),
|
|
99
94
|
searchParams: url.searchParams,
|
|
100
95
|
method: req.method || "GET",
|
|
101
96
|
params: {},
|
|
@@ -130,7 +125,6 @@ function createContext(req, res, viteServer) {
|
|
|
130
125
|
const newUrl = new URL(rewriteUrl, `http://${req.headers.host || "localhost"}`);
|
|
131
126
|
ctx.url = newUrl;
|
|
132
127
|
ctx.pathname = newUrl.pathname;
|
|
133
|
-
ctx.routePathname = canonicalizeRequestPathname(newUrl.pathname);
|
|
134
128
|
ctx.searchParams = newUrl.searchParams;
|
|
135
129
|
// Update the original request URL
|
|
136
130
|
req.url = rewriteUrl;
|
|
@@ -6,8 +6,7 @@ import type { CookieOptions } from "./index.js";
|
|
|
6
6
|
* (a latin-1 value from an old link, a crawler, or a bare `%`) must not take
|
|
7
7
|
* the whole map down: an unguarded `decodeURIComponent` throws `URIError`,
|
|
8
8
|
* which fails the request before any middleware runs. Decoding falls back to
|
|
9
|
-
* the raw value per entry instead.
|
|
10
|
-
* agree on which duplicate wins.
|
|
9
|
+
* the raw value per entry instead.
|
|
11
10
|
*/
|
|
12
11
|
export declare function parseCookies(cookieHeader?: string): Record<string, string>;
|
|
13
12
|
/**
|
|
@@ -29,8 +28,7 @@ export declare function middlewareMatchesPath(pathname: string, middlewarePath:
|
|
|
29
28
|
*
|
|
30
29
|
* `Max-Age=0` is the canonical immediate-expiry directive, so the attribute is
|
|
31
30
|
* emitted whenever `maxAge` is provided — a `0` must not be dropped the way a
|
|
32
|
-
* plain truthiness check would drop it.
|
|
33
|
-
* Set-Cookie carries the attributes a browser requires, as production does.
|
|
31
|
+
* plain truthiness check would drop it.
|
|
34
32
|
*/
|
|
35
33
|
export declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|
|
36
34
|
//# sourceMappingURL=matching.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"matching.d.ts","sourceRoot":"","sources":["../../src/middleware/matching.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1E;AAUD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAkChG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { canonicalizeRequestPathSegments
|
|
1
|
+
import { canonicalizeRequestPathSegments } from "@farm.js/core/middleware";
|
|
2
2
|
/**
|
|
3
3
|
* Parse cookies from a Cookie header.
|
|
4
4
|
*
|
|
@@ -6,11 +6,27 @@ import { canonicalizeRequestPathSegments, parseMiddlewareCookieHeader, serialize
|
|
|
6
6
|
* (a latin-1 value from an old link, a crawler, or a bare `%`) must not take
|
|
7
7
|
* the whole map down: an unguarded `decodeURIComponent` throws `URIError`,
|
|
8
8
|
* which fails the request before any middleware runs. Decoding falls back to
|
|
9
|
-
* the raw value per entry instead.
|
|
10
|
-
* agree on which duplicate wins.
|
|
9
|
+
* the raw value per entry instead.
|
|
11
10
|
*/
|
|
12
11
|
export function parseCookies(cookieHeader) {
|
|
13
|
-
|
|
12
|
+
if (!cookieHeader)
|
|
13
|
+
return {};
|
|
14
|
+
return cookieHeader.split(";").reduce((cookies, cookie) => {
|
|
15
|
+
const [name, ...rest] = cookie.split("=");
|
|
16
|
+
const value = rest.join("=").trim();
|
|
17
|
+
if (name && value) {
|
|
18
|
+
cookies[name.trim()] = decodeCookieValue(value);
|
|
19
|
+
}
|
|
20
|
+
return cookies;
|
|
21
|
+
}, {});
|
|
22
|
+
}
|
|
23
|
+
function decodeCookieValue(value) {
|
|
24
|
+
try {
|
|
25
|
+
return decodeURIComponent(value);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
14
30
|
}
|
|
15
31
|
/**
|
|
16
32
|
* Whether a middleware registered at `middlewarePath` applies to `pathname`.
|
|
@@ -39,9 +55,33 @@ export function middlewareMatchesPath(pathname, middlewarePath) {
|
|
|
39
55
|
*
|
|
40
56
|
* `Max-Age=0` is the canonical immediate-expiry directive, so the attribute is
|
|
41
57
|
* emitted whenever `maxAge` is provided — a `0` must not be dropped the way a
|
|
42
|
-
* plain truthiness check would drop it.
|
|
43
|
-
* Set-Cookie carries the attributes a browser requires, as production does.
|
|
58
|
+
* plain truthiness check would drop it.
|
|
44
59
|
*/
|
|
45
60
|
export function serializeCookie(name, value, options = {}) {
|
|
46
|
-
|
|
61
|
+
let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
62
|
+
if (options.maxAge != null) {
|
|
63
|
+
cookie += `; Max-Age=${options.maxAge}`;
|
|
64
|
+
}
|
|
65
|
+
if (options.expires) {
|
|
66
|
+
cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
67
|
+
}
|
|
68
|
+
if (options.path) {
|
|
69
|
+
cookie += `; Path=${options.path}`;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
cookie += "; Path=/";
|
|
73
|
+
}
|
|
74
|
+
if (options.domain) {
|
|
75
|
+
cookie += `; Domain=${options.domain}`;
|
|
76
|
+
}
|
|
77
|
+
if (options.secure) {
|
|
78
|
+
cookie += "; Secure";
|
|
79
|
+
}
|
|
80
|
+
if (options.httpOnly) {
|
|
81
|
+
cookie += "; HttpOnly";
|
|
82
|
+
}
|
|
83
|
+
if (options.sameSite) {
|
|
84
|
+
cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1)}`;
|
|
85
|
+
}
|
|
86
|
+
return cookie;
|
|
47
87
|
}
|
|
@@ -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;
|
|
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;AAEhD,eAAO,MAAM,mCAAmC,62BA6B9C,CAAC;AAEH;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAyT7D"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { generateMobileShellNavigation } from "../mobile-client.js";
|
|
2
1
|
export const serverFnTransportErrorClientRuntime = `function createFarmServerFnTransportError(value) {
|
|
3
2
|
const message = value && typeof value === 'object' && typeof value.message === 'string'
|
|
4
3
|
? value.message
|
|
@@ -61,15 +60,10 @@ import {
|
|
|
61
60
|
createFarmDeploymentRequestHeaders,
|
|
62
61
|
isFarmDeploymentMismatchResponse,
|
|
63
62
|
} from '@farm.js/core/deployment';
|
|
64
|
-
import { runFarmNavigationDelegates } from '@farm.js/core/internal/client-runtime';
|
|
65
63
|
`;
|
|
66
|
-
// farm dev --mobile: every page runs in the shell's WebView, so this entry is the mobile client.
|
|
67
|
-
if (ctx.mobileClient === "inline") {
|
|
68
|
-
imports += generateMobileShellNavigation();
|
|
69
|
-
}
|
|
70
64
|
if (ctx.actionsEnabled) {
|
|
71
65
|
imports += `import { setServerCallback, encodeReply, createTemporaryReferenceSet } from '@vitejs/plugin-rsc/browser';
|
|
72
|
-
import { applyFarmCacheInvalidations } from '@farm.js/core/
|
|
66
|
+
import { applyFarmCacheInvalidations } from '@farm.js/core/cache';
|
|
73
67
|
import {
|
|
74
68
|
beginFarmServerQueryAction,
|
|
75
69
|
completeFarmServerQueryAction,
|
|
@@ -143,7 +137,8 @@ setServerCallback(async (id, args) => {
|
|
|
143
137
|
// router performs the navigation here.
|
|
144
138
|
if (p.returnValue?.redirect?.url) {
|
|
145
139
|
debug('Server action redirected:', p.returnValue.redirect.url);
|
|
146
|
-
|
|
140
|
+
history.pushState(null, '', p.returnValue.redirect.url);
|
|
141
|
+
await farmNavigateRef.current?.(location.href);
|
|
147
142
|
return;
|
|
148
143
|
}
|
|
149
144
|
debug('Server action failed:', id);
|
|
@@ -176,44 +171,15 @@ function debug(...args) {
|
|
|
176
171
|
${debugLog}
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
// A server component that fails while a client navigation renders it: a redirect() becomes a
|
|
180
|
-
// client navigation to its target, and anything else loads the URL as a document, so the server
|
|
181
|
-
// answers with its status and error.tsx. Errors in the first render are left to React.
|
|
182
|
-
class FarmNavigationErrorBoundary extends React.Component {
|
|
183
|
-
constructor(props) {
|
|
184
|
-
super(props);
|
|
185
|
-
this.state = { error: null, payload: props.payload };
|
|
186
|
-
}
|
|
187
|
-
static getDerivedStateFromProps(props, state) {
|
|
188
|
-
return props.payload === state.payload ? null : { error: null, payload: props.payload };
|
|
189
|
-
}
|
|
190
|
-
static getDerivedStateFromError(error) {
|
|
191
|
-
return { error };
|
|
192
|
-
}
|
|
193
|
-
componentDidCatch(error) {
|
|
194
|
-
const digest = error && typeof error.digest === 'string' ? error.digest : '';
|
|
195
|
-
if (digest.startsWith('FARM_REDIRECT;')) {
|
|
196
|
-
farmNavigateRef.current?.(digest.split(';').slice(2).join(';'), 'replace');
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
location.reload();
|
|
200
|
-
}
|
|
201
|
-
render() {
|
|
202
|
-
if (this.state.error && !this.props.navigated) throw this.state.error;
|
|
203
|
-
return this.state.error ? null : this.props.children;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
174
|
async function main() {
|
|
208
175
|
// Prevent double execution (e.g. script loaded twice)
|
|
209
176
|
if (globalThis.__FARM_RSC_HYDRATED) return;
|
|
210
177
|
|
|
211
178
|
debug('Starting client hydration');
|
|
212
179
|
|
|
213
|
-
// Clean duplicate DOM as early as possible (server may have sent two blocks)
|
|
214
|
-
// wrapper: an app that owns the document can have an element with id="root" in its content.
|
|
180
|
+
// Clean duplicate DOM as early as possible (server may have sent two blocks)
|
|
215
181
|
const rootEl = document.getElementById('root');
|
|
216
|
-
if (rootEl
|
|
182
|
+
if (rootEl) {
|
|
217
183
|
while (rootEl.children.length > 1) rootEl.lastElementChild.remove();
|
|
218
184
|
while (rootEl.nextElementSibling) rootEl.nextElementSibling.remove();
|
|
219
185
|
}
|
|
@@ -285,8 +251,8 @@ async function main() {
|
|
|
285
251
|
}
|
|
286
252
|
|
|
287
253
|
e.preventDefault();
|
|
288
|
-
|
|
289
|
-
|
|
254
|
+
history.pushState(null, '', a.href);
|
|
255
|
+
nav();
|
|
290
256
|
}
|
|
291
257
|
};
|
|
292
258
|
|
|
@@ -305,46 +271,17 @@ async function main() {
|
|
|
305
271
|
if (payload.root != null) console.warn('[Farm.js] payload.rootContent missing; not using payload.root to avoid duplicate block. Keys:', Object.keys(payload));
|
|
306
272
|
return null;
|
|
307
273
|
}
|
|
308
|
-
return
|
|
309
|
-
FarmNavigationErrorBoundary,
|
|
310
|
-
{ payload, navigated: payload !== initial },
|
|
311
|
-
content,
|
|
312
|
-
);
|
|
274
|
+
return content;
|
|
313
275
|
}
|
|
314
276
|
|
|
315
|
-
// An in-app navigation (a link click, a redirect after a server action). Navigation delegates
|
|
316
|
-
// get it first, after the router's own checks, as Farm's other routers offer it: one that takes
|
|
317
|
-
// it (a native shell showing the URL on its own screen) leaves the page and URL as they are.
|
|
318
|
-
// Back/forward, refreshes and same-page moves are not offered; other origins load as documents.
|
|
319
|
-
async function navigate(href, action) {
|
|
320
|
-
const url = new URL(href, location.href);
|
|
321
|
-
if (url.origin !== location.origin) {
|
|
322
|
-
location.assign(url.href);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const from = location.pathname + location.search;
|
|
326
|
-
const to = url.pathname + url.search;
|
|
327
|
-
if (to !== from && (await runFarmNavigationDelegates({ url: url.href, from, to, action }))) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
if (action === 'replace') history.replaceState(null, '', url.href);
|
|
331
|
-
else history.pushState(null, '', url.href);
|
|
332
|
-
await refetch(location.href);
|
|
333
|
-
}
|
|
334
|
-
farmNavigateRef.current = navigate;
|
|
335
|
-
|
|
336
277
|
// Fetch new RSC payload for a URL
|
|
278
|
+
farmNavigateRef.current = (url) => refetch(url);
|
|
337
279
|
async function refetch(url) {
|
|
338
280
|
debug('Fetching RSC for:', url);
|
|
339
281
|
|
|
340
282
|
try {
|
|
341
|
-
// Request
|
|
342
|
-
|
|
343
|
-
const payloadUrl = new URL(url, location.href);
|
|
344
|
-
payloadUrl.pathname = payloadUrl.pathname.endsWith('/')
|
|
345
|
-
? payloadUrl.pathname + 'index.rsc'
|
|
346
|
-
: payloadUrl.pathname + '.rsc';
|
|
347
|
-
const res = await fetch(payloadUrl, {
|
|
283
|
+
// Request RSC format instead of HTML
|
|
284
|
+
const res = await fetch(url, {
|
|
348
285
|
headers: createFarmDeploymentRequestHeaders(farmDeploymentId, {
|
|
349
286
|
Accept: 'text/x-component',
|
|
350
287
|
}),
|
|
@@ -368,10 +305,6 @@ async function main() {
|
|
|
368
305
|
// reflect the page actually rendered (auth gates redirect this way).
|
|
369
306
|
if (res.redirected && res.url) {
|
|
370
307
|
const dest = new URL(res.url);
|
|
371
|
-
if (dest.pathname.endsWith('.rsc')) {
|
|
372
|
-
const page = dest.pathname.slice(0, -'.rsc'.length);
|
|
373
|
-
dest.pathname = page.endsWith('/index') ? page.slice(0, -'index'.length) : page;
|
|
374
|
-
}
|
|
375
308
|
if (dest.origin === location.origin) {
|
|
376
309
|
const target = dest.pathname + dest.search + dest.hash;
|
|
377
310
|
if (target !== location.pathname + location.search + location.hash) {
|
|
@@ -388,17 +321,14 @@ async function main() {
|
|
|
388
321
|
location.href = url;
|
|
389
322
|
}
|
|
390
323
|
}
|
|
391
|
-
|
|
392
|
-
const rootElForHydrate = initial.ownsDocument ? document : document.getElementById('root');
|
|
324
|
+
const rootElForHydrate = document.getElementById('root');
|
|
393
325
|
if (!rootElForHydrate) {
|
|
394
326
|
console.error('[Farm.js] #root element not found');
|
|
395
327
|
return;
|
|
396
328
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
while (rootElForHydrate.nextElementSibling) rootElForHydrate.nextElementSibling.remove();
|
|
401
|
-
}
|
|
329
|
+
// Final cleanup pass before hydrate (in case DOM changed during async)
|
|
330
|
+
while (rootElForHydrate.children.length > 1) rootElForHydrate.lastElementChild.remove();
|
|
331
|
+
while (rootElForHydrate.nextElementSibling) rootElForHydrate.nextElementSibling.remove();
|
|
402
332
|
debug('Hydrating application');
|
|
403
333
|
globalThis.__FARM_RSC_HYDRATED = true;
|
|
404
334
|
hydrateRoot(rootElForHydrate, React.createElement(BrowserRoot), {
|
|
@@ -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":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,mCAAmC,IAAI,MAAM,CAe5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAy+B1D"}
|