expo-router 4.0.15 → 4.0.17
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/babel.js +17 -3
- package/build/fast-refresh.d.ts.map +1 -1
- package/build/fast-refresh.js +21 -13
- package/build/fast-refresh.js.map +1 -1
- package/build/loadStaticParamsAsync.d.ts +5 -0
- package/build/loadStaticParamsAsync.d.ts.map +1 -1
- package/build/loadStaticParamsAsync.js +16 -8
- package/build/loadStaticParamsAsync.js.map +1 -1
- package/build/rsc/middleware.js +1 -0
- package/build/rsc/middleware.js.map +1 -1
- package/build/rsc/router/create-pages.d.ts +3 -1
- package/build/rsc/router/create-pages.d.ts.map +1 -1
- package/build/rsc/router/create-pages.js +1 -1
- package/build/rsc/router/create-pages.js.map +1 -1
- package/build/rsc/router/errors.d.ts +5 -1
- package/build/rsc/router/errors.d.ts.map +1 -1
- package/build/rsc/router/errors.js +5 -1
- package/build/rsc/router/errors.js.map +1 -1
- package/build/rsc/router/expo-definedRouter.d.ts.map +1 -1
- package/build/rsc/router/expo-definedRouter.js +82 -15
- package/build/rsc/router/expo-definedRouter.js.map +1 -1
- package/build/rsc/router/host.d.ts.map +1 -1
- package/build/rsc/router/host.js +15 -5
- package/build/rsc/router/host.js.map +1 -1
- package/build/rsc/server.d.ts +1 -1
- package/build/rsc/server.d.ts.map +1 -1
- package/build/rsc/server.js +18 -34
- package/build/rsc/server.js.map +1 -1
- package/build/static/getServerManifest.d.ts +5 -0
- package/build/static/getServerManifest.d.ts.map +1 -1
- package/build/static/getServerManifest.js +17 -1
- package/build/static/getServerManifest.js.map +1 -1
- package/build/static/renderStaticContent.d.ts +1 -8
- package/build/static/renderStaticContent.d.ts.map +1 -1
- package/build/static/renderStaticContent.js +3 -19
- package/build/static/renderStaticContent.js.map +1 -1
- package/build/views/ErrorBoundary.d.ts.map +1 -1
- package/build/views/ErrorBoundary.js +93 -15
- package/build/views/ErrorBoundary.js.map +1 -1
- package/package.json +4 -4
|
@@ -3,8 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const _ctx_1 = require("expo-router/_ctx");
|
|
4
4
|
const create_pages_1 = require("./create-pages");
|
|
5
5
|
const getRoutesSSR_1 = require("../../getRoutesSSR");
|
|
6
|
+
const loadStaticParamsAsync_1 = require("../../loadStaticParamsAsync");
|
|
6
7
|
const matchers_1 = require("../../matchers");
|
|
7
8
|
const sortRoutes_1 = require("../../sortRoutes");
|
|
9
|
+
const UNIMPLEMENTED_PARAMS = new Proxy({}, {
|
|
10
|
+
// Assert that params is unimplemented when accessed.
|
|
11
|
+
get() {
|
|
12
|
+
throw new Error('generateStaticParams(): params is not implemented yet');
|
|
13
|
+
},
|
|
14
|
+
});
|
|
8
15
|
exports.default = (0, create_pages_1.createPages)(async ({ createPage, createLayout, unstable_setBuildData }) => {
|
|
9
16
|
const routes = (0, getRoutesSSR_1.getRoutes)(_ctx_1.ctx, {
|
|
10
17
|
platform: process.env.EXPO_OS,
|
|
@@ -13,32 +20,92 @@ exports.default = (0, create_pages_1.createPages)(async ({ createPage, createLay
|
|
|
13
20
|
});
|
|
14
21
|
if (!routes)
|
|
15
22
|
return;
|
|
16
|
-
function
|
|
23
|
+
async function loadAndConvertStaticParamsAsync(route) {
|
|
24
|
+
const loaded = route.loadRoute();
|
|
25
|
+
let staticPaths = undefined;
|
|
26
|
+
if (route.dynamic) {
|
|
27
|
+
const params = await (0, loadStaticParamsAsync_1.evalStaticParamsAsync)(route, { parentParams: UNIMPLEMENTED_PARAMS }, loaded.generateStaticParams);
|
|
28
|
+
// Sort `params` like `[{a: 'x', b: 'y'}, { a: 'z', b: 'w' }]` for a route.dynamic like `[{name: 'a', deep: false}, {name: 'b', deep: false}]` to `[['a', 'y'], ['z', 'w]]`
|
|
29
|
+
staticPaths = params?.map((p) => {
|
|
30
|
+
const grouped = [];
|
|
31
|
+
for (const dynamic of route.dynamic) {
|
|
32
|
+
const defined = p[dynamic.name];
|
|
33
|
+
if (!defined) {
|
|
34
|
+
throw new Error('generateStaticParams is missing param: ' +
|
|
35
|
+
dynamic.name +
|
|
36
|
+
'. In route: ' +
|
|
37
|
+
route.contextKey);
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(defined)) {
|
|
40
|
+
if (defined.length > 1) {
|
|
41
|
+
throw new Error('generateStaticParams does not support returning multiple static paths for deep dynamic routes in React Server Components yet. Update route: ' +
|
|
42
|
+
route.contextKey);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const first = Array.isArray(defined) ? defined[0] : defined;
|
|
46
|
+
grouped.push(first);
|
|
47
|
+
}
|
|
48
|
+
return grouped;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (loaded.generateStaticParams) {
|
|
52
|
+
throw new Error('Cannot use generateStaticParams without a dynamic route: ' + route.contextKey);
|
|
53
|
+
}
|
|
54
|
+
return staticPaths;
|
|
55
|
+
}
|
|
56
|
+
async function addLayout(route) {
|
|
17
57
|
const normal = (0, matchers_1.getContextKey)(route.contextKey).replace(/\/index$/, '');
|
|
58
|
+
const loaded = route.loadRoute();
|
|
59
|
+
if (loaded.generateStaticParams) {
|
|
60
|
+
throw new Error('generateStaticParams is not supported in _layout routes with React Server Components enabled yet.');
|
|
61
|
+
}
|
|
18
62
|
createLayout({
|
|
19
63
|
// NOTE(EvanBacon): Support routes with top-level "use client"
|
|
20
|
-
component:
|
|
64
|
+
component: loaded.default,
|
|
21
65
|
path: normal,
|
|
22
|
-
// staticPaths
|
|
23
66
|
render: 'static',
|
|
24
|
-
...
|
|
67
|
+
...loaded.unstable_settings,
|
|
25
68
|
});
|
|
26
|
-
route.children.sort(sortRoutes_1.sortRoutes).
|
|
69
|
+
await Promise.all(route.children.sort(sortRoutes_1.sortRoutes).map(async (child) => {
|
|
27
70
|
if (child.type === 'layout') {
|
|
28
|
-
addLayout(child);
|
|
71
|
+
await addLayout(child);
|
|
29
72
|
}
|
|
30
73
|
else {
|
|
31
74
|
const normal = (0, matchers_1.getContextKey)(child.contextKey).replace(/\/index$/, '');
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
75
|
+
const loaded = child.loadRoute();
|
|
76
|
+
const settings = loaded.unstable_settings;
|
|
77
|
+
// Support generateStaticParams for dynamic routes by defining the route twice.
|
|
78
|
+
if (loaded.generateStaticParams) {
|
|
79
|
+
createPage({
|
|
80
|
+
// NOTE(EvanBacon): Support routes with top-level "use client"
|
|
81
|
+
component: loaded.default,
|
|
82
|
+
path: normal,
|
|
83
|
+
render: 'static',
|
|
84
|
+
...loaded.unstable_settings,
|
|
85
|
+
staticPaths: (await loadAndConvertStaticParamsAsync(child)),
|
|
86
|
+
});
|
|
87
|
+
if (settings?.render !== 'static') {
|
|
88
|
+
createPage({
|
|
89
|
+
// NOTE(EvanBacon): Support routes with top-level "use client"
|
|
90
|
+
component: loaded.default,
|
|
91
|
+
path: normal,
|
|
92
|
+
render: 'dynamic',
|
|
93
|
+
...settings,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
createPage({
|
|
99
|
+
// NOTE(EvanBacon): Support routes with top-level "use client"
|
|
100
|
+
component: loaded.default,
|
|
101
|
+
path: normal,
|
|
102
|
+
render: 'dynamic',
|
|
103
|
+
...settings,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
39
106
|
}
|
|
40
|
-
});
|
|
107
|
+
}));
|
|
41
108
|
}
|
|
42
|
-
addLayout(routes);
|
|
109
|
+
await addLayout(routes);
|
|
43
110
|
});
|
|
44
111
|
//# sourceMappingURL=expo-definedRouter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo-definedRouter.js","sourceRoot":"","sources":["../../../src/rsc/router/expo-definedRouter.ts"],"names":[],"mappings":";;AAAA,2CAAuC;AAEvC,iDAA6C;AAE7C,qDAA+C;AAC/C,6CAA+C;AAC/C,iD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AAM,EAAE,SAAS;4BACjB,GAAG,QAAQ;yBACZ,CAAC,CAAC;qBACJ;iBACF;qBAAM;oBACL,UAAU,CAAC;wBACT,8DAA8D;wBAC9D,SAAS,EAAE,MAAM,CAAC,OAAc;wBAChC,IAAI,EAAE,MAAa;wBACnB,MAAM,EAAE,SAAS;wBACjB,GAAG,QAAQ;qBACZ,CAAC,CAAC;iBACJ;aACF;QACH,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;AAC1B,CAAC,CAAC,CAAC","sourcesContent":["import { ctx } from 'expo-router/_ctx';\n\nimport { createPages } from './create-pages';\nimport type { RouteNode } from '../../Route';\nimport { getRoutes } from '../../getRoutesSSR';\nimport { evalStaticParamsAsync } from '../../loadStaticParamsAsync';\nimport { getContextKey } from '../../matchers';\nimport { sortRoutes } from '../../sortRoutes';\n\nconst UNIMPLEMENTED_PARAMS = new Proxy(\n {},\n {\n // Assert that params is unimplemented when accessed.\n get() {\n throw new Error('generateStaticParams(): params is not implemented yet');\n },\n }\n);\n\nexport default createPages(async ({ createPage, createLayout, unstable_setBuildData }) => {\n const routes = getRoutes(ctx, {\n platform: process.env.EXPO_OS,\n skipGenerated: true,\n importMode: 'lazy',\n });\n\n if (!routes) return;\n\n async function loadAndConvertStaticParamsAsync(route: RouteNode) {\n const loaded = route.loadRoute();\n\n let staticPaths: string[][] | undefined = undefined;\n\n if (route.dynamic) {\n const params = await evalStaticParamsAsync(\n route,\n { parentParams: UNIMPLEMENTED_PARAMS },\n loaded.generateStaticParams\n );\n\n // Sort `params` like `[{a: 'x', b: 'y'}, { a: 'z', b: 'w' }]` for a route.dynamic like `[{name: 'a', deep: false}, {name: 'b', deep: false}]` to `[['a', 'y'], ['z', 'w]]`\n staticPaths = params?.map((p) => {\n const grouped: string[] = [];\n\n for (const dynamic of route.dynamic!) {\n const defined = p[dynamic.name];\n if (!defined) {\n throw new Error(\n 'generateStaticParams is missing param: ' +\n dynamic.name +\n '. In route: ' +\n route.contextKey\n );\n }\n if (Array.isArray(defined)) {\n if (defined.length > 1) {\n throw new Error(\n 'generateStaticParams does not support returning multiple static paths for deep dynamic routes in React Server Components yet. Update route: ' +\n route.contextKey\n );\n }\n }\n\n const first = Array.isArray(defined) ? defined[0] : defined;\n\n grouped.push(first);\n }\n return grouped;\n });\n } else if (loaded.generateStaticParams) {\n throw new Error(\n 'Cannot use generateStaticParams without a dynamic route: ' + route.contextKey\n );\n }\n return staticPaths;\n }\n async function addLayout(route: RouteNode) {\n const normal = getContextKey(route.contextKey).replace(/\\/index$/, '');\n\n const loaded = route.loadRoute();\n\n if (loaded.generateStaticParams) {\n throw new Error(\n 'generateStaticParams is not supported in _layout routes with React Server Components enabled yet.'\n );\n }\n\n createLayout({\n // NOTE(EvanBacon): Support routes with top-level \"use client\"\n component: loaded.default! as any,\n path: normal as any,\n render: 'static',\n ...loaded.unstable_settings,\n });\n\n await Promise.all(\n route.children.sort(sortRoutes).map(async (child) => {\n if (child.type === 'layout') {\n await addLayout(child);\n } else {\n const normal = getContextKey(child.contextKey).replace(/\\/index$/, '');\n const loaded = child.loadRoute();\n const settings = loaded.unstable_settings;\n\n // Support generateStaticParams for dynamic routes by defining the route twice.\n if (loaded.generateStaticParams) {\n createPage({\n // NOTE(EvanBacon): Support routes with top-level \"use client\"\n component: loaded.default as any,\n path: normal as any,\n render: 'static',\n ...loaded.unstable_settings,\n staticPaths: (await loadAndConvertStaticParamsAsync(child)) as any,\n });\n\n if (settings?.render !== 'static') {\n createPage({\n // NOTE(EvanBacon): Support routes with top-level \"use client\"\n component: loaded.default as any,\n path: normal as any,\n render: 'dynamic',\n ...settings,\n });\n }\n } else {\n createPage({\n // NOTE(EvanBacon): Support routes with top-level \"use client\"\n component: loaded.default as any,\n path: normal as any,\n render: 'dynamic',\n ...settings,\n });\n }\n }\n })\n );\n }\n\n await addLayout(routes);\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/host.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../../src/rsc/router/host.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAgBH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAgDvC,KAAK,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;AAC3C,KAAK,WAAW,GAAG,CAAC,OAAO,EAAE,QAAQ,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,QAAQ,CAAC,KAAK,IAAI,CAAC;AAIhF,QAAA,MAAM,KAAK,MAAM,CAAC;AAClB,QAAA,MAAM,YAAY,MAAM,CAAC;AACzB,QAAA,MAAM,aAAa,MAAM,CAAC;AAE1B,KAAK,UAAU,GAAG;IAChB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC,YAAY,CAAC,CAAC,EAAE,WAAW,CAAC;IAC7B,CAAC,aAAa,CAAC,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAC3C,CAAC;AA4DF,KAAK,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,GAAG;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC;CAC9C,CAAC;AAmCF;;;GAGG;AACH,eAAO,MAAM,aAAa,aACd,MAAM,SACT,OAAO,EAAE,gDAmBjB,CAAC;AAyBF,eAAO,MAAM,QAAQ,UACZ,MAAM,WACJ,OAAO,8BAEf,QA0CF,CAAC;AAqBF,eAAO,MAAM,WAAW,UAAW,MAAM,WAAW,OAAO,KAAG,IAQ7D,CAAC;AASF,eAAO,MAAM,IAAI;;oBASC,OAAO;;mCAEO,OAAO,KAAK,IAAI;cACpC,SAAS;qFAnBwB,MAAM,iBAAiB,eAAe,KAAK,IAAI,EA4C3F,CAAC;AAEF,eAAO,MAAM,UAAU,WAA4B,CAAC;AAKpD,eAAO,MAAM,IAAI;QAKX,MAAM;eACC,SAAS;eACT,SAAS;gOAcrB,CAAC;AAEF,eAAO,MAAM,QAAQ,WAA6B,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,UAAU;cAAwC,QAAQ;cAAY,SAAS;8FACpB,CAAC"}
|
package/build/rsc/router/host.js
CHANGED
|
@@ -41,6 +41,11 @@ if (!BASE_PATH.endsWith('/')) {
|
|
|
41
41
|
if (BASE_PATH === '/') {
|
|
42
42
|
throw new Error(`Invalid React Flight path "${BASE_PATH}". The path should not live at the project root, e.g. /_flight/. Dev server URL: ${(0, getDevServer_1.getDevServer)().fullBundleUrl}`);
|
|
43
43
|
}
|
|
44
|
+
if (process.env.EXPO_OS !== 'web' && !window.location?.href) {
|
|
45
|
+
// This can happen if the user attempts to use React Server Components without
|
|
46
|
+
// enabling the flags in the app.json. This will set origin to false and prevent the expo/metro-runtime polyfill from running.
|
|
47
|
+
throw new Error('window.location.href is not defined. This is required for React Server Components to work correctly. Ensure React Server Components is correctly enabled in your project and config.');
|
|
48
|
+
}
|
|
44
49
|
const RSC_CONTENT_TYPE = 'text/x-component';
|
|
45
50
|
const ENTRY = 'e';
|
|
46
51
|
const SET_ELEMENTS = 's';
|
|
@@ -65,16 +70,21 @@ const checkStatus = async (responsePromise) => {
|
|
|
65
70
|
if (!response.ok) {
|
|
66
71
|
// NOTE(EvanBacon): Transform the Metro development error into a JS error that can be used by LogBox.
|
|
67
72
|
// This was tested against using a Class component in a server component.
|
|
68
|
-
if (response.status === 500) {
|
|
73
|
+
if (__DEV__ && (response.status === 500 || response.status === 404)) {
|
|
69
74
|
const errorText = await response.text();
|
|
70
75
|
let errorJson;
|
|
71
76
|
try {
|
|
72
77
|
errorJson = JSON.parse(errorText);
|
|
73
78
|
}
|
|
74
79
|
catch {
|
|
75
|
-
|
|
80
|
+
// `Unable to resolve module` error should respond as JSON from the dev server and sent to the master red box, this can get corrupt when it's returned as the formatted string.
|
|
81
|
+
if (errorText.startsWith('Unable to resolve module')) {
|
|
82
|
+
console.error('Unexpected Metro error format from dev server');
|
|
83
|
+
// This is an unexpected state that occurs when the dev server renderer does not throw Metro errors in the expected JSON format.
|
|
84
|
+
throw new Error(errorJson);
|
|
85
|
+
}
|
|
86
|
+
throw new errors_1.ReactServerError(errorText, response.url, response.status, response.headers);
|
|
76
87
|
}
|
|
77
|
-
// TODO: This should be a dev-only error. Add handling for production equivalent.
|
|
78
88
|
throw new errors_1.MetroServerError(errorJson, response.url);
|
|
79
89
|
}
|
|
80
90
|
let responseText;
|
|
@@ -82,9 +92,9 @@ const checkStatus = async (responsePromise) => {
|
|
|
82
92
|
responseText = await response.text();
|
|
83
93
|
}
|
|
84
94
|
catch {
|
|
85
|
-
throw new errors_1.ReactServerError(response.statusText, response.url, response.status);
|
|
95
|
+
throw new errors_1.ReactServerError(response.statusText, response.url, response.status, response.headers);
|
|
86
96
|
}
|
|
87
|
-
throw new errors_1.ReactServerError(responseText, response.url, response.status);
|
|
97
|
+
throw new errors_1.ReactServerError(responseText, response.url, response.status, response.headers);
|
|
88
98
|
}
|
|
89
99
|
return response;
|
|
90
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../../src/rsc/router/host.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,uCAAuC;AACvC,YAAY,CAAC;;;;;;;AAEb,iCAUe;AAEf,6EAAyD;AAEzD,qCAA8D;AAC9D,mCAAgC;AAChC,mCAAsD;AACtD,qDAAkD;AAClD,wCAAwD;AAExD,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,gBAA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IAAA,WAAG,EAAC,eAAe,CAAC,CAAC;AAAtC,QAAA,QAAQ,YAA8B;AAEnD;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAA+C,EAAE,EAAE,CAChG,IAAA,qBAAa,EAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;AAD5D,QAAA,UAAU,cACkD","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n * Copyright © 2024 2023 Daishi Kato\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/client.ts#L1\n */\n\n//// <reference types=\"react/canary\" />\n'use client';\n\nimport {\n createContext,\n createElement,\n memo,\n useCallback,\n useState,\n startTransition,\n // @ts-expect-error\n use,\n useEffect,\n} from 'react';\nimport type { ReactNode } from 'react';\nimport RSDWClient from 'react-server-dom-webpack/client';\n\nimport { MetroServerError, ReactServerError } from './errors';\nimport { fetch } from './fetch';\nimport { encodeInput, encodeActionId } from './utils';\nimport { getDevServer } from '../../getDevServer';\nimport { getOriginFromConstants } from '../../head/url';\n\nconst { createFromFetch, encodeReply } = RSDWClient;\n\n// TODO: Maybe this could be a bundler global instead.\nconst IS_DOM =\n // @ts-expect-error: Added via react-native-webview\n typeof ReactNativeWebView !== 'undefined';\n\n// NOTE: Ensured to start with `/`.\nconst RSC_PATH = '/_flight/' + process.env.EXPO_OS; // process.env.EXPO_RSC_PATH;\n\n// Using base URL for remote hosts isn't currently supported in DOM components as we use it for offline assets.\nconst BASE_URL = IS_DOM ? '' : process.env.EXPO_BASE_URL;\n\nlet BASE_PATH = `${BASE_URL}${RSC_PATH}`;\n\nif (!BASE_PATH.startsWith('/')) {\n BASE_PATH = '/' + BASE_PATH;\n}\n\nif (!BASE_PATH.endsWith('/')) {\n BASE_PATH += '/';\n}\n\nif (BASE_PATH === '/') {\n throw new Error(\n `Invalid React Flight path \"${BASE_PATH}\". The path should not live at the project root, e.g. /_flight/. Dev server URL: ${\n getDevServer().fullBundleUrl\n }`\n );\n}\n\ntype OnFetchData = (data: unknown) => void;\ntype SetElements = (updater: Elements | ((prev: Elements) => Elements)) => void;\n\nconst RSC_CONTENT_TYPE = 'text/x-component';\n\nconst ENTRY = 'e';\nconst SET_ELEMENTS = 's';\nconst ON_FETCH_DATA = 'o';\n\ntype FetchCache = {\n [ENTRY]?: [input: string, params: unknown, elements: Elements];\n [SET_ELEMENTS]?: SetElements;\n [ON_FETCH_DATA]?: OnFetchData | undefined;\n};\n\nconst defaultFetchCache: FetchCache = {};\n\nconst NO_CACHE_HEADERS: Record<string, string> =\n process.env.EXPO_OS === 'web'\n ? {}\n : // These are needed for iOS + Prod to get updates after the first request.\n {\n 'Cache-Control': 'no-cache',\n Pragma: 'no-cache',\n Expires: '0',\n };\n\nconst ACTION_HEADERS = {\n ...NO_CACHE_HEADERS,\n accept: RSC_CONTENT_TYPE,\n 'expo-platform': process.env.EXPO_OS!,\n};\n\nconst checkStatus = async (responsePromise: Promise<Response>): Promise<Response> => {\n // TODO: Combine with metro async fetch logic.\n const response = await responsePromise;\n if (!response.ok) {\n // NOTE(EvanBacon): Transform the Metro development error into a JS error that can be used by LogBox.\n // This was tested against using a Class component in a server component.\n if (response.status === 500) {\n const errorText = await response.text();\n let errorJson;\n try {\n errorJson = JSON.parse(errorText);\n } catch {\n throw new ReactServerError(errorText, response.url, response.status);\n }\n // TODO: This should be a dev-only error. Add handling for production equivalent.\n throw new MetroServerError(errorJson, response.url);\n }\n\n let responseText;\n try {\n responseText = await response.text();\n } catch {\n throw new ReactServerError(response.statusText, response.url, response.status);\n }\n throw new ReactServerError(responseText, response.url, response.status);\n }\n return response;\n};\n\ntype Elements = Promise<Record<string, ReactNode>> & {\n prev?: Record<string, ReactNode> | undefined;\n};\nfunction getCached<T>(c: () => T, m: WeakMap<object, T>, k: object): T {\n return (m.has(k) ? m : m.set(k, c())).get(k) as T;\n}\n\nconst cache1 = new WeakMap();\nconst mergeElements = (a: Elements, b: Elements): Elements => {\n const getResult = () => {\n const promise: Elements = new Promise((resolve, reject) => {\n Promise.all([a, b])\n .then(([a, b]) => {\n const nextElements = { ...a, ...b };\n delete nextElements._value;\n promise.prev = a;\n resolve(nextElements);\n })\n .catch((e) => {\n a.then(\n (a) => {\n promise.prev = a;\n reject(e);\n },\n () => {\n promise.prev = a.prev;\n reject(e);\n }\n );\n });\n });\n return promise;\n };\n const cache2 = getCached(() => new WeakMap(), cache1, a);\n return getCached(getResult, cache2, b);\n};\n\n/**\n * callServer callback\n * This is not a public API.\n */\nexport const callServerRSC = async (\n actionId: string,\n args?: unknown[],\n fetchCache = defaultFetchCache\n) => {\n const url = getAdjustedRemoteFilePath(BASE_PATH + encodeInput(encodeActionId(actionId)));\n const response =\n args === undefined\n ? fetch(url, { headers: ACTION_HEADERS })\n : encodeReply(args).then((body) =>\n fetch(url, { method: 'POST', body, headers: ACTION_HEADERS })\n );\n const data = createFromFetch<Awaited<Elements>>(checkStatus(response), {\n callServer: (actionId: string, args: unknown[]) => callServerRSC(actionId, args, fetchCache),\n });\n fetchCache[ON_FETCH_DATA]?.(data);\n startTransition(() => {\n // FIXME this causes rerenders even if data is empty\n fetchCache[SET_ELEMENTS]?.((prev) => mergeElements(prev, data));\n });\n return (await data)._value;\n};\n\nconst prefetchedParams = new WeakMap<Promise<unknown>, unknown>();\n\nconst fetchRSCInternal = (url: string, params: unknown) =>\n params === undefined\n ? fetch(url, {\n // Disable caching\n headers: {\n ...NO_CACHE_HEADERS,\n 'expo-platform': process.env.EXPO_OS!,\n },\n })\n : typeof params === 'string'\n ? fetch(url, {\n headers: {\n ...NO_CACHE_HEADERS,\n 'expo-platform': process.env.EXPO_OS!,\n 'X-Expo-Params': params,\n },\n })\n : encodeReply(params).then((body) =>\n fetch(url, { method: 'POST', headers: ACTION_HEADERS, body })\n );\n\nexport const fetchRSC = (\n input: string,\n params?: unknown,\n fetchCache = defaultFetchCache\n): Elements => {\n // TODO: strip when \"is exporting\".\n if (process.env.NODE_ENV === 'development') {\n const refetchRsc = () => {\n delete fetchCache[ENTRY];\n const data = fetchRSC(input, params, fetchCache);\n fetchCache[SET_ELEMENTS]?.(() => data);\n };\n globalThis.__EXPO_RSC_RELOAD_LISTENERS__ ||= [];\n const index = globalThis.__EXPO_RSC_RELOAD_LISTENERS__.indexOf(globalThis.__EXPO_REFETCH_RSC__);\n if (index !== -1) {\n globalThis.__EXPO_RSC_RELOAD_LISTENERS__.splice(index, 1, refetchRsc);\n } else {\n globalThis.__EXPO_RSC_RELOAD_LISTENERS__.push(refetchRsc);\n }\n globalThis.__EXPO_REFETCH_RSC__ = refetchRsc;\n }\n\n const entry = fetchCache[ENTRY];\n if (entry && entry[0] === input && entry[1] === params) {\n return entry[2];\n }\n\n // eslint-disable-next-line no-multi-assign\n const prefetched = ((globalThis as any).__EXPO_PREFETCHED__ ||= {});\n // TODO: Load from on-disk on native when indicated.\n // const reqPath = fetchOptions?.remote ? getAdjustedRemoteFilePath(url) : getAdjustedRemoteFilePath(url);\n const url = getAdjustedRemoteFilePath(BASE_PATH + encodeInput(input));\n const hasValidPrefetchedResponse =\n !!prefetched[url] &&\n // HACK .has() is for the initial hydration\n // It's limited and may result in a wrong result. FIXME\n (!prefetchedParams.has(prefetched[url]) || prefetchedParams.get(prefetched[url]) === params);\n const response = hasValidPrefetchedResponse ? prefetched[url] : fetchRSCInternal(url, params);\n delete prefetched[url];\n const data = createFromFetch<Awaited<Elements>>(checkStatus(response), {\n callServer: (actionId: string, args: unknown[]) => callServerRSC(actionId, args, fetchCache),\n });\n fetchCache[ON_FETCH_DATA]?.(data);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchCache[ENTRY] = [input, params, data];\n return data;\n};\n\nfunction getAdjustedRemoteFilePath(path: string): string {\n if (IS_DOM && process.env.NODE_ENV === 'production') {\n const origin = getOriginFromConstants();\n if (!origin) {\n throw new Error(\n 'Expo RSC: Origin not found in Constants. This is required for production DOM components using server actions.'\n );\n }\n // DOM components in production need to use the same origin logic as native.\n return new URL(path, origin).toString();\n }\n\n if (!IS_DOM && process.env.EXPO_OS === 'web') {\n return path;\n }\n\n return new URL(path, window.location.href).toString();\n}\n\nexport const prefetchRSC = (input: string, params?: unknown): void => {\n // eslint-disable-next-line no-multi-assign\n const prefetched = ((globalThis as any).__EXPO_PREFETCHED__ ||= {});\n const url = getAdjustedRemoteFilePath(BASE_PATH + encodeInput(input));\n if (!(url in prefetched)) {\n prefetched[url] = fetchRSCInternal(url, params);\n prefetchedParams.set(prefetched[url], params);\n }\n};\n\nconst RefetchContext = createContext<(input: string, searchParams?: URLSearchParams) => void>(\n () => {\n throw new Error('Missing Root component');\n }\n);\nconst ElementsContext = createContext<Elements | null>(null);\n\nexport const Root = ({\n initialInput,\n initialParams,\n fetchCache = defaultFetchCache,\n\n unstable_onFetchData,\n children,\n}: {\n initialInput?: string;\n initialParams?: unknown;\n fetchCache?: FetchCache;\n unstable_onFetchData?: (data: unknown) => void;\n children: ReactNode;\n}) => {\n fetchCache[ON_FETCH_DATA] = unstable_onFetchData;\n const [elements, setElements] = useState(() =>\n fetchRSC(initialInput || '', initialParams, fetchCache)\n );\n useEffect(() => {\n fetchCache[SET_ELEMENTS] = setElements;\n }, [fetchCache, setElements]);\n const refetch = useCallback(\n (input: string, params?: unknown) => {\n // clear cache entry before fetching\n delete fetchCache[ENTRY];\n const data = fetchRSC(input, params, fetchCache);\n startTransition(() => {\n setElements((prev) => mergeElements(prev, data));\n });\n },\n [fetchCache]\n );\n return createElement(\n RefetchContext.Provider,\n { value: refetch },\n createElement(ElementsContext.Provider, { value: elements }, children)\n );\n};\n\nexport const useRefetch = () => use(RefetchContext);\n\nconst ChildrenContext = createContext<ReactNode>(undefined);\nconst ChildrenContextProvider = memo(ChildrenContext.Provider);\n\nexport const Slot = ({\n id,\n children,\n fallback,\n}: {\n id: string;\n children?: ReactNode;\n fallback?: ReactNode;\n}) => {\n const elementsPromise = use(ElementsContext);\n if (!elementsPromise) {\n throw new Error('Missing Root component');\n }\n const elements = use(elementsPromise);\n if (!(id in elements)) {\n if (fallback) {\n return fallback;\n }\n throw new Error('Not found: ' + id + '. Expected: ' + Object.keys(elements).join(', '));\n }\n return createElement(ChildrenContextProvider, { value: children }, elements[id]);\n};\n\nexport const Children = () => use(ChildrenContext);\n\n/**\n * ServerRoot for SSR\n * This is not a public API.\n */\nexport const ServerRoot = ({ elements, children }: { elements: Elements; children: ReactNode }) =>\n createElement(ElementsContext.Provider, { value: elements }, children);\n"]}
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../../src/rsc/router/host.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,uCAAuC;AACvC,YAAY,CAAC;;;;;;;AAEb,iCAUe;AAEf,6EAAyD;AAEzD,qCAA8D;AAC9D,mCAAgC;AAChC,mCAAsD;AACtD,qDAAkD;AAClD,wCAAwD;AAExD,MAAM,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,gBAAU,CAAC;AAEpD,sDAAsD;AACtD,MAAM,MAAM;AACV,mDAAmD;AACnD,OAAO,kBAAkB,KAAK,WAAW,CAAC;AAE5C,mCAAmC;AACnC,MAAM,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,6BAA6B;AAEjF,+GAA+G;AAC/G,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAEzD,IAAI,SAAS,GAAG,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;AAEzC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;IAC9B,SAAS,GAAG,GAAG,GAAG,SAAS,CAAC;CAC7B;AAED,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,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AC;AAAtC,QAAA,QAAQ,YAA8B;AAEnD;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAA+C,EAAE,EAAE,CAChG,IAAA,qBAAa,EAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,QAAQ,CAAC,CAAC;AAD5D,QAAA,UAAU,cACkD","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n * Copyright © 2024 2023 Daishi Kato\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/client.ts#L1\n */\n\n//// <reference types=\"react/canary\" />\n'use client';\n\nimport {\n createContext,\n createElement,\n memo,\n useCallback,\n useState,\n startTransition,\n // @ts-expect-error\n use,\n useEffect,\n} from 'react';\nimport type { ReactNode } from 'react';\nimport RSDWClient from 'react-server-dom-webpack/client';\n\nimport { MetroServerError, ReactServerError } from './errors';\nimport { fetch } from './fetch';\nimport { encodeInput, encodeActionId } from './utils';\nimport { getDevServer } from '../../getDevServer';\nimport { getOriginFromConstants } from '../../head/url';\n\nconst { createFromFetch, encodeReply } = RSDWClient;\n\n// TODO: Maybe this could be a bundler global instead.\nconst IS_DOM =\n // @ts-expect-error: Added via react-native-webview\n typeof ReactNativeWebView !== 'undefined';\n\n// NOTE: Ensured to start with `/`.\nconst RSC_PATH = '/_flight/' + process.env.EXPO_OS; // process.env.EXPO_RSC_PATH;\n\n// Using base URL for remote hosts isn't currently supported in DOM components as we use it for offline assets.\nconst BASE_URL = IS_DOM ? '' : process.env.EXPO_BASE_URL;\n\nlet BASE_PATH = `${BASE_URL}${RSC_PATH}`;\n\nif (!BASE_PATH.startsWith('/')) {\n BASE_PATH = '/' + BASE_PATH;\n}\n\nif (!BASE_PATH.endsWith('/')) {\n BASE_PATH += '/';\n}\n\nif (BASE_PATH === '/') {\n throw new Error(\n `Invalid React Flight path \"${BASE_PATH}\". The path should not live at the project root, e.g. /_flight/. Dev server URL: ${\n getDevServer().fullBundleUrl\n }`\n );\n}\n\nif (process.env.EXPO_OS !== 'web' && !window.location?.href) {\n // This can happen if the user attempts to use React Server Components without\n // enabling the flags in the app.json. This will set origin to false and prevent the expo/metro-runtime polyfill from running.\n throw new Error(\n 'window.location.href is not defined. This is required for React Server Components to work correctly. Ensure React Server Components is correctly enabled in your project and config.'\n );\n}\n\ntype OnFetchData = (data: unknown) => void;\ntype SetElements = (updater: Elements | ((prev: Elements) => Elements)) => void;\n\nconst RSC_CONTENT_TYPE = 'text/x-component';\n\nconst ENTRY = 'e';\nconst SET_ELEMENTS = 's';\nconst ON_FETCH_DATA = 'o';\n\ntype FetchCache = {\n [ENTRY]?: [input: string, params: unknown, elements: Elements];\n [SET_ELEMENTS]?: SetElements;\n [ON_FETCH_DATA]?: OnFetchData | undefined;\n};\n\nconst defaultFetchCache: FetchCache = {};\n\nconst NO_CACHE_HEADERS: Record<string, string> =\n process.env.EXPO_OS === 'web'\n ? {}\n : // These are needed for iOS + Prod to get updates after the first request.\n {\n 'Cache-Control': 'no-cache',\n Pragma: 'no-cache',\n Expires: '0',\n };\n\nconst ACTION_HEADERS = {\n ...NO_CACHE_HEADERS,\n accept: RSC_CONTENT_TYPE,\n 'expo-platform': process.env.EXPO_OS!,\n};\n\nconst checkStatus = async (responsePromise: Promise<Response>): Promise<Response> => {\n // TODO: Combine with metro async fetch logic.\n const response = await responsePromise;\n if (!response.ok) {\n // NOTE(EvanBacon): Transform the Metro development error into a JS error that can be used by LogBox.\n // This was tested against using a Class component in a server component.\n if (__DEV__ && (response.status === 500 || response.status === 404)) {\n const errorText = await response.text();\n let errorJson;\n try {\n errorJson = JSON.parse(errorText);\n } catch {\n // `Unable to resolve module` error should respond as JSON from the dev server and sent to the master red box, this can get corrupt when it's returned as the formatted string.\n if (errorText.startsWith('Unable to resolve module')) {\n console.error('Unexpected Metro error format from dev server');\n // This is an unexpected state that occurs when the dev server renderer does not throw Metro errors in the expected JSON format.\n throw new Error(errorJson);\n }\n throw new ReactServerError(errorText, response.url, response.status, response.headers);\n }\n\n throw new MetroServerError(errorJson, response.url);\n }\n\n let responseText;\n try {\n responseText = await response.text();\n } catch {\n throw new ReactServerError(\n response.statusText,\n response.url,\n response.status,\n response.headers\n );\n }\n throw new ReactServerError(responseText, response.url, response.status, response.headers);\n }\n return response;\n};\n\ntype Elements = Promise<Record<string, ReactNode>> & {\n prev?: Record<string, ReactNode> | undefined;\n};\nfunction getCached<T>(c: () => T, m: WeakMap<object, T>, k: object): T {\n return (m.has(k) ? m : m.set(k, c())).get(k) as T;\n}\n\nconst cache1 = new WeakMap();\nconst mergeElements = (a: Elements, b: Elements): Elements => {\n const getResult = () => {\n const promise: Elements = new Promise((resolve, reject) => {\n Promise.all([a, b])\n .then(([a, b]) => {\n const nextElements = { ...a, ...b };\n delete nextElements._value;\n promise.prev = a;\n resolve(nextElements);\n })\n .catch((e) => {\n a.then(\n (a) => {\n promise.prev = a;\n reject(e);\n },\n () => {\n promise.prev = a.prev;\n reject(e);\n }\n );\n });\n });\n return promise;\n };\n const cache2 = getCached(() => new WeakMap(), cache1, a);\n return getCached(getResult, cache2, b);\n};\n\n/**\n * callServer callback\n * This is not a public API.\n */\nexport const callServerRSC = async (\n actionId: string,\n args?: unknown[],\n fetchCache = defaultFetchCache\n) => {\n const url = getAdjustedRemoteFilePath(BASE_PATH + encodeInput(encodeActionId(actionId)));\n const response =\n args === undefined\n ? fetch(url, { headers: ACTION_HEADERS })\n : encodeReply(args).then((body) =>\n fetch(url, { method: 'POST', body, headers: ACTION_HEADERS })\n );\n const data = createFromFetch<Awaited<Elements>>(checkStatus(response), {\n callServer: (actionId: string, args: unknown[]) => callServerRSC(actionId, args, fetchCache),\n });\n fetchCache[ON_FETCH_DATA]?.(data);\n startTransition(() => {\n // FIXME this causes rerenders even if data is empty\n fetchCache[SET_ELEMENTS]?.((prev) => mergeElements(prev, data));\n });\n return (await data)._value;\n};\n\nconst prefetchedParams = new WeakMap<Promise<unknown>, unknown>();\n\nconst fetchRSCInternal = (url: string, params: unknown) =>\n params === undefined\n ? fetch(url, {\n // Disable caching\n headers: {\n ...NO_CACHE_HEADERS,\n 'expo-platform': process.env.EXPO_OS!,\n },\n })\n : typeof params === 'string'\n ? fetch(url, {\n headers: {\n ...NO_CACHE_HEADERS,\n 'expo-platform': process.env.EXPO_OS!,\n 'X-Expo-Params': params,\n },\n })\n : encodeReply(params).then((body) =>\n fetch(url, { method: 'POST', headers: ACTION_HEADERS, body })\n );\n\nexport const fetchRSC = (\n input: string,\n params?: unknown,\n fetchCache = defaultFetchCache\n): Elements => {\n // TODO: strip when \"is exporting\".\n if (process.env.NODE_ENV === 'development') {\n const refetchRsc = () => {\n delete fetchCache[ENTRY];\n const data = fetchRSC(input, params, fetchCache);\n fetchCache[SET_ELEMENTS]?.(() => data);\n };\n globalThis.__EXPO_RSC_RELOAD_LISTENERS__ ||= [];\n const index = globalThis.__EXPO_RSC_RELOAD_LISTENERS__.indexOf(globalThis.__EXPO_REFETCH_RSC__);\n if (index !== -1) {\n globalThis.__EXPO_RSC_RELOAD_LISTENERS__.splice(index, 1, refetchRsc);\n } else {\n globalThis.__EXPO_RSC_RELOAD_LISTENERS__.push(refetchRsc);\n }\n globalThis.__EXPO_REFETCH_RSC__ = refetchRsc;\n }\n\n const entry = fetchCache[ENTRY];\n if (entry && entry[0] === input && entry[1] === params) {\n return entry[2];\n }\n\n // eslint-disable-next-line no-multi-assign\n const prefetched = ((globalThis as any).__EXPO_PREFETCHED__ ||= {});\n // TODO: Load from on-disk on native when indicated.\n // const reqPath = fetchOptions?.remote ? getAdjustedRemoteFilePath(url) : getAdjustedRemoteFilePath(url);\n const url = getAdjustedRemoteFilePath(BASE_PATH + encodeInput(input));\n const hasValidPrefetchedResponse =\n !!prefetched[url] &&\n // HACK .has() is for the initial hydration\n // It's limited and may result in a wrong result. FIXME\n (!prefetchedParams.has(prefetched[url]) || prefetchedParams.get(prefetched[url]) === params);\n const response = hasValidPrefetchedResponse ? prefetched[url] : fetchRSCInternal(url, params);\n delete prefetched[url];\n const data = createFromFetch<Awaited<Elements>>(checkStatus(response), {\n callServer: (actionId: string, args: unknown[]) => callServerRSC(actionId, args, fetchCache),\n });\n fetchCache[ON_FETCH_DATA]?.(data);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n fetchCache[ENTRY] = [input, params, data];\n return data;\n};\n\nfunction getAdjustedRemoteFilePath(path: string): string {\n if (IS_DOM && process.env.NODE_ENV === 'production') {\n const origin = getOriginFromConstants();\n if (!origin) {\n throw new Error(\n 'Expo RSC: Origin not found in Constants. This is required for production DOM components using server actions.'\n );\n }\n // DOM components in production need to use the same origin logic as native.\n return new URL(path, origin).toString();\n }\n\n if (!IS_DOM && process.env.EXPO_OS === 'web') {\n return path;\n }\n\n return new URL(path, window.location.href).toString();\n}\n\nexport const prefetchRSC = (input: string, params?: unknown): void => {\n // eslint-disable-next-line no-multi-assign\n const prefetched = ((globalThis as any).__EXPO_PREFETCHED__ ||= {});\n const url = getAdjustedRemoteFilePath(BASE_PATH + encodeInput(input));\n if (!(url in prefetched)) {\n prefetched[url] = fetchRSCInternal(url, params);\n prefetchedParams.set(prefetched[url], params);\n }\n};\n\nconst RefetchContext = createContext<(input: string, searchParams?: URLSearchParams) => void>(\n () => {\n throw new Error('Missing Root component');\n }\n);\nconst ElementsContext = createContext<Elements | null>(null);\n\nexport const Root = ({\n initialInput,\n initialParams,\n fetchCache = defaultFetchCache,\n\n unstable_onFetchData,\n children,\n}: {\n initialInput?: string;\n initialParams?: unknown;\n fetchCache?: FetchCache;\n unstable_onFetchData?: (data: unknown) => void;\n children: ReactNode;\n}) => {\n fetchCache[ON_FETCH_DATA] = unstable_onFetchData;\n const [elements, setElements] = useState(() =>\n fetchRSC(initialInput || '', initialParams, fetchCache)\n );\n useEffect(() => {\n fetchCache[SET_ELEMENTS] = setElements;\n }, [fetchCache, setElements]);\n const refetch = useCallback(\n (input: string, params?: unknown) => {\n // clear cache entry before fetching\n delete fetchCache[ENTRY];\n const data = fetchRSC(input, params, fetchCache);\n startTransition(() => {\n setElements((prev) => mergeElements(prev, data));\n });\n },\n [fetchCache]\n );\n return createElement(\n RefetchContext.Provider,\n { value: refetch },\n createElement(ElementsContext.Provider, { value: elements }, children)\n );\n};\n\nexport const useRefetch = () => use(RefetchContext);\n\nconst ChildrenContext = createContext<ReactNode>(undefined);\nconst ChildrenContextProvider = memo(ChildrenContext.Provider);\n\nexport const Slot = ({\n id,\n children,\n fallback,\n}: {\n id: string;\n children?: ReactNode;\n fallback?: ReactNode;\n}) => {\n const elementsPromise = use(ElementsContext);\n if (!elementsPromise) {\n throw new Error('Missing Root component');\n }\n const elements = use(elementsPromise);\n if (!(id in elements)) {\n if (fallback) {\n return fallback;\n }\n throw new Error('Not found: ' + id + '. Expected: ' + Object.keys(elements).join(', '));\n }\n return createElement(ChildrenContextProvider, { value: children }, elements[id]);\n};\n\nexport const Children = () => use(ChildrenContext);\n\n/**\n * ServerRoot for SSR\n * This is not a public API.\n */\nexport const ServerRoot = ({ elements, children }: { elements: Elements; children: ReactNode }) =>\n createElement(ElementsContext.Provider, { value: elements }, children);\n"]}
|
package/build/rsc/server.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ type RenderStore = {
|
|
|
57
57
|
* This is an internal function and not for public use.
|
|
58
58
|
*/
|
|
59
59
|
export declare const runWithRenderStore: <T>(renderStore: RenderStore, fn: () => T) => T;
|
|
60
|
-
export declare function rerender(input: string, params?: unknown): void
|
|
60
|
+
export declare function rerender(input: string, params?: unknown): Promise<void>;
|
|
61
61
|
export declare function getContext<RscContext extends Record<string, unknown> = Record<string, unknown>>(): RscContext;
|
|
62
62
|
/** Get the request headers used to make the server component or action request. */
|
|
63
63
|
export declare function unstable_headers(): Promise<Headers>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/rsc/server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AAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,iBAO7D;AAED,wBAAgB,UAAU,CACxB,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACjE,UAAU,CAOd;AAED,mFAAmF;AACnF,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,CAGzD"}
|
package/build/rsc/server.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.unstable_headers = exports.getContext = exports.rerender = exports.runWithRenderStore = exports.defineEntries = exports.REQUEST_HEADERS = void 0;
|
|
11
|
+
const async_hooks_1 = require("async_hooks");
|
|
11
12
|
exports.REQUEST_HEADERS = '__expo_requestHeaders';
|
|
12
13
|
function defineEntries(renderEntries, getBuildConfig, getSsrConfig) {
|
|
13
14
|
return { renderEntries, getBuildConfig, getSsrConfig };
|
|
@@ -16,46 +17,27 @@ exports.defineEntries = defineEntries;
|
|
|
16
17
|
// TODO(EvanBacon): This can leak between platforms and runs.
|
|
17
18
|
// We need to share this module between the server action module and the renderer module, per platform, and invalidate on refreshes.
|
|
18
19
|
function getGlobalCacheForPlatform() {
|
|
20
|
+
// HACK: This is a workaround for the shared middleware being shared between web and native.
|
|
21
|
+
// In production the shared middleware is web-only and that causes the first version of this module
|
|
22
|
+
// to be bound to web.
|
|
23
|
+
const platform = globalThis.__expo_platform_header ?? process.env.EXPO_OS;
|
|
19
24
|
if (!globalThis.__EXPO_RSC_CACHE__) {
|
|
20
25
|
globalThis.__EXPO_RSC_CACHE__ = new Map();
|
|
21
26
|
}
|
|
22
|
-
if (globalThis.__EXPO_RSC_CACHE__.has(
|
|
23
|
-
return globalThis.__EXPO_RSC_CACHE__.get(
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
const { AsyncLocalStorage } = require('node:async_hooks');
|
|
27
|
-
// @ts-expect-error: This is a Node.js feature.
|
|
28
|
-
const serverCache = new AsyncLocalStorage();
|
|
29
|
-
globalThis.__EXPO_RSC_CACHE__.set(process.env.EXPO_OS, serverCache);
|
|
30
|
-
return serverCache;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
console.log('[RSC]: Failed to create cache:', error);
|
|
34
|
-
// Fallback to a simple in-memory cache.
|
|
35
|
-
const cache = new Map();
|
|
36
|
-
const serverCache = {
|
|
37
|
-
getStore: () => cache.get('store'),
|
|
38
|
-
run: (store, fn) => {
|
|
39
|
-
cache.set('store', store);
|
|
40
|
-
try {
|
|
41
|
-
return fn();
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
cache.delete('store');
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
globalThis.__EXPO_RSC_CACHE__.set(process.env.EXPO_OS, serverCache);
|
|
49
|
-
return serverCache;
|
|
27
|
+
if (globalThis.__EXPO_RSC_CACHE__.has(platform)) {
|
|
28
|
+
return globalThis.__EXPO_RSC_CACHE__.get(platform);
|
|
50
29
|
}
|
|
30
|
+
const serverCache = new async_hooks_1.AsyncLocalStorage();
|
|
31
|
+
globalThis.__EXPO_RSC_CACHE__.set(platform, serverCache);
|
|
32
|
+
return serverCache;
|
|
51
33
|
}
|
|
52
34
|
let previousRenderStore;
|
|
53
35
|
let currentRenderStore;
|
|
54
|
-
const renderStorage = getGlobalCacheForPlatform();
|
|
55
36
|
/**
|
|
56
37
|
* This is an internal function and not for public use.
|
|
57
38
|
*/
|
|
58
39
|
const runWithRenderStore = (renderStore, fn) => {
|
|
40
|
+
const renderStorage = getGlobalCacheForPlatform();
|
|
59
41
|
if (renderStorage) {
|
|
60
42
|
return renderStorage.run(renderStore, fn);
|
|
61
43
|
}
|
|
@@ -69,18 +51,20 @@ const runWithRenderStore = (renderStore, fn) => {
|
|
|
69
51
|
}
|
|
70
52
|
};
|
|
71
53
|
exports.runWithRenderStore = runWithRenderStore;
|
|
72
|
-
function rerender(input, params) {
|
|
73
|
-
const
|
|
54
|
+
async function rerender(input, params) {
|
|
55
|
+
const renderStorage = getGlobalCacheForPlatform();
|
|
56
|
+
const renderStore = renderStorage.getStore() ?? currentRenderStore;
|
|
74
57
|
if (!renderStore) {
|
|
75
|
-
throw new Error('Render store is not available');
|
|
58
|
+
throw new Error('Render store is not available for rerender');
|
|
76
59
|
}
|
|
77
60
|
renderStore.rerender(input, params);
|
|
78
61
|
}
|
|
79
62
|
exports.rerender = rerender;
|
|
80
63
|
function getContext() {
|
|
81
|
-
const
|
|
64
|
+
const renderStorage = getGlobalCacheForPlatform();
|
|
65
|
+
const renderStore = renderStorage.getStore() ?? currentRenderStore;
|
|
82
66
|
if (!renderStore) {
|
|
83
|
-
throw new Error('Render store is not available');
|
|
67
|
+
throw new Error('Render store is not available for accessing context');
|
|
84
68
|
}
|
|
85
69
|
return renderStore.context;
|
|
86
70
|
}
|
package/build/rsc/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rsc/server.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/rsc/server.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAgD;AAKnC,QAAA,eAAe,GAAG,uBAAuB,CAAC;AAkDvD,SAAgB,aAAa,CAC3B,aAA4B,EAC5B,cAA+B,EAC/B,YAA2B;IAE3B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AACzD,CAAC;AAND,sCAMC;AAkBD,6DAA6D;AAC7D,oIAAoI;AACpI,SAAS,yBAAyB;IAChC,4FAA4F;IAC5F,mGAAmG;IACnG,sBAAsB;IACtB,MAAM,QAAQ,GAAG,UAAU,CAAC,sBAAsB,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAC1E,IAAI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U;IAGxB,MAAM,aAAa,GAAG,yBAAyB,EAAE,CAAC;IAClD,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,EAAE,IAAI,kBAAkB,CAAC;IACnE,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KACxE;IACD,OAAO,WAAW,CAAC,OAAqB,CAAC;AAC3C,CAAC;AATD,gCASC;AAED,mFAAmF;AAC5E,KAAK,UAAU,gBAAgB;IACpC,MAAM,OAAO,GAAG,CAAC,UAAU,EAAE,CAAC,uBAAe,CAAC,IAAI,EAAE,CAA2B,CAAC;IAChF,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAHD,4CAGC;AAED,MAAM,eAAgB,SAAQ,OAAO;IACnC,GAAG;QACD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM;QACJ,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n * Copyright © 2024 2023 Daishi Kato\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { AsyncLocalStorage } from 'async_hooks';\nimport type { ReactNode } from 'react';\n\nimport type { PathSpec } from './path';\n\nexport const REQUEST_HEADERS = '__expo_requestHeaders';\n\ndeclare let globalThis: {\n __EXPO_RSC_CACHE__?: Map<string, any>;\n __expo_platform_header?: string;\n __webpack_chunk_load__: (id: string) => Promise<any>;\n __webpack_require__: (id: string) => any;\n};\n\ntype Config = any;\n\ntype Elements = Record<string, ReactNode>;\n\nexport type BuildConfig = {\n pathname: string | PathSpec; // TODO drop support for string?\n isStatic?: boolean | undefined;\n entries?: {\n input: string;\n skipPrefetch?: boolean | undefined;\n isStatic?: boolean | undefined;\n }[];\n context?: Record<string, unknown>;\n customCode?: string; // optional code to inject TODO hope to remove this\n customData?: unknown; // should be serializable with JSON.stringify\n}[];\n\nexport type RenderEntries = (\n input: string,\n options: {\n params: unknown | undefined;\n buildConfig: BuildConfig | undefined;\n }\n) => Promise<Elements | null>;\n\nexport type GetBuildConfig = (\n unstable_collectClientModules: (input: string) => Promise<string[]>\n) => Promise<BuildConfig>;\n\nexport type GetSsrConfig = (\n pathname: string,\n options: {\n searchParams: URLSearchParams;\n buildConfig?: BuildConfig | undefined;\n }\n) => Promise<{\n input: string;\n searchParams?: URLSearchParams;\n html: ReactNode;\n} | null>;\n\nexport function defineEntries(\n renderEntries: RenderEntries,\n getBuildConfig?: GetBuildConfig,\n getSsrConfig?: GetSsrConfig\n) {\n return { renderEntries, getBuildConfig, getSsrConfig };\n}\n\nexport type EntriesDev = {\n default: ReturnType<typeof defineEntries>;\n};\n\nexport type EntriesPrd = EntriesDev & {\n loadConfig: () => Promise<Config>;\n loadModule: (id: string) => Promise<unknown>;\n dynamicHtmlPaths: [pathSpec: PathSpec, htmlHead: string][];\n publicIndexHtml: string;\n};\n\ntype RenderStore<> = {\n rerender: (input: string, params?: unknown) => void;\n context: Record<string, unknown>;\n};\n\n// TODO(EvanBacon): This can leak between platforms and runs.\n// We need to share this module between the server action module and the renderer module, per platform, and invalidate on refreshes.\nfunction getGlobalCacheForPlatform() {\n // HACK: This is a workaround for the shared middleware being shared between web and native.\n // In production the shared middleware is web-only and that causes the first version of this module\n // to be bound to web.\n const platform = globalThis.__expo_platform_header ?? process.env.EXPO_OS;\n if (!globalThis.__EXPO_RSC_CACHE__) {\n globalThis.__EXPO_RSC_CACHE__ = new Map();\n }\n\n if (globalThis.__EXPO_RSC_CACHE__.has(platform!)) {\n return globalThis.__EXPO_RSC_CACHE__.get(platform!)!;\n }\n\n const serverCache = new AsyncLocalStorage<RenderStore>();\n\n globalThis.__EXPO_RSC_CACHE__.set(platform!, serverCache);\n\n return serverCache;\n}\n\nlet previousRenderStore: RenderStore | undefined;\nlet currentRenderStore: RenderStore | undefined;\n\n/**\n * This is an internal function and not for public use.\n */\nexport const runWithRenderStore = <T>(renderStore: RenderStore, fn: () => T): T => {\n const renderStorage = getGlobalCacheForPlatform();\n if (renderStorage) {\n return renderStorage.run(renderStore, fn);\n }\n previousRenderStore = currentRenderStore;\n currentRenderStore = renderStore;\n try {\n return fn();\n } finally {\n currentRenderStore = previousRenderStore;\n }\n};\n\nexport async function rerender(input: string, params?: unknown) {\n const renderStorage = getGlobalCacheForPlatform();\n const renderStore = renderStorage.getStore() ?? currentRenderStore;\n if (!renderStore) {\n throw new Error('Render store is not available for rerender');\n }\n renderStore.rerender(input, params);\n}\n\nexport function getContext<\n RscContext extends Record<string, unknown> = Record<string, unknown>,\n>(): RscContext {\n const renderStorage = getGlobalCacheForPlatform();\n const renderStore = renderStorage.getStore() ?? currentRenderStore;\n if (!renderStore) {\n throw new Error('Render store is not available for accessing context');\n }\n return renderStore.context as RscContext;\n}\n\n/** Get the request headers used to make the server component or action request. */\nexport async function unstable_headers(): Promise<Headers> {\n const headers = (getContext()[REQUEST_HEADERS] || {}) as Record<string, string>;\n return new ReadonlyHeaders(headers);\n}\n\nclass ReadonlyHeaders extends Headers {\n set() {\n throw new Error('Server component Headers are read-only');\n }\n append() {\n throw new Error('Server component Headers are read-only');\n }\n delete() {\n throw new Error('Server component Headers are read-only');\n }\n}\n"]}
|
|
@@ -14,4 +14,9 @@ import { ExpoRouterServerManifestV1 } from '../getServerManifest';
|
|
|
14
14
|
* This is used for the production manifest where we pre-render certain pages and should no longer treat them as dynamic.
|
|
15
15
|
*/
|
|
16
16
|
export declare function getBuildTimeServerManifestAsync(options?: Options): Promise<ExpoRouterServerManifestV1>;
|
|
17
|
+
/** Get the linking manifest from a Node.js process. */
|
|
18
|
+
export declare function getManifest(options?: Options): Promise<{
|
|
19
|
+
initialRouteName: undefined;
|
|
20
|
+
screens: Record<string, import("../getReactNavigationConfig").Screen>;
|
|
21
|
+
}>;
|
|
17
22
|
//# sourceMappingURL=getServerManifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getServerManifest.d.ts","sourceRoot":"","sources":["../../src/static/getServerManifest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"getServerManifest.d.ts","sourceRoot":"","sources":["../../src/static/getServerManifest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAa,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAqB,MAAM,sBAAsB,CAAC;AAGrF;;;;;;GAMG;AACH,wBAAsB,+BAA+B,CACnD,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,0BAA0B,CAAC,CAcrC;AAED,uDAAuD;AACvD,wBAAsB,WAAW,CAAC,OAAO,GAAE,OAAY;;;GAetD"}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getBuildTimeServerManifestAsync = void 0;
|
|
9
|
+
exports.getManifest = exports.getBuildTimeServerManifestAsync = void 0;
|
|
10
10
|
const _ctx_1 = require("../../_ctx");
|
|
11
|
+
const getReactNavigationConfig_1 = require("../getReactNavigationConfig");
|
|
11
12
|
const getRoutes_1 = require("../getRoutes");
|
|
12
13
|
const getServerManifest_1 = require("../getServerManifest");
|
|
13
14
|
const loadStaticParamsAsync_1 = require("../loadStaticParamsAsync");
|
|
@@ -31,4 +32,19 @@ async function getBuildTimeServerManifestAsync(options = {}) {
|
|
|
31
32
|
return (0, getServerManifest_1.getServerManifest)(routeTree);
|
|
32
33
|
}
|
|
33
34
|
exports.getBuildTimeServerManifestAsync = getBuildTimeServerManifestAsync;
|
|
35
|
+
/** Get the linking manifest from a Node.js process. */
|
|
36
|
+
async function getManifest(options = {}) {
|
|
37
|
+
const routeTree = (0, getRoutes_1.getRoutes)(_ctx_1.ctx, {
|
|
38
|
+
preserveApiRoutes: true,
|
|
39
|
+
platform: 'web',
|
|
40
|
+
...options,
|
|
41
|
+
});
|
|
42
|
+
if (!routeTree) {
|
|
43
|
+
throw new Error('No routes found');
|
|
44
|
+
}
|
|
45
|
+
// Evaluate all static params
|
|
46
|
+
await (0, loadStaticParamsAsync_1.loadStaticParamsAsync)(routeTree);
|
|
47
|
+
return (0, getReactNavigationConfig_1.getReactNavigationConfig)(routeTree, false);
|
|
48
|
+
}
|
|
49
|
+
exports.getManifest = getManifest;
|
|
34
50
|
//# sourceMappingURL=getServerManifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getServerManifest.js","sourceRoot":"","sources":["../../src/static/getServerManifest.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAiC;AACjC,4CAAkD;AAClD,4DAAqF;AACrF,oEAAiE;AAEjE;;;;;;GAMG;AACI,KAAK,UAAU,+BAA+B,CACnD,UAAmB,EAAE;IAErB,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,UAAG,EAAE;QAC/B,QAAQ,EAAE,KAAK;QACf,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;KACpC;IAED,6BAA6B;IAC7B,MAAM,IAAA,6CAAqB,EAAC,SAAS,CAAC,CAAC;IAEvC,OAAO,IAAA,qCAAiB,EAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAhBD,0EAgBC","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { ctx } from '../../_ctx';\nimport { getRoutes, Options } from '../getRoutes';\nimport { ExpoRouterServerManifestV1, getServerManifest } from '../getServerManifest';\nimport { loadStaticParamsAsync } from '../loadStaticParamsAsync';\n\n/**\n * Get the server manifest with all dynamic routes loaded with `generateStaticParams`.\n * Unlike the `expo-router/src/routes-manifest.ts` method, this requires loading the entire app in-memory, which\n * takes substantially longer and requires Metro bundling.\n *\n * This is used for the production manifest where we pre-render certain pages and should no longer treat them as dynamic.\n */\nexport async function getBuildTimeServerManifestAsync(\n options: Options = {}\n): Promise<ExpoRouterServerManifestV1> {\n const routeTree = getRoutes(ctx, {\n platform: 'web',\n ...options,\n });\n\n if (!routeTree) {\n throw new Error('No routes found');\n }\n\n // Evaluate all static params\n await loadStaticParamsAsync(routeTree);\n\n return getServerManifest(routeTree);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getServerManifest.js","sourceRoot":"","sources":["../../src/static/getServerManifest.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAiC;AACjC,0EAAuE;AACvE,4CAAkD;AAClD,4DAAqF;AACrF,oEAAiE;AAEjE;;;;;;GAMG;AACI,KAAK,UAAU,+BAA+B,CACnD,UAAmB,EAAE;IAErB,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,UAAG,EAAE;QAC/B,QAAQ,EAAE,KAAK;QACf,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;KACpC;IAED,6BAA6B;IAC7B,MAAM,IAAA,6CAAqB,EAAC,SAAS,CAAC,CAAC;IAEvC,OAAO,IAAA,qCAAiB,EAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAhBD,0EAgBC;AAED,uDAAuD;AAChD,KAAK,UAAU,WAAW,CAAC,UAAmB,EAAE;IACrD,MAAM,SAAS,GAAG,IAAA,qBAAS,EAAC,UAAG,EAAE;QAC/B,iBAAiB,EAAE,IAAI;QACvB,QAAQ,EAAE,KAAK;QACf,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;KACpC;IAED,6BAA6B;IAC7B,MAAM,IAAA,6CAAqB,EAAC,SAAS,CAAC,CAAC;IAEvC,OAAO,IAAA,mDAAwB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC;AAfD,kCAeC","sourcesContent":["/**\n * Copyright © 2024 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { ctx } from '../../_ctx';\nimport { getReactNavigationConfig } from '../getReactNavigationConfig';\nimport { getRoutes, Options } from '../getRoutes';\nimport { ExpoRouterServerManifestV1, getServerManifest } from '../getServerManifest';\nimport { loadStaticParamsAsync } from '../loadStaticParamsAsync';\n\n/**\n * Get the server manifest with all dynamic routes loaded with `generateStaticParams`.\n * Unlike the `expo-router/src/routes-manifest.ts` method, this requires loading the entire app in-memory, which\n * takes substantially longer and requires Metro bundling.\n *\n * This is used for the production manifest where we pre-render certain pages and should no longer treat them as dynamic.\n */\nexport async function getBuildTimeServerManifestAsync(\n options: Options = {}\n): Promise<ExpoRouterServerManifestV1> {\n const routeTree = getRoutes(ctx, {\n platform: 'web',\n ...options,\n });\n\n if (!routeTree) {\n throw new Error('No routes found');\n }\n\n // Evaluate all static params\n await loadStaticParamsAsync(routeTree);\n\n return getServerManifest(routeTree);\n}\n\n/** Get the linking manifest from a Node.js process. */\nexport async function getManifest(options: Options = {}) {\n const routeTree = getRoutes(ctx, {\n preserveApiRoutes: true,\n platform: 'web',\n ...options,\n });\n\n if (!routeTree) {\n throw new Error('No routes found');\n }\n\n // Evaluate all static params\n await loadStaticParamsAsync(routeTree);\n\n return getReactNavigationConfig(routeTree, false);\n}\n"]}
|
|
@@ -5,13 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import '@expo/metro-runtime';
|
|
8
|
-
import { Options } from '../getRoutes';
|
|
9
|
-
/** Get the linking manifest from a Node.js process. */
|
|
10
|
-
declare function getManifest(options?: Options): Promise<{
|
|
11
|
-
initialRouteName: undefined;
|
|
12
|
-
screens: Record<string, import("../getReactNavigationConfig").Screen>;
|
|
13
|
-
}>;
|
|
14
8
|
export declare function getStaticContent(location: URL): Promise<string>;
|
|
15
|
-
export { getManifest };
|
|
16
|
-
export { getBuildTimeServerManifestAsync } from './getServerManifest';
|
|
9
|
+
export { getBuildTimeServerManifestAsync, getManifest } from './getServerManifest';
|
|
17
10
|
//# sourceMappingURL=renderStaticContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderStaticContent.d.ts","sourceRoot":"","sources":["../../src/static/renderStaticContent.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"renderStaticContent.d.ts","sourceRoot":"","sources":["../../src/static/renderStaticContent.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,qBAAqB,CAAC;AA2B7B,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAoDrE;AAmBD,OAAO,EAAE,+BAA+B,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.getManifest = exports.getBuildTimeServerManifestAsync = exports.getStaticContent = void 0;
|
|
30
30
|
/**
|
|
31
31
|
* Copyright © 2023 650 Industries.
|
|
32
32
|
*
|
|
@@ -42,27 +42,9 @@ const react_native_web_1 = require("react-native-web");
|
|
|
42
42
|
const getRootComponent_1 = require("./getRootComponent");
|
|
43
43
|
const _ctx_1 = require("../../_ctx");
|
|
44
44
|
const ExpoRoot_1 = require("../ExpoRoot");
|
|
45
|
-
const getReactNavigationConfig_1 = require("../getReactNavigationConfig");
|
|
46
|
-
const getRoutes_1 = require("../getRoutes");
|
|
47
45
|
const head_1 = require("../head");
|
|
48
|
-
const loadStaticParamsAsync_1 = require("../loadStaticParamsAsync");
|
|
49
46
|
const debug = require('debug')('expo:router:renderStaticContent');
|
|
50
47
|
react_native_web_1.AppRegistry.registerComponent('App', () => ExpoRoot_1.ExpoRoot);
|
|
51
|
-
/** Get the linking manifest from a Node.js process. */
|
|
52
|
-
async function getManifest(options = {}) {
|
|
53
|
-
const routeTree = (0, getRoutes_1.getRoutes)(_ctx_1.ctx, {
|
|
54
|
-
preserveApiRoutes: true,
|
|
55
|
-
platform: 'web',
|
|
56
|
-
...options,
|
|
57
|
-
});
|
|
58
|
-
if (!routeTree) {
|
|
59
|
-
throw new Error('No routes found');
|
|
60
|
-
}
|
|
61
|
-
// Evaluate all static params
|
|
62
|
-
await (0, loadStaticParamsAsync_1.loadStaticParamsAsync)(routeTree);
|
|
63
|
-
return (0, getReactNavigationConfig_1.getReactNavigationConfig)(routeTree, false);
|
|
64
|
-
}
|
|
65
|
-
exports.getManifest = getManifest;
|
|
66
48
|
function resetReactNavigationContexts() {
|
|
67
49
|
// https://github.com/expo/router/discussions/588
|
|
68
50
|
// https://github.com/react-navigation/react-navigation/blob/9fe34b445fcb86e5666f61e144007d7540f014fa/packages/elements/src/getNamedContext.tsx#LL3C1-L4C1
|
|
@@ -121,6 +103,8 @@ function mixHeadComponentsWithStaticResults(helmet, html) {
|
|
|
121
103
|
html = html.replace('<body ', `<body ${helmet?.bodyAttributes.toString()} `);
|
|
122
104
|
return html;
|
|
123
105
|
}
|
|
106
|
+
// Re-export for use in server
|
|
124
107
|
var getServerManifest_1 = require("./getServerManifest");
|
|
125
108
|
Object.defineProperty(exports, "getBuildTimeServerManifestAsync", { enumerable: true, get: function () { return getServerManifest_1.getBuildTimeServerManifestAsync; } });
|
|
109
|
+
Object.defineProperty(exports, "getManifest", { enumerable: true, get: function () { return getServerManifest_1.getManifest; } });
|
|
126
110
|
//# sourceMappingURL=renderStaticContent.js.map
|