diff --git a/examples/react/start-basic/src/Foo.ts b/examples/react/start-basic/src/Foo.ts deleted file mode 100644 index 6a3a36a146..0000000000 --- a/examples/react/start-basic/src/Foo.ts +++ /dev/null @@ -1,6 +0,0 @@ -export class Foo { - constructor(private value: string) {} - bar() { - return this.value - } -} diff --git a/examples/react/start-basic/src/routeTree.gen.ts b/examples/react/start-basic/src/routeTree.gen.ts index d7e1332c9a..06a64190d7 100644 --- a/examples/react/start-basic/src/routeTree.gen.ts +++ b/examples/react/start-basic/src/routeTree.gen.ts @@ -438,11 +438,10 @@ export const routeTree = rootRouteImport ._addFileTypes() import type { getRouter } from './router.tsx' -import type { startInstance } from './start.tsx' +import type { createStart } from '@tanstack/react-start' declare module '@tanstack/react-start' { interface Register { ssr: true router: Awaited> - config: Awaited> } } diff --git a/examples/react/start-basic/src/router.tsx b/examples/react/start-basic/src/router.tsx index 6773db547f..f380f73be7 100644 --- a/examples/react/start-basic/src/router.tsx +++ b/examples/react/start-basic/src/router.tsx @@ -1,5 +1,4 @@ import { createRouter } from '@tanstack/react-router' -import { getGlobalStartContext } from '@tanstack/react-start' import { routeTree } from './routeTree.gen' import { DefaultCatchBoundary } from './components/DefaultCatchBoundary' import { NotFound } from './components/NotFound' @@ -11,9 +10,6 @@ export function getRouter() { defaultErrorComponent: DefaultCatchBoundary, defaultNotFoundComponent: () => , scrollRestoration: true, - ssr: { - nonce: getGlobalStartContext()?.nonce, - }, }) return router } diff --git a/examples/react/start-basic/src/routes/__root.tsx b/examples/react/start-basic/src/routes/__root.tsx index e9c952a1f7..346409e9d9 100644 --- a/examples/react/start-basic/src/routes/__root.tsx +++ b/examples/react/start-basic/src/routes/__root.tsx @@ -9,140 +9,10 @@ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' import * as React from 'react' import { DefaultCatchBoundary } from '~/components/DefaultCatchBoundary' import { NotFound } from '~/components/NotFound' -import { Test, startInstance } from '~/start' import appCss from '~/styles/app.css?url' import { seo } from '~/utils/seo' -export const testServerMw = startInstance - .createMiddleware() - .server(({ next, context }) => { - context.fromFetch - // ^? - context.fromServerMw - // ^? - - return next({ - context: { - fromIndexServerMw: true, - }, - }) - }) - -export const testFnMw = startInstance - .createMiddleware({ type: 'function' }) - .middleware([testServerMw]) - .server(({ next, context }) => { - context.fromFetch - // ^? - context.fromServerMw - // ^? - context.fromFnMw - // ^? - context.fromIndexServerMw - // ^? - - return next({ - context: { - fromIndexFnMw: true, - }, - }) - }) - -export const testGetMiddleware = startInstance - .createMiddleware() - .server(({ next, context }) => { - return next({ - context: { - fromGetMiddleware: true, - }, - }) - }) - export const Route = createRootRoute({ - server: { - middleware: [testServerMw], - handlers: { - GET: ({ context, next }) => { - context.fromFetch - // ^? - context.fromServerMw - // ^? - context.fromIndexServerMw - // ^? - return next({ - context: { - fromGet: true, - }, - }) - }, - POST: ({ context, next }) => { - context.fromFetch - context.fromServerMw - context.fromIndexServerMw - return next({ - context: { - fromPost: true, - }, - }) - }, - }, - // handlers: ({ createHandlers }) => - // createHandlers({ - // GET: { - // middleware: [testGetMiddleware], - // handler: ({ context, next }) => { - // context.fromFetch - // // ^? - // context.fromServerMw - // // ^? - // context.fromIndexServerMw - // // ^? - // context.fromGetMiddleware - // // ^? - // return next({ - // context: { - // fromGet: true, - // fromPost: false, - // }, - // }) - // }, - // }, - // POST: { - // handler: ({ next }) => { - // return next({ - // context: { - // fromGet: false, - // fromPost: true, - // }, - // }) - // }, - // }, - // }), - test: (test) => {}, - }, - beforeLoad: ({ serverContext }) => { - serverContext?.fromFetch - // ^? - serverContext?.fromServerMw - // ^? - serverContext?.fromIndexServerMw - // ^? - serverContext?.fromGet - // ^? - return serverContext - }, - // ssr: false, - loader: ({ context }) => { - context?.fromFetch - // ^? - context?.fromServerMw - // ^? - context?.fromIndexServerMw - // ^? - context?.fromPost - // ^? - return new Test('test') - }, head: () => ({ meta: [ { diff --git a/examples/react/start-basic/src/routes/index.tsx b/examples/react/start-basic/src/routes/index.tsx index 9e9601e86d..09a907cb18 100644 --- a/examples/react/start-basic/src/routes/index.tsx +++ b/examples/react/start-basic/src/routes/index.tsx @@ -1,70 +1,6 @@ import { createFileRoute } from '@tanstack/react-router' -import { Test } from '~/start' export const Route = createFileRoute('/')({ - // server: { - // handlers: { - // GET: ({ context, next }) => { - // context.fromFetch - // // ^? - // context.fromServerMw - // // ^? - // context.fromIndexServerMw - // // ^? - // return next({ - // context: { - // fromGet: true, - // }, - // }) - // }, - // POST: ({ context, next }) => { - // context.fromFetch - // context.fromServerMw - // context.fromIndexServerMw - // return next({ - // context: { - // fromPost: true, - // }, - // }) - // }, - // }, - // // handlers: ({ createHandlers }) => - // // createHandlers({ - // // GET: { - // // middleware: [testGetMiddleware], - // // handler: ({ context, next }) => { - // // context.fromFetch - // // // ^? - // // context.fromServerMw - // // // ^? - // // context.fromIndexServerMw - // // // ^? - // // context.fromGetMiddleware - // // // ^? - // // return next({ - // // context: { - // // fromGet: true, - // // fromPost: false, - // // }, - // // }) - // // }, - // // }, - // // POST: { - // // handler: ({ next }) => { - // // return next({ - // // context: { - // // fromGet: false, - // // fromPost: true, - // // }, - // // }) - // // }, - // // }, - // // }), - // test: (test) => {}, - // }, - loader: () => { - return new Test('test') - }, component: Home, }) diff --git a/examples/react/start-basic/src/server.ts b/examples/react/start-basic/src/server.ts deleted file mode 100644 index 49256ef1e3..0000000000 --- a/examples/react/start-basic/src/server.ts +++ /dev/null @@ -1,11 +0,0 @@ -// DO NOT DELETE THIS FILE!!! -// This file is a good smoke test to make sure the custom server entry is working -import handler from '@tanstack/react-start/server-entry' - -console.log("[server-entry]: using custom server entry in 'src/server.ts'") - -export default { - fetch(request: Request) { - return handler.fetch(request, { context: { fromFetch: true } }) - }, -} diff --git a/examples/react/start-basic/src/start.tsx b/examples/react/start-basic/src/start.tsx deleted file mode 100644 index 38f083f237..0000000000 --- a/examples/react/start-basic/src/start.tsx +++ /dev/null @@ -1,114 +0,0 @@ -import { createMiddleware, createStart } from '@tanstack/react-start' -import { createSerializationAdapter } from '@tanstack/react-router' -import type { Register } from '@tanstack/react-router' - -declare module '@tanstack/react-start' { - interface Register { - server: { - requestContext: { - fromFetch: boolean - } - } - } -} - -// @manuel -export const serverMw = createMiddleware().server(({ next, context }) => { - context.fromFetch - // ^? - - const nonce = Math.random().toString(16).slice(2, 10) - console.log('nonce', nonce) - return next({ - context: { - fromServerMw: true, - nonce, - }, - }) -}) - -export const fnMw = createMiddleware({ type: 'function' }) - .middleware([serverMw]) - .server(({ next, context }) => { - context.fromFetch - // ^? - - return next({ - context: { - fromFnMw: true, - }, - }) - }) - -const serializeClass = createSerializationAdapter({ - key: 'Test', - test: (v) => v instanceof Test, - toSerializable: (v) => v.test, - fromSerializable: (v) => new Test(v), -}) - -export class Test { - constructor(public test: string) {} - init() { - return this.test - } -} - -export const startInstance = createStart(() => { - return { - defaultSsr: true, - serializationAdapters: [serializeClass], - requestMiddleware: [serverMw], - functionMiddleware: [fnMw], - } -}) - -// type configKey2 = Register['configKey'] - -// type configKey = GetRegisteredConfigKey - -// type test3 = Register[GetRegisteredConfigKey]['~types'] - -// type test = Register[GetRegisteredConfigKey] extends { -// '~types': infer TTypes -// } -// ? 'defaultSsr' extends keyof TTypes -// ? TTypes['defaultSsr'] -// : unknown -// : unknown - -// export type RegisteredConfigType = TRegister extends Register -// ? TRegister['config'] extends { -// '~types': infer TTypes -// } -// ? TKey extends keyof TTypes -// ? TTypes[TKey] -// : unknown -// : unknown -// : unknown - -// type test = RegisteredSSROption -// type test2 = RegisteredConfigType - -type test3 = Register extends { - config: infer TConfig -} - ? TConfig extends { - '~types': infer TTypes - } - ? TTypes - : unknown - : unknown - -startInstance.createMiddleware().server(({ next, context }) => { - context.fromFetch - // ^? - context.fromServerMw - // ^? - - return next({ - context: { - fromStartInstanceMw: true, - }, - }) -}) diff --git a/examples/react/start-basic/vite.config.ts b/examples/react/start-basic/vite.config.ts index 797d124a2f..c7851284b6 100644 --- a/examples/react/start-basic/vite.config.ts +++ b/examples/react/start-basic/vite.config.ts @@ -4,7 +4,6 @@ import tsConfigPaths from 'vite-tsconfig-paths' import viteReact from '@vitejs/plugin-react' export default defineConfig({ - base: '/foo/', server: { port: 3000, }, @@ -14,8 +13,6 @@ export default defineConfig({ }), tanstackStart({ srcDirectory: 'src', - start: { entry: './start.tsx' }, - server: { entry: './server.ts' }, }), viteReact(), ], diff --git a/packages/start-client-core/src/serverRoute.ts b/packages/start-client-core/src/serverRoute.ts index 2386402105..92666256ff 100644 --- a/packages/start-client-core/src/serverRoute.ts +++ b/packages/start-client-core/src/serverRoute.ts @@ -172,7 +172,6 @@ export interface RouteServerOptions< any >) > - test?: (test: Expand>) => void } declare const createHandlersSymbol: unique symbol