@tanstack/react-start 1.132.0-alpha.8 → 1.132.0
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/default-entry/esm/server.d.ts +6 -0
- package/dist/default-entry/esm/server.js +11 -0
- package/dist/default-entry/esm/server.js.map +1 -0
- package/dist/default-entry/esm/start.d.ts +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/plugin/vite.js +24 -30
- package/dist/esm/plugin/vite.js.map +1 -1
- package/dist/esm/useServerFn.d.ts +1 -0
- package/dist/esm/useServerFn.js +27 -0
- package/dist/esm/useServerFn.js.map +1 -0
- package/dist/plugin/default-entry/client.tsx +2 -5
- package/dist/plugin/default-entry/server.ts +7 -6
- package/dist/plugin/default-entry/start.ts +1 -0
- package/package.json +17 -9
- package/src/{plugin/default-entry → default-entry}/client.tsx +2 -5
- package/src/default-entry/server.ts +15 -0
- package/src/default-entry/start.ts +1 -0
- package/src/index.ts +2 -0
- package/src/plugin/vite.ts +34 -44
- package/src/useServerFn.ts +30 -0
- package/src/plugin/default-entry/router-entry.d.ts +0 -4
- package/src/plugin/default-entry/server.ts +0 -14
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createStartHandler, defaultStreamHandler } from "@tanstack/react-start/server";
|
|
2
|
+
const fetch = createStartHandler(defaultStreamHandler);
|
|
3
|
+
const server = {
|
|
4
|
+
// Providing `RequestHandler` from `@tanstack/react-start/server` is required so that the output types don't import it from `@tanstack/start-server-core`
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
6
|
+
fetch
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
server as default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sources":["../../../src/default-entry/server.ts"],"sourcesContent":["import {\n createStartHandler,\n defaultStreamHandler,\n} from '@tanstack/react-start/server'\nimport type { Register } from '@tanstack/react-start'\nimport type { RequestHandler } from '@tanstack/react-start/server'\n\nconst fetch = createStartHandler(defaultStreamHandler)\n\nexport default {\n // Providing `RequestHandler` from `@tanstack/react-start/server` is required so that the output types don't import it from `@tanstack/start-server-core`\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n fetch: fetch as RequestHandler<Register>,\n}\n"],"names":[],"mappings":";AAOA,MAAM,QAAQ,mBAAmB,oBAAoB;AAErD,MAAA,SAAe;AAAA;AAAA;AAAA,EAIb;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/dist/esm/plugin/vite.js
CHANGED
|
@@ -11,57 +11,51 @@ const defaultEntryDir = path.resolve(
|
|
|
11
11
|
);
|
|
12
12
|
const defaultEntryPaths = {
|
|
13
13
|
client: path.resolve(defaultEntryDir, "client"),
|
|
14
|
-
server: path.resolve(defaultEntryDir, "server")
|
|
14
|
+
server: path.resolve(defaultEntryDir, "server"),
|
|
15
|
+
start: path.resolve(defaultEntryDir, "start")
|
|
15
16
|
};
|
|
16
17
|
const isInsideRouterMonoRepo = path.basename(path.resolve(currentDir, "../../../../")) === "packages";
|
|
17
|
-
function hasRootExport(exportsField) {
|
|
18
|
-
if (!exportsField) return false;
|
|
19
|
-
if (typeof exportsField === "string") {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (typeof exportsField === "object") {
|
|
23
|
-
return "." in exportsField;
|
|
24
|
-
}
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
18
|
function tanstackStart(options) {
|
|
28
19
|
return [
|
|
29
20
|
{
|
|
30
21
|
name: "tanstack-react-start:config",
|
|
31
|
-
configEnvironment(
|
|
22
|
+
configEnvironment(environmentName, options2) {
|
|
32
23
|
return {
|
|
33
24
|
resolve: {
|
|
34
|
-
dedupe: [
|
|
35
|
-
|
|
25
|
+
dedupe: [
|
|
26
|
+
"react",
|
|
27
|
+
"react-dom",
|
|
28
|
+
"@tanstack/react-start",
|
|
29
|
+
"@tanstack/react-router"
|
|
30
|
+
],
|
|
31
|
+
external: options2.resolve?.noExternal === true || !isInsideRouterMonoRepo ? void 0 : ["@tanstack/react-router", "@tanstack/react-router-devtools"]
|
|
36
32
|
},
|
|
37
|
-
optimizeDeps:
|
|
38
|
-
|
|
33
|
+
optimizeDeps: environmentName === VITE_ENVIRONMENT_NAMES.client || environmentName === VITE_ENVIRONMENT_NAMES.server && // This indicates that the server environment has opted in to dependency optimization
|
|
34
|
+
options2.optimizeDeps?.noDiscovery === false ? {
|
|
35
|
+
// As `@tanstack/react-start` depends on `@tanstack/react-router`, we should exclude both.
|
|
36
|
+
exclude: [
|
|
37
|
+
"@tanstack/react-start",
|
|
38
|
+
"@tanstack/react-router",
|
|
39
|
+
"@tanstack/react-router-devtools"
|
|
40
|
+
],
|
|
39
41
|
include: [
|
|
40
42
|
"react",
|
|
41
43
|
"react/jsx-runtime",
|
|
42
44
|
"react/jsx-dev-runtime",
|
|
43
45
|
"react-dom",
|
|
44
|
-
"react-dom/client",
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
...environmentName === VITE_ENVIRONMENT_NAMES.client ? ["react-dom/client"] : ["react-dom/server"],
|
|
47
|
+
// `@tanstack/react-store` has a dependency on `use-sync-external-store`, which is CJS.
|
|
48
|
+
// It therefore needs to included so that it is converted to ESM.
|
|
49
|
+
"@tanstack/react-router > @tanstack/react-store"
|
|
47
50
|
]
|
|
48
|
-
}
|
|
51
|
+
} : void 0
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
},
|
|
52
55
|
TanStackStartVitePluginCore(
|
|
53
56
|
{
|
|
54
57
|
framework: "react",
|
|
55
|
-
defaultEntryPaths
|
|
56
|
-
crawlPackages(opts) {
|
|
57
|
-
if (opts.name === "@tanstack/react-router-devtools") {
|
|
58
|
-
return "exclude";
|
|
59
|
-
}
|
|
60
|
-
if (hasRootExport(opts.exports) && "react" in opts.peerDependencies) {
|
|
61
|
-
return "include";
|
|
62
|
-
}
|
|
63
|
-
return void 0;
|
|
64
|
-
}
|
|
58
|
+
defaultEntryPaths
|
|
65
59
|
},
|
|
66
60
|
options
|
|
67
61
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sources":["../../../src/plugin/vite.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url'\nimport {\n TanStackStartVitePluginCore,\n VITE_ENVIRONMENT_NAMES,\n} from '@tanstack/start-plugin-core'\nimport path from 'pathe'\nimport type { TanStackStartInputConfig } from '@tanstack/start-plugin-core'\nimport type { PluginOption } from 'vite'\n\nconst currentDir = path.dirname(fileURLToPath(import.meta.url))\nconst defaultEntryDir = path.resolve(\n currentDir,\n '..',\n '..',\n 'plugin',\n 'default-entry',\n)\nconst defaultEntryPaths = {\n client: path.resolve(defaultEntryDir, 'client'),\n server: path.resolve(defaultEntryDir, 'server'),\n}\n\nconst isInsideRouterMonoRepo =\n path.basename(path.resolve(currentDir, '../../../../')) === 'packages'\n\
|
|
1
|
+
{"version":3,"file":"vite.js","sources":["../../../src/plugin/vite.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url'\nimport {\n TanStackStartVitePluginCore,\n VITE_ENVIRONMENT_NAMES,\n} from '@tanstack/start-plugin-core'\nimport path from 'pathe'\nimport type { TanStackStartInputConfig } from '@tanstack/start-plugin-core'\nimport type { PluginOption } from 'vite'\n\nconst currentDir = path.dirname(fileURLToPath(import.meta.url))\nconst defaultEntryDir = path.resolve(\n currentDir,\n '..',\n '..',\n 'plugin',\n 'default-entry',\n)\nconst defaultEntryPaths = {\n client: path.resolve(defaultEntryDir, 'client'),\n server: path.resolve(defaultEntryDir, 'server'),\n start: path.resolve(defaultEntryDir, 'start'),\n}\n\nconst isInsideRouterMonoRepo =\n path.basename(path.resolve(currentDir, '../../../../')) === 'packages'\n\nexport function tanstackStart(\n options?: TanStackStartInputConfig,\n): Array<PluginOption> {\n return [\n {\n name: 'tanstack-react-start:config',\n configEnvironment(environmentName, options) {\n return {\n resolve: {\n dedupe: [\n 'react',\n 'react-dom',\n '@tanstack/react-start',\n '@tanstack/react-router',\n ],\n external:\n options.resolve?.noExternal === true || !isInsideRouterMonoRepo\n ? undefined\n : ['@tanstack/react-router', '@tanstack/react-router-devtools'],\n },\n optimizeDeps:\n environmentName === VITE_ENVIRONMENT_NAMES.client ||\n (environmentName === VITE_ENVIRONMENT_NAMES.server &&\n // This indicates that the server environment has opted in to dependency optimization\n options.optimizeDeps?.noDiscovery === false)\n ? {\n // As `@tanstack/react-start` depends on `@tanstack/react-router`, we should exclude both.\n exclude: [\n '@tanstack/react-start',\n '@tanstack/react-router',\n '@tanstack/react-router-devtools',\n ],\n include: [\n 'react',\n 'react/jsx-runtime',\n 'react/jsx-dev-runtime',\n 'react-dom',\n ...(environmentName === VITE_ENVIRONMENT_NAMES.client\n ? ['react-dom/client']\n : ['react-dom/server']),\n // `@tanstack/react-store` has a dependency on `use-sync-external-store`, which is CJS.\n // It therefore needs to included so that it is converted to ESM.\n '@tanstack/react-router > @tanstack/react-store',\n ],\n }\n : undefined,\n }\n },\n },\n TanStackStartVitePluginCore(\n {\n framework: 'react',\n defaultEntryPaths,\n },\n options,\n ),\n ]\n}\n"],"names":["options"],"mappings":";;;AASA,MAAM,aAAa,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAC9D,MAAM,kBAAkB,KAAK;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,oBAAoB;AAAA,EACxB,QAAQ,KAAK,QAAQ,iBAAiB,QAAQ;AAAA,EAC9C,QAAQ,KAAK,QAAQ,iBAAiB,QAAQ;AAAA,EAC9C,OAAO,KAAK,QAAQ,iBAAiB,OAAO;AAC9C;AAEA,MAAM,yBACJ,KAAK,SAAS,KAAK,QAAQ,YAAY,cAAc,CAAC,MAAM;AAEvD,SAAS,cACd,SACqB;AACrB,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,iBAAiBA,UAAS;AAC1C,eAAO;AAAA,UACL,SAAS;AAAA,YACP,QAAQ;AAAA,cACN;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,YAEF,UACEA,SAAQ,SAAS,eAAe,QAAQ,CAAC,yBACrC,SACA,CAAC,0BAA0B,iCAAiC;AAAA,UAAA;AAAA,UAEpE,cACE,oBAAoB,uBAAuB,UAC1C,oBAAoB,uBAAuB;AAAA,UAE1CA,SAAQ,cAAc,gBAAgB,QACpC;AAAA;AAAA,YAEE,SAAS;AAAA,cACP;AAAA,cACA;AAAA,cACA;AAAA,YAAA;AAAA,YAEF,SAAS;AAAA,cACP;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA,GAAI,oBAAoB,uBAAuB,SAC3C,CAAC,kBAAkB,IACnB,CAAC,kBAAkB;AAAA;AAAA;AAAA,cAGvB;AAAA,YAAA;AAAA,UACF,IAEF;AAAA,QAAA;AAAA,MAEV;AAAA,IAAA;AAAA,IAEF;AAAA,MACE;AAAA,QACE,WAAW;AAAA,QACX;AAAA,MAAA;AAAA,MAEF;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useServerFn<T extends (...deps: Array<any>) => Promise<any>>(serverFn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRouter, isRedirect } from "@tanstack/react-router";
|
|
3
|
+
function useServerFn(serverFn) {
|
|
4
|
+
const router = useRouter();
|
|
5
|
+
return React.useCallback(
|
|
6
|
+
async (...args) => {
|
|
7
|
+
try {
|
|
8
|
+
const res = await serverFn(...args);
|
|
9
|
+
if (isRedirect(res)) {
|
|
10
|
+
throw res;
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
} catch (err) {
|
|
14
|
+
if (isRedirect(err)) {
|
|
15
|
+
err.options._fromLocation = router.state.location;
|
|
16
|
+
return router.navigate(router.resolveRedirect(err).options);
|
|
17
|
+
}
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
[router, serverFn]
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
useServerFn
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=useServerFn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useServerFn.js","sources":["../../src/useServerFn.ts"],"sourcesContent":["import * as React from 'react'\nimport { isRedirect, useRouter } from '@tanstack/react-router'\n\nexport function useServerFn<T extends (...deps: Array<any>) => Promise<any>>(\n serverFn: T,\n): (...args: Parameters<T>) => ReturnType<T> {\n const router = useRouter()\n\n return React.useCallback(\n async (...args: Array<any>) => {\n try {\n const res = await serverFn(...args)\n\n if (isRedirect(res)) {\n throw res\n }\n\n return res\n } catch (err) {\n if (isRedirect(err)) {\n err.options._fromLocation = router.state.location\n return router.navigate(router.resolveRedirect(err).options)\n }\n\n throw err\n }\n },\n [router, serverFn],\n ) as any\n}\n"],"names":[],"mappings":";;AAGO,SAAS,YACd,UAC2C;AAC3C,QAAM,SAAS,UAAA;AAEf,SAAO,MAAM;AAAA,IACX,UAAU,SAAqB;AAC7B,UAAI;AACF,cAAM,MAAM,MAAM,SAAS,GAAG,IAAI;AAElC,YAAI,WAAW,GAAG,GAAG;AACnB,gBAAM;AAAA,QACR;AAEA,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,YAAI,WAAW,GAAG,GAAG;AACnB,cAAI,QAAQ,gBAAgB,OAAO,MAAM;AACzC,iBAAO,OAAO,SAAS,OAAO,gBAAgB,GAAG,EAAE,OAAO;AAAA,QAC5D;AAEA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAC,QAAQ,QAAQ;AAAA,EAAA;AAErB;"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { StrictMode, startTransition } from 'react'
|
|
2
2
|
import { hydrateRoot } from 'react-dom/client'
|
|
3
|
-
import { StartClient } from '@tanstack/react-start'
|
|
4
|
-
import { createRouter } from '#tanstack-start-router-entry'
|
|
5
|
-
|
|
6
|
-
const router = createRouter()
|
|
3
|
+
import { StartClient } from '@tanstack/react-start/client'
|
|
7
4
|
|
|
8
5
|
startTransition(() => {
|
|
9
6
|
hydrateRoot(
|
|
10
7
|
document,
|
|
11
8
|
<StrictMode>
|
|
12
|
-
<StartClient
|
|
9
|
+
<StartClient />
|
|
13
10
|
</StrictMode>,
|
|
14
11
|
)
|
|
15
12
|
})
|
|
@@ -2,13 +2,14 @@ import {
|
|
|
2
2
|
createStartHandler,
|
|
3
3
|
defaultStreamHandler,
|
|
4
4
|
} from '@tanstack/react-start/server'
|
|
5
|
+
import type { Register } from '@tanstack/react-start'
|
|
6
|
+
import type { RequestHandler } from '@tanstack/react-start/server'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fetch = createStartHandler({
|
|
9
|
-
createRouter,
|
|
10
|
-
})(defaultStreamHandler)
|
|
8
|
+
const fetch = createStartHandler(defaultStreamHandler)
|
|
11
9
|
|
|
12
10
|
export default {
|
|
13
|
-
|
|
11
|
+
// Providing `RequestHandler` from `@tanstack/react-start/server` is required so that the output types don't import it from `@tanstack/start-server-core`
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
14
|
+
fetch: fetch as RequestHandler<Register>,
|
|
14
15
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-start",
|
|
3
|
-
"version": "1.132.0
|
|
3
|
+
"version": "1.132.0",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"typescript"
|
|
25
25
|
],
|
|
26
26
|
"type": "module",
|
|
27
|
-
"types": "dist/esm/
|
|
27
|
+
"types": "dist/esm/index.d.ts",
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
30
30
|
"import": {
|
|
31
|
-
"types": "./dist/esm/
|
|
32
|
-
"default": "./dist/esm/
|
|
31
|
+
"types": "./dist/esm/index.d.ts",
|
|
32
|
+
"default": "./dist/esm/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"./client": {
|
|
@@ -50,6 +50,12 @@
|
|
|
50
50
|
"default": "./dist/esm/plugin/vite.js"
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
+
"./server-entry": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/default-entry/esm/server.d.ts",
|
|
56
|
+
"default": "./dist/default-entry/esm/server.js"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
53
59
|
"./package.json": "./package.json"
|
|
54
60
|
},
|
|
55
61
|
"sideEffects": false,
|
|
@@ -58,14 +64,16 @@
|
|
|
58
64
|
"src"
|
|
59
65
|
],
|
|
60
66
|
"engines": {
|
|
61
|
-
"node": ">=12"
|
|
67
|
+
"node": ">=22.12.0"
|
|
62
68
|
},
|
|
63
69
|
"dependencies": {
|
|
64
70
|
"pathe": "^2.0.3",
|
|
65
|
-
"@tanstack/react-start-client": "1.132.0
|
|
66
|
-
"@tanstack/react-start-server": "1.132.0
|
|
67
|
-
"@tanstack/
|
|
68
|
-
"@tanstack/
|
|
71
|
+
"@tanstack/react-start-client": "1.132.0",
|
|
72
|
+
"@tanstack/react-start-server": "1.132.0",
|
|
73
|
+
"@tanstack/start-plugin-core": "1.132.0",
|
|
74
|
+
"@tanstack/router-utils": "^1.132.0",
|
|
75
|
+
"@tanstack/react-router": "1.132.0",
|
|
76
|
+
"@tanstack/start-client-core": "1.132.0"
|
|
69
77
|
},
|
|
70
78
|
"peerDependencies": {
|
|
71
79
|
"react": ">=18.0.0 || >=19.0.0",
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { StrictMode, startTransition } from 'react'
|
|
2
2
|
import { hydrateRoot } from 'react-dom/client'
|
|
3
|
-
import { StartClient } from '@tanstack/react-start'
|
|
4
|
-
import { createRouter } from '#tanstack-start-router-entry'
|
|
5
|
-
|
|
6
|
-
const router = createRouter()
|
|
3
|
+
import { StartClient } from '@tanstack/react-start/client'
|
|
7
4
|
|
|
8
5
|
startTransition(() => {
|
|
9
6
|
hydrateRoot(
|
|
10
7
|
document,
|
|
11
8
|
<StrictMode>
|
|
12
|
-
<StartClient
|
|
9
|
+
<StartClient />
|
|
13
10
|
</StrictMode>,
|
|
14
11
|
)
|
|
15
12
|
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createStartHandler,
|
|
3
|
+
defaultStreamHandler,
|
|
4
|
+
} from '@tanstack/react-start/server'
|
|
5
|
+
import type { Register } from '@tanstack/react-start'
|
|
6
|
+
import type { RequestHandler } from '@tanstack/react-start/server'
|
|
7
|
+
|
|
8
|
+
const fetch = createStartHandler(defaultStreamHandler)
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
// Providing `RequestHandler` from `@tanstack/react-start/server` is required so that the output types don't import it from `@tanstack/start-server-core`
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
14
|
+
fetch: fetch as RequestHandler<Register>,
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default {}
|
package/src/index.ts
ADDED
package/src/plugin/vite.ts
CHANGED
|
@@ -18,59 +18,58 @@ const defaultEntryDir = path.resolve(
|
|
|
18
18
|
const defaultEntryPaths = {
|
|
19
19
|
client: path.resolve(defaultEntryDir, 'client'),
|
|
20
20
|
server: path.resolve(defaultEntryDir, 'server'),
|
|
21
|
+
start: path.resolve(defaultEntryDir, 'start'),
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
const isInsideRouterMonoRepo =
|
|
24
25
|
path.basename(path.resolve(currentDir, '../../../../')) === 'packages'
|
|
25
26
|
|
|
26
|
-
function hasRootExport(
|
|
27
|
-
exportsField?: Record<string, unknown> | string,
|
|
28
|
-
): boolean {
|
|
29
|
-
if (!exportsField) return false
|
|
30
|
-
|
|
31
|
-
if (typeof exportsField === 'string') {
|
|
32
|
-
// shorthand form: "exports": "./index.js"
|
|
33
|
-
return true
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (typeof exportsField === 'object') {
|
|
37
|
-
return '.' in exportsField
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return false
|
|
41
|
-
}
|
|
42
|
-
|
|
43
27
|
export function tanstackStart(
|
|
44
28
|
options?: TanStackStartInputConfig,
|
|
45
29
|
): Array<PluginOption> {
|
|
46
30
|
return [
|
|
47
31
|
{
|
|
48
32
|
name: 'tanstack-react-start:config',
|
|
49
|
-
configEnvironment(
|
|
33
|
+
configEnvironment(environmentName, options) {
|
|
50
34
|
return {
|
|
51
35
|
resolve: {
|
|
52
|
-
dedupe: [
|
|
53
|
-
|
|
54
|
-
external:
|
|
55
|
-
userConfig.resolve?.noExternal === true || !isInsideRouterMonoRepo
|
|
56
|
-
? undefined
|
|
57
|
-
: ['@tanstack/react-router', '@tanstack/react-router-devtools'],
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
optimizeDeps: {
|
|
61
|
-
exclude: ['@tanstack/react-router-devtools'],
|
|
62
|
-
include: [
|
|
36
|
+
dedupe: [
|
|
63
37
|
'react',
|
|
64
|
-
'react/jsx-runtime',
|
|
65
|
-
'react/jsx-dev-runtime',
|
|
66
38
|
'react-dom',
|
|
67
|
-
'react-
|
|
39
|
+
'@tanstack/react-start',
|
|
68
40
|
'@tanstack/react-router',
|
|
69
|
-
...(env === VITE_ENVIRONMENT_NAMES.server
|
|
70
|
-
? ['react-dom/server']
|
|
71
|
-
: []),
|
|
72
41
|
],
|
|
42
|
+
external:
|
|
43
|
+
options.resolve?.noExternal === true || !isInsideRouterMonoRepo
|
|
44
|
+
? undefined
|
|
45
|
+
: ['@tanstack/react-router', '@tanstack/react-router-devtools'],
|
|
73
46
|
},
|
|
47
|
+
optimizeDeps:
|
|
48
|
+
environmentName === VITE_ENVIRONMENT_NAMES.client ||
|
|
49
|
+
(environmentName === VITE_ENVIRONMENT_NAMES.server &&
|
|
50
|
+
// This indicates that the server environment has opted in to dependency optimization
|
|
51
|
+
options.optimizeDeps?.noDiscovery === false)
|
|
52
|
+
? {
|
|
53
|
+
// As `@tanstack/react-start` depends on `@tanstack/react-router`, we should exclude both.
|
|
54
|
+
exclude: [
|
|
55
|
+
'@tanstack/react-start',
|
|
56
|
+
'@tanstack/react-router',
|
|
57
|
+
'@tanstack/react-router-devtools',
|
|
58
|
+
],
|
|
59
|
+
include: [
|
|
60
|
+
'react',
|
|
61
|
+
'react/jsx-runtime',
|
|
62
|
+
'react/jsx-dev-runtime',
|
|
63
|
+
'react-dom',
|
|
64
|
+
...(environmentName === VITE_ENVIRONMENT_NAMES.client
|
|
65
|
+
? ['react-dom/client']
|
|
66
|
+
: ['react-dom/server']),
|
|
67
|
+
// `@tanstack/react-store` has a dependency on `use-sync-external-store`, which is CJS.
|
|
68
|
+
// It therefore needs to included so that it is converted to ESM.
|
|
69
|
+
'@tanstack/react-router > @tanstack/react-store',
|
|
70
|
+
],
|
|
71
|
+
}
|
|
72
|
+
: undefined,
|
|
74
73
|
}
|
|
75
74
|
},
|
|
76
75
|
},
|
|
@@ -78,15 +77,6 @@ export function tanstackStart(
|
|
|
78
77
|
{
|
|
79
78
|
framework: 'react',
|
|
80
79
|
defaultEntryPaths,
|
|
81
|
-
crawlPackages(opts) {
|
|
82
|
-
if (opts.name === '@tanstack/react-router-devtools') {
|
|
83
|
-
return 'exclude'
|
|
84
|
-
}
|
|
85
|
-
if (hasRootExport(opts.exports) && 'react' in opts.peerDependencies) {
|
|
86
|
-
return 'include'
|
|
87
|
-
}
|
|
88
|
-
return undefined
|
|
89
|
-
},
|
|
90
80
|
},
|
|
91
81
|
options,
|
|
92
82
|
),
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { isRedirect, useRouter } from '@tanstack/react-router'
|
|
3
|
+
|
|
4
|
+
export function useServerFn<T extends (...deps: Array<any>) => Promise<any>>(
|
|
5
|
+
serverFn: T,
|
|
6
|
+
): (...args: Parameters<T>) => ReturnType<T> {
|
|
7
|
+
const router = useRouter()
|
|
8
|
+
|
|
9
|
+
return React.useCallback(
|
|
10
|
+
async (...args: Array<any>) => {
|
|
11
|
+
try {
|
|
12
|
+
const res = await serverFn(...args)
|
|
13
|
+
|
|
14
|
+
if (isRedirect(res)) {
|
|
15
|
+
throw res
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return res
|
|
19
|
+
} catch (err) {
|
|
20
|
+
if (isRedirect(err)) {
|
|
21
|
+
err.options._fromLocation = router.state.location
|
|
22
|
+
return router.navigate(router.resolveRedirect(err).options)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw err
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
[router, serverFn],
|
|
29
|
+
) as any
|
|
30
|
+
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createStartHandler,
|
|
3
|
-
defaultStreamHandler,
|
|
4
|
-
} from '@tanstack/react-start/server'
|
|
5
|
-
|
|
6
|
-
import { createRouter } from '#tanstack-start-router-entry'
|
|
7
|
-
|
|
8
|
-
const fetch = createStartHandler({
|
|
9
|
-
createRouter,
|
|
10
|
-
})(defaultStreamHandler)
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
fetch,
|
|
14
|
-
}
|