From b87a7a0fc13b340c60b5a96c596fea820ff66322 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Fri, 17 Feb 2023 10:52:09 -0700 Subject: [PATCH] Checkpoint --- README.md | 8 +- docs/adapters/react-router.md | 2 +- docs/api/react/Outlet.md | 3 +- docs/api/react/RouterProvider.md | 15 +- docs/api/react/createReactRouter.md | 10 +- docs/api/react/createRouteConfig.md | 6 +- docs/api/react/lazy.md | 5 +- docs/comparison.md | 4 +- docs/config.json | 4 +- docs/devtools.md | 12 +- .../custom-search-param-serialization.md | 34 +- docs/guide/data-loading.md | 14 +- docs/guide/history-types.md | 14 +- docs/guide/preloading.md | 6 +- docs/guide/routes.md | 14 +- docs/guide/type-safety.md | 2 +- docs/quick-start.md | 8 +- .../basic-ssr-generated-wip/package.json | 4 +- .../src/entry-server.tsx | 2 +- .../basic-ssr-generated-wip/src/index.tsx | 2 +- .../basic-ssr-generated-wip/src/router.tsx | 6 +- .../src/routes.generated/__root.client.tsx | 45 +- .../src/routes.generated/__root.tsx | 6 +- .../src/routes.generated/index.client.tsx | 4 +- .../src/routes.generated/index.tsx | 4 +- .../src/routes.generated/posts.client.tsx | 4 +- .../src/routes.generated/posts.tsx | 4 +- .../routes.generated/posts/$postId.client.tsx | 81 +- .../src/routes.generated/posts/$postId.tsx | 81 +- .../routes.generated/posts/index.client.tsx | 4 +- .../src/routes.generated/posts/index.tsx | 4 +- .../src/routes/__root.tsx | 4 +- .../src/routes/index.tsx | 2 +- .../src/routes/posts.tsx | 2 +- .../src/routes/posts/$postId.tsx | 2 +- .../src/routes/posts/index.tsx | 2 +- .../react/basic-ssr-streaming/package.json | 4 +- .../basic-ssr-streaming/src/entry-server.tsx | 6 +- .../react/basic-ssr-streaming/src/index.tsx | 2 +- .../react/basic-ssr-streaming/src/router.tsx | 6 +- .../basic-ssr-streaming/src/routes/__root.tsx | 4 +- .../basic-ssr-streaming/src/routes/index.tsx | 2 +- .../basic-ssr-streaming/src/routes/posts.tsx | 2 +- .../src/routes/posts/$postId.tsx | 2 +- .../src/routes/posts/index.tsx | 2 +- .../react/basic-ssr-with-html/package.json | 4 +- .../basic-ssr-with-html/src/entry-server.tsx | 2 +- .../react/basic-ssr-with-html/src/index.tsx | 2 +- .../react/basic-ssr-with-html/src/router.tsx | 6 +- .../basic-ssr-with-html/src/routes/__root.tsx | 4 +- .../basic-ssr-with-html/src/routes/index.tsx | 2 +- .../basic-ssr-with-html/src/routes/posts.tsx | 2 +- .../src/routes/posts/$postId.tsx | 2 +- .../src/routes/posts/index.tsx | 2 +- examples/react/basic-ssr/package.json | 4 +- examples/react/basic-ssr/src/entry-server.tsx | 2 +- examples/react/basic-ssr/src/index.tsx | 2 +- examples/react/basic-ssr/src/router.tsx | 6 +- .../react/basic-ssr/src/routes/__root.tsx | 4 +- examples/react/basic-ssr/src/routes/index.tsx | 2 +- examples/react/basic-ssr/src/routes/posts.tsx | 2 +- .../basic-ssr/src/routes/posts/$postId.tsx | 2 +- .../basic-ssr/src/routes/posts/index.tsx | 2 +- examples/react/basic/package.json | 4 +- examples/react/basic/src/main.tsx | 182 ++-- .../kitchen-sink-multi-file/package.json | 4 +- .../kitchen-sink-multi-file/src/main.tsx | 2 +- .../kitchen-sink-multi-file/src/mockTodos.ts | 2 +- .../kitchen-sink-multi-file/src/router.tsx | 6 +- .../src/routes/__root.tsx | 4 +- .../src/routes/authenticated/index.tsx | 2 +- .../src/routes/dashboard/dashboard.tsx | 2 +- .../src/routes/dashboard/index.tsx | 2 +- .../src/routes/dashboard/invoices/index.tsx | 2 +- .../src/routes/dashboard/invoices/invoice.tsx | 2 +- .../routes/dashboard/invoices/invoices.tsx | 2 +- .../src/routes/dashboard/users/index.tsx | 2 +- .../src/routes/dashboard/users/user.tsx | 2 +- .../src/routes/dashboard/users/users.tsx | 2 +- .../src/routes/expensive/index.tsx | 2 +- .../src/routes/index.tsx | 2 +- .../src/routes/layout/index.tsx | 2 +- .../src/routes/layout/layout-a.tsx | 2 +- .../src/routes/layout/layout-b.tsx | 2 +- .../kitchen-sink-route-gen-wip/package.json | 4 +- .../kitchen-sink-route-gen-wip/src/actions.ts | 2 +- .../kitchen-sink-route-gen-wip/src/main.tsx | 2 +- .../src/mockTodos.ts | 2 +- .../kitchen-sink-route-gen-wip/src/router.tsx | 6 +- .../src/routes/__layout.tsx | 2 +- .../src/routes/__root.tsx | 4 +- .../src/routes/authenticated.tsx | 2 +- .../src/routes/dashboard.tsx | 2 +- .../src/routes/dashboard/index.tsx | 2 +- .../src/routes/dashboard/invoices.tsx | 2 +- .../routes/dashboard/invoices/$invoiceId.tsx | 2 +- .../src/routes/dashboard/invoices/index.tsx | 2 +- .../src/routes/dashboard/users.tsx | 2 +- .../src/routes/dashboard/users/$userId.tsx | 2 +- .../src/routes/index.tsx | 2 +- .../kitchen-sink-single-file/package.json | 4 +- .../kitchen-sink-single-file/src/main.tsx | 153 ++- .../kitchen-sink-single-file/src/mockTodos.ts | 2 +- examples/react/quickstart/package.json | 4 +- examples/react/quickstart/src/main.tsx | 8 +- .../package.json | 4 +- .../src/main.tsx | 10 +- .../src/mockTodos.ts | 2 +- .../chunks/App.880c3073.mjs | 42 +- .../chunks/App.8def3af9.mjs | 42 +- .../chunks/App.f72c7d3d.mjs | 43 +- .../chunks/routeTree.2e12cfef.mjs | 886 ++++++++++-------- .../chunks/routeTree.c870053d.mjs | 886 ++++++++++-------- .../chunks/routeTree.f436718c.mjs | 886 ++++++++++-------- examples/react/with-astro-ssr/package.json | 4 +- examples/react/with-astro-ssr/src/app/App.tsx | 2 +- .../react/with-astro-ssr/src/app/router.tsx | 6 +- .../with-astro-ssr/src/app/routes/__root.tsx | 4 +- .../with-astro-ssr/src/app/routes/index.tsx | 2 +- .../with-astro-ssr/src/app/routes/posts.tsx | 2 +- .../src/app/routes/posts/$postId.tsx | 2 +- .../src/app/routes/posts/index.tsx | 2 +- examples/react/with-react-query/package.json | 4 +- examples/react/with-react-query/src/main.tsx | 12 +- .../with-trpc-react-query/client/main.tsx | 12 +- .../react/with-trpc-react-query/package.json | 4 +- examples/react/with-trpc/client/main.tsx | 10 +- examples/react/with-trpc/package.json | 4 +- examples/solid/basic/.gitignore | 2 - examples/solid/basic/README.md | 34 - examples/solid/basic/index.html | 17 - examples/solid/basic/package.json | 22 - examples/solid/basic/src/index.css | 9 - examples/solid/basic/src/index.tsx | 211 ----- examples/solid/basic/tsconfig.json | 15 - examples/solid/basic/vite.config.ts | 12 - .../solid/kitchen-sink-multi-file/.gitignore | 5 - .../solid/kitchen-sink-multi-file/README.md | 6 - .../solid/kitchen-sink-multi-file/index.html | 15 - .../kitchen-sink-multi-file/package.json | 23 - .../solid/kitchen-sink-multi-file/src/App.tsx | 130 --- .../src/actionClient.tsx | 13 - .../src/components/InvoiceFields.tsx | 27 - .../src/components/Spinner.tsx | 3 - .../kitchen-sink-multi-file/src/index.tsx | 6 - .../src/loaderClient.tsx | 22 - .../kitchen-sink-multi-file/src/mockTodos.ts | 139 --- .../kitchen-sink-multi-file/src/router.tsx | 54 -- .../src/routes/__root.tsx | 71 -- .../src/routes/authenticated/index.tsx | 85 -- .../src/routes/dashboard/dashboard.tsx | 25 - .../src/routes/dashboard/index.tsx | 64 -- .../src/routes/dashboard/invoices/index.tsx | 76 -- .../src/routes/dashboard/invoices/invoice.tsx | 157 ---- .../routes/dashboard/invoices/invoices.tsx | 67 -- .../src/routes/dashboard/users/index.tsx | 169 ---- .../src/routes/dashboard/users/user.tsx | 49 - .../src/routes/dashboard/users/users.tsx | 32 - .../src/routes/expensive/Expensive.tsx | 8 - .../src/routes/expensive/index.tsx | 9 - .../src/routes/index.tsx | 39 - .../src/routes/layout/index.tsx | 40 - .../src/routes/layout/layout-a.tsx | 16 - .../src/routes/layout/layout-b.tsx | 16 - .../kitchen-sink-multi-file/src/utils.tsx | 49 - .../kitchen-sink-multi-file/tsconfig.json | 19 - .../kitchen-sink-multi-file/vite.config.js | 12 - .../solid/with-trpc-solid-query/.gitignore | 5 - .../solid/with-trpc-solid-query/README.md | 6 - .../solid/with-trpc-solid-query/index.html | 15 - .../solid/with-trpc-solid-query/package.json | 32 - .../with-trpc-solid-query/server/server.ts | 44 - .../solid/with-trpc-solid-query/src/App.tsx | 184 ---- .../solid/with-trpc-solid-query/src/index.tsx | 6 - .../solid/with-trpc-solid-query/tsconfig.json | 15 - .../with-trpc-solid-query/vite.config.js | 12 - media/logo.svg | 2 +- package.json | 3 +- packages/loaders/src/index.ts | 213 ++--- packages/react-actions/src/index.tsx | 4 +- packages/react-loaders/src/index.tsx | 2 +- packages/react-router/package.json | 50 - packages/react-router/tsconfig.json | 12 - packages/react-store/src/index.tsx | 37 +- packages/router-cli/bin/tsr.js | 3 - packages/router-cli/package.json | 61 -- packages/router-cli/src/config.ts | 15 - packages/router-cli/src/generate.ts | 12 - packages/router-cli/src/generator.ts | 513 ---------- packages/router-cli/src/index.ts | 24 - packages/router-cli/src/transformCode.ts | 860 ----------------- packages/router-cli/src/watch.ts | 48 - packages/router-cli/tsconfig.json | 9 - .../README.md | 0 .../media/logo.sketch | Bin .../media/logo.svg | 2 +- .../media/repo-dark.png | Bin .../package.json | 6 +- .../src/Explorer.tsx | 0 .../src/devtools.tsx | 3 +- .../src/index.tsx | 0 .../src/styledComponents.ts | 0 .../src/theme.tsx | 0 .../src/useLocalStorage.ts | 0 .../src/useMediaQuery.ts | 0 .../src/utils.ts | 2 +- .../tsconfig.json | 0 packages/router/package.json | 8 +- packages/router/src/frameworks.ts | 12 - packages/router/src/index.ts | 3 +- packages/router/src/path.ts | 1 - .../src/index.tsx => router/src/react.tsx} | 159 ++-- packages/router/src/route.ts | 183 ++-- packages/router/src/routeInfo.ts | 2 + packages/router/src/routeMatch.ts | 78 +- packages/router/src/router.ts | 40 +- packages/solid-actions/package.json | 50 - packages/solid-actions/src/index.tsx | 98 -- packages/solid-actions/transform.js | 9 - packages/solid-actions/tsconfig.json | 14 - packages/solid-loaders/package.json | 50 - packages/solid-loaders/src/index.tsx | 184 ---- packages/solid-loaders/transform.js | 9 - packages/solid-loaders/tsconfig.json | 14 - packages/solid-router/package.json | 49 - packages/solid-router/src/index.tsx | 810 ---------------- packages/solid-router/transform.js | 9 - packages/solid-router/tsconfig.json | 14 - packages/solid-store/package.json | 43 - packages/solid-store/src/index.tsx | 58 -- packages/solid-store/tsconfig.json | 12 - packages/store/src/index.ts | 54 -- pnpm-lock.yaml | 551 ++++------- scripts/config.ts | 99 +- tsconfig.base.json | 4 +- tsconfig.json | 12 +- 236 files changed, 2760 insertions(+), 7657 deletions(-) delete mode 100644 examples/solid/basic/.gitignore delete mode 100644 examples/solid/basic/README.md delete mode 100644 examples/solid/basic/index.html delete mode 100644 examples/solid/basic/package.json delete mode 100644 examples/solid/basic/src/index.css delete mode 100644 examples/solid/basic/src/index.tsx delete mode 100644 examples/solid/basic/tsconfig.json delete mode 100644 examples/solid/basic/vite.config.ts delete mode 100644 examples/solid/kitchen-sink-multi-file/.gitignore delete mode 100644 examples/solid/kitchen-sink-multi-file/README.md delete mode 100644 examples/solid/kitchen-sink-multi-file/index.html delete mode 100644 examples/solid/kitchen-sink-multi-file/package.json delete mode 100644 examples/solid/kitchen-sink-multi-file/src/App.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/actionClient.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/components/InvoiceFields.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/components/Spinner.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/loaderClient.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/mockTodos.ts delete mode 100644 examples/solid/kitchen-sink-multi-file/src/router.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/__root.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/authenticated/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/dashboard.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/invoices/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoice.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoices.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/users/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/users/user.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/dashboard/users/users.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/expensive/Expensive.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/expensive/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/layout/index.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/layout/layout-a.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/routes/layout/layout-b.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/src/utils.tsx delete mode 100644 examples/solid/kitchen-sink-multi-file/tsconfig.json delete mode 100644 examples/solid/kitchen-sink-multi-file/vite.config.js delete mode 100644 examples/solid/with-trpc-solid-query/.gitignore delete mode 100644 examples/solid/with-trpc-solid-query/README.md delete mode 100644 examples/solid/with-trpc-solid-query/index.html delete mode 100644 examples/solid/with-trpc-solid-query/package.json delete mode 100644 examples/solid/with-trpc-solid-query/server/server.ts delete mode 100644 examples/solid/with-trpc-solid-query/src/App.tsx delete mode 100644 examples/solid/with-trpc-solid-query/src/index.tsx delete mode 100644 examples/solid/with-trpc-solid-query/tsconfig.json delete mode 100644 examples/solid/with-trpc-solid-query/vite.config.js delete mode 100644 packages/react-router/package.json delete mode 100644 packages/react-router/tsconfig.json delete mode 100755 packages/router-cli/bin/tsr.js delete mode 100644 packages/router-cli/package.json delete mode 100644 packages/router-cli/src/config.ts delete mode 100644 packages/router-cli/src/generate.ts delete mode 100644 packages/router-cli/src/generator.ts delete mode 100644 packages/router-cli/src/index.ts delete mode 100644 packages/router-cli/src/transformCode.ts delete mode 100644 packages/router-cli/src/watch.ts delete mode 100644 packages/router-cli/tsconfig.json rename packages/{react-router-devtools => router-devtools}/README.md (100%) rename packages/{react-router-devtools => router-devtools}/media/logo.sketch (100%) rename packages/{react-router-devtools => router-devtools}/media/logo.svg (99%) rename packages/{react-router-devtools => router-devtools}/media/repo-dark.png (100%) rename packages/{react-router-devtools => router-devtools}/package.json (88%) rename packages/{react-router-devtools => router-devtools}/src/Explorer.tsx (100%) rename packages/{react-router-devtools => router-devtools}/src/devtools.tsx (99%) rename packages/{react-router-devtools => router-devtools}/src/index.tsx (100%) rename packages/{react-router-devtools => router-devtools}/src/styledComponents.ts (100%) rename packages/{react-router-devtools => router-devtools}/src/theme.tsx (100%) rename packages/{react-router-devtools => router-devtools}/src/useLocalStorage.ts (100%) rename packages/{react-router-devtools => router-devtools}/src/useMediaQuery.ts (100%) rename packages/{react-router-devtools => router-devtools}/src/utils.ts (98%) rename packages/{react-router-devtools => router-devtools}/tsconfig.json (100%) delete mode 100644 packages/router/src/frameworks.ts rename packages/{react-router/src/index.tsx => router/src/react.tsx} (89%) delete mode 100644 packages/solid-actions/package.json delete mode 100644 packages/solid-actions/src/index.tsx delete mode 100644 packages/solid-actions/transform.js delete mode 100644 packages/solid-actions/tsconfig.json delete mode 100644 packages/solid-loaders/package.json delete mode 100644 packages/solid-loaders/src/index.tsx delete mode 100644 packages/solid-loaders/transform.js delete mode 100644 packages/solid-loaders/tsconfig.json delete mode 100644 packages/solid-router/package.json delete mode 100644 packages/solid-router/src/index.tsx delete mode 100644 packages/solid-router/transform.js delete mode 100644 packages/solid-router/tsconfig.json delete mode 100644 packages/solid-store/package.json delete mode 100644 packages/solid-store/src/index.tsx delete mode 100644 packages/solid-store/tsconfig.json diff --git a/README.md b/README.md index 9b4c8d4880..9ee9ab9510 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ #TanStack - - - - + + + + semantic-release diff --git a/docs/adapters/react-router.md b/docs/adapters/react-router.md index 8f82a3a3c7..44d94e7f7e 100644 --- a/docs/adapters/react-router.md +++ b/docs/adapters/react-router.md @@ -5,7 +5,7 @@ title: React Router You can install TanStack React Router with any [NPM](https://npmjs.com) package manager. ```sh -npm install @tanstack/react-router@beta +npm install @tanstack/router@beta ``` TanStack React Router is compatible with React v16.8+ and is currently only compatible with ReactDOM only. If you would like to contribute to the React Native adapter, please reach out to us on [Discord](https://tlinz.com/discord). diff --git a/docs/api/react/Outlet.md b/docs/api/react/Outlet.md index 169938625f..254f0b5476 100644 --- a/docs/api/react/Outlet.md +++ b/docs/api/react/Outlet.md @@ -4,8 +4,7 @@ title: Outlet --- ```tsx -import { Outlet } from '@tanstack/react-router' - +import { Outlet } from '@tanstack/router' ``` **Options** diff --git a/docs/api/react/RouterProvider.md b/docs/api/react/RouterProvider.md index 77d7d8acbd..5245a2649a 100644 --- a/docs/api/react/RouterProvider.md +++ b/docs/api/react/RouterProvider.md @@ -3,12 +3,12 @@ id: RouterProvider title: RouterProvider --- -Use the `RouterProvider` component to connect and provide a `ReactRouter` to your application: +Use the `RouterProvider` component to connect and provide a `Router` to your application: ```tsx -import { RouterProvider, ReactRouter } from '@tanstack/react-router' +import { RouterProvider, Router } from '@tanstack/router' -const router = new ReactRouter() +const router = new Router() function App() { return @@ -19,7 +19,7 @@ function App() { - `router: Router` - **Required** - - the `ReactRouter` instance to provide + - the `Router` instance to provide - `history?: BrowserHistory | MemoryHistory | HashHistory` - **Optional** - `stringifySearch?: SearchSerializer` @@ -38,7 +38,10 @@ function App() { - **Optional** - `defaultComponent?: GetFrameworkGeneric<'Component'>` - **Optional** -- `defaultErrorComponent?: GetFrameworkGeneric<'ErrorComponent'>` +- `defaultErrorComponent?: RouteComponent<{ + error: Error + info: { componentStack: string } +}>` - **Optional** - `defaultPendingComponent?: GetFrameworkGeneric<'Component'>` - **Optional** @@ -60,5 +63,3 @@ function App() { - **Optional** - `context?: TRouterContext` - **Optional** -- `loadComponent?: (component: GetFrameworkGeneric<'Component'>) => Promise` - - **Optional** diff --git a/docs/api/react/createReactRouter.md b/docs/api/react/createReactRouter.md index 4513f06d2e..4e437d9ed1 100644 --- a/docs/api/react/createReactRouter.md +++ b/docs/api/react/createReactRouter.md @@ -1,16 +1,16 @@ --- -id: ReactRouter -title: ReactRouter +id: Router +title: Router --- -use the 'ReactRouter' to create a router to provide it to the Router Provider, 'ReactRouter' takes in routes config in the options. +use the 'Router' to create a router to provide it to the Router Provider, 'Router' takes in routes config in the options. ```tsx -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' const routeConfig = rootRoute.addChildren([indexRoute]) -const router = new ReactRouter({ +const router = new Router({ routeConfig, //add other options here }) diff --git a/docs/api/react/createRouteConfig.md b/docs/api/react/createRouteConfig.md index de8814377e..4f3bed5ae3 100644 --- a/docs/api/react/createRouteConfig.md +++ b/docs/api/react/createRouteConfig.md @@ -6,7 +6,7 @@ title: route Use the 'route' to create route to pass to your Route Provider. ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' const router = new Route() ``` @@ -110,14 +110,14 @@ search: {}}) => void | ((match: {params: {}; search: {}; }) => void) | undefined) | undefined ` - This function is called when moving from an inactive state to an active one. Likewise, when moving from an active to an inactive state, the return function (if provided) is called. + This function is called when moving from an inactive state to an active one. Likewise, when moving from an active to an inactive state, the return function (if provided) is called. - `onTransition: ((match: { params: {}; search: {}; }) => void) | undefined ` - This function is called when the route remains active from one transition to the next. + This function is called when the route remains active from one transition to the next. - `parseParams: ((rawParams: Record) => Record) | undefined` diff --git a/docs/api/react/lazy.md b/docs/api/react/lazy.md index b85ef18c4d..799aad450a 100644 --- a/docs/api/react/lazy.md +++ b/docs/api/react/lazy.md @@ -4,9 +4,10 @@ title: lazy --- ```tsx -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' -export const expensiveRoute = new Route({ getParentRoute: () => rootRoute, +export const expensiveRoute = new Route({ + getParentRoute: () => rootRoute, path: 'expensive', component: lazy(() => import('./Expensive')), }) diff --git a/docs/comparison.md b/docs/comparison.md index cbd8b9cbf2..46889c83ba 100644 --- a/docs/comparison.md +++ b/docs/comparison.md @@ -62,8 +62,8 @@ Feature/Capability Key: | Deferred Loader Streaming | 🛑 | ✅ | 🔶 | | `
` API | 🛑 | ✅ | 🛑 | -[bp-tanstack-router]: https://badgen.net/bundlephobia/minzip/@tanstack/react-router@beta?label=Router -[bpl-tanstack-router]: https://bundlephobia.com/result?p=@tanstack/react-router@beta +[bp-tanstack-router]: https://badgen.net/bundlephobia/minzip/@tanstack/router@beta?label=Router +[bpl-tanstack-router]: https://bundlephobia.com/result?p=@tanstack/router@beta [bp-tanstack-loaders]: https://badgen.net/bundlephobia/minzip/@tanstack/react-loaders@beta?label=Loaders [bpl-tanstack-loaders]: https://bundlephobia.com/result?p=@tanstack/react-loaders@beta [bp-tanstack-actions]: https://badgen.net/bundlephobia/minzip/@tanstack/react-actions@beta?label=Actions diff --git a/docs/config.json b/docs/config.json index 3ab5316e42..08a0a6fc9e 100644 --- a/docs/config.json +++ b/docs/config.json @@ -137,8 +137,8 @@ "to": "api/react/RouterProvider" }, { - "label": "ReactRouter", - "to": "api/react/ReactRouter" + "label": "Router", + "to": "api/react/Router" }, { "label": "route", diff --git a/docs/devtools.md b/docs/devtools.md index 64f6c810ea..a17543bc5f 100644 --- a/docs/devtools.md +++ b/docs/devtools.md @@ -13,13 +13,13 @@ When you begin your TanStack Router journey, you'll want these devtools by your ## Installation ```sh -npm install @tanstack/react-router-devtools@beta --save +npm install @tanstack/router-devtools@beta --save ``` ## Import the Devtools ```js -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' ``` ## Only importing and using Devtools in Development @@ -32,7 +32,7 @@ const TanStackRouterDevtools = ? () => null // Render nothing in production : React.lazy(() => // Lazy load in development - import('@tanstack/react-router-devtools').then((res) => ({ + import('@tanstack/router-devtools').then((res) => ({ default: res.TanStackRouterDevtools, // For Embedded Mode // default: res.TanStackRouterDevtoolsPanel @@ -54,7 +54,7 @@ const rootRoute = new RootRoute({ ), }) -const router = new ReactRouter({ +const router = new Router({ routes: [rootRoute], }) @@ -85,7 +85,7 @@ Floating Mode will mount the devtools as a fixed, floating element in your app a Place the following code as high in your React app as you can. The closer it is to the root of the page, the better it will work! ```js -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' function App() { return ( @@ -118,7 +118,7 @@ function App() { Embedded Mode will embed the devtools as a regular component in your application. You can style it however you'd like after that! ```js -import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtoolsPanel } from '@tanstack/router-devtools' function App() { return ( diff --git a/docs/guide/custom-search-param-serialization.md b/docs/guide/custom-search-param-serialization.md index 0c27a9e209..b407efd98b 100644 --- a/docs/guide/custom-search-param-serialization.md +++ b/docs/guide/custom-search-param-serialization.md @@ -6,18 +6,14 @@ title: Custom Search Param Serialization By default, TanStack Router parses and serializes your search params automatically. Depending on your needs though, you may want to customize the serialization process. -To do so, you can [use `ReactRouter`'s `parseSearch` and `stringifySearch` options combined with the `parseSearchWith` and `stringifySearchWith` utilities](../docs/api#search-param-parsing-and-serialization). +To do so, you can [use `Router`'s `parseSearch` and `stringifySearch` options combined with the `parseSearchWith` and `stringifySearchWith` utilities](../docs/api#search-param-parsing-and-serialization). For example: We can reimplement the default parser/serializer with the following code: ```tsx -import { - ReactRouter, - parseSearchWith, - stringifySearchWith, -} from '@tanstack/react-router' +import { Router, parseSearchWith, stringifySearchWith } from '@tanstack/router' -const router = new ReactRouter({ +const router = new Router({ parseSearch: parseSearchWith(JSON.parse), stringifySearch: stringifySearchWith(JSON.stringify), }) @@ -28,13 +24,9 @@ const router = new ReactRouter({ It's common to base64 encode your search params to achieve maximum compatibility across browsers and URL unfurlers, etc. This can be done with the following code: ```tsx -import { - ReactRouter, - parseSearchWith, - stringifySearchWith, -} from '@tanstack/react-router' +import { Router, parseSearchWith, stringifySearchWith } from '@tanstack/router' -const router = new ReactRouter({ +const router = new Router({ parseSearch: parseSearchWith((value) => JSON.parse(decodeFromBinary(value))), stringifySearch: stringifySearchWith((value) => encodeToBinary(JSON.stringify(value)), @@ -66,14 +58,10 @@ export function encodeToBinary(str: string): string { [Zipson](https://jgranstrom.github.io/zipson/) is a very user-friendly and performant JSON compression library (both in runtime performance and the resulting compression performance). To compress your search params with it (which requires escaping/unescaping and base64 encoding/decoding them as well), you can use the following code: ```tsx -import { - ReactRouter, - parseSearchWith, - stringifySearchWith, -} from '@tanstack/react-router' +import { Router, parseSearchWith, stringifySearchWith } from '@tanstack/router' import { stringify, parse } from 'zipson' -const router = new ReactRouter({ +const router = new Router({ parseSearch: parseSearchWith((value) => parse(decodeURIComponent(decodeFromBinary(value))), ), @@ -107,14 +95,10 @@ export function encodeToBinary(str: string): string { [JSURL](https://github.com/Sage/jsurl) is a non-standard library that can both compress URLs while still maintaining readability. This can be done with the following code: ```tsx -import { - ReactRouter, - parseSearchWith, - stringifySearchWith, -} from '@tanstack/react-router' +import { Router, parseSearchWith, stringifySearchWith } from '@tanstack/router' import jsurl from 'jsurl' -const router = new ReactRouter({ +const router = new Router({ parseSearch: parseSearchWith(jsurl.parse), stringifySearch: stringifySearchWith(jsurl.stringify), }) diff --git a/docs/guide/data-loading.md b/docs/guide/data-loading.md index 75548763f3..faa5c1cd96 100644 --- a/docs/guide/data-loading.md +++ b/docs/guide/data-loading.md @@ -60,7 +60,7 @@ The biggest reason for calling `onLoad` every time is to notify your data loadin Here is a simple example of using `onLoad` to fetch data for a route: ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' const postsLoader = new Loader({ @@ -107,7 +107,7 @@ Using these parameters, we can do a lot of cool things. Let's take a look at a f The `params` property of the `onLoad` function is an object containing the route's path params. ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' const postLoader = new Loader({ @@ -140,7 +140,7 @@ const postRoute = new Route({ The `search` and `routeSearch` properties of the `onLoad` function are objects containing the route's search params. `search` contains _all_ of the search params including parent search params. `routeSearch` only includes specific search params from this route. In this example, we'll use zod to validate and parse the search params for `/posts/$postId` route and use them in an `onload` function and our component. ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' const postsLoader = new Loader({ @@ -181,7 +181,7 @@ The `context` and `routeContext` properties of the `onLoad` function are objects > 🧠 Context is a powerful tool for dependency injection. You can use it to inject services, loaders, and other objects into your router and routes. You can also additively pass data down the route tree at every route using a route's `getContext` option. ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' const postsLoader = new Loader({ @@ -223,7 +223,7 @@ const postsRoute = new Route({ const routeTree = rootRoute.addChildren([postsRoute]) -const router = new ReactRouter({ +const router = new Router({ routeTree, context: { // Supply our loaderClient to the whole router @@ -237,7 +237,7 @@ const router = new ReactRouter({ The `signal` property of the `onLoad` function is an [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which is cancelled when the route is unloaded or when the `onLoad` call becomes outdated. This is useful for cancelling network requests when the route is unloaded or when the route's params change. Here is an example using TanStack Loader's signal passthrough: ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' const postsLoader = new Loader({ @@ -270,7 +270,7 @@ const postsRoute = new Route({ The `prefetch` property of the `onLoad` function is a boolean which is `true` when the route is being loaded via a prefetch action. Some data loading libraries may handle prefetching differently than a standard fetch, so you may want to pass `prefetch` to your data loading library, or use it to execute the appropriate data loading logic. Here is an example using TanStack Loader and it's built-in `prefetch` flag: ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' const postsLoader = new Loader({ diff --git a/docs/guide/history-types.md b/docs/guide/history-types.md index 43007ebde9..6a65284947 100644 --- a/docs/guide/history-types.md +++ b/docs/guide/history-types.md @@ -16,10 +16,10 @@ If you need a special history instance type, You can use the history package to Each of these APIs behaves slightly differently and documentation for them can be found in the [history](https://github.com/remix-run/history) package. -Once you have a history instance, you can pass it to the `ReactRouter` constructor: +Once you have a history instance, you can pass it to the `Router` constructor: ```ts -import { createMemoryHistory, ReactRouter, route } from '@tanstack/react-router' +import { createMemoryHistory, Router, route } from '@tanstack/router' const rootRoute = new Route() @@ -29,7 +29,7 @@ const memoryHistory = createMemoryHistory({ initialEntries: ['/'], // Pass your initial url }) -const router = new ReactRouter({ routeConfig, history: memoryHistory }) +const router = new Router({ routeConfig, history: memoryHistory }) ``` ## Browser Routing @@ -41,7 +41,7 @@ The `createBrowserHistory` is the default history type. It uses the browser's hi Hash routing can be helpful if your server doesn't support rewrites to index.html for HTTP requests (among other environments that don't have a server). ```ts -import { createHashHistory, ReactRouter, route } from '@tanstack/react-router' +import { createHashHistory, Router, route } from '@tanstack/router' const rootRoute = new Route() @@ -49,7 +49,7 @@ const indexRoute = new Route({ getParentRoute: () => rootRoute, path: '/' }) const hashHistory = createHashHistory() -const router = new ReactRouter({ routeConfig, history: hashHistory }) +const router = new Router({ routeConfig, history: hashHistory }) ``` ## Memory Routing @@ -57,7 +57,7 @@ const router = new ReactRouter({ routeConfig, history: hashHistory }) Memory routing is useful in environments that are not a browser or when you do not want components to interact with the URL. ```ts -import { createMemoryHistory, ReactRouter, route } from '@tanstack/router' +import { createMemoryHistory, Router, route } from '@tanstack/router' const rootRoute = new Route() @@ -67,5 +67,5 @@ const memoryHistory = createMemoryHistory({ initialEntries: ['/'], // Pass your initial url }) -const router = new ReactRouter({ routeConfig, history: memoryHistory }) +const router = new Router({ routeConfig, history: memoryHistory }) ``` diff --git a/docs/guide/preloading.md b/docs/guide/preloading.md index a11343b17e..9b6bb7f355 100644 --- a/docs/guide/preloading.md +++ b/docs/guide/preloading.md @@ -9,7 +9,7 @@ Preloading in TanStack Router is a way to load a route before the user actually The simplest way to preload routes for your application is to set the `preload` option to `intent` for your entire router: ```tsx -import { Router } from '@tanstack/react-router' +import { Router } from '@tanstack/router' const router = new Router({ // ... @@ -24,7 +24,7 @@ This will turn on preloading by default for all `` components in your appl By default, preloading will start after **50ms** of the user hovering or touching a `` component. You can change this delay by setting the `preloadDelay` option on your router: ```tsx -import { Router } from '@tanstack/react-router' +import { Router } from '@tanstack/router' const router = new Router({ // ... @@ -41,7 +41,7 @@ Preloading is most useful when combined with your favorite data loading library. Here's an example using TanStack Loaders: ```tsx -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' const postsRoute = new Route({ getParentRoute: () => rootRoute, diff --git a/docs/guide/routes.md b/docs/guide/routes.md index 7291644d8a..5c587e7cbc 100644 --- a/docs/guide/routes.md +++ b/docs/guide/routes.md @@ -57,18 +57,18 @@ const routeTree = rootRoute.addChildren([ ## Creating a Router -Once you have a route tree, you can create a router using the framework `Router` class of your choice. For example, if you are using React, you would use call `new ReactRouter()`. Router classes take a route tree as one of their many options, and return a router instance. +Once you have a route tree, you can create a router using the framework `Router` class of your choice. For example, if you are using React, you would use call `new Router()`. Router classes take a route tree as one of their many options, and return a router instance. ```tsx -const router = new ReactRouter({ routeTree }) +const router = new Router({ routeTree }) ``` ## Registering Router Types -TanStack Router provides amazing support for TypeScript, even for things you wouldn't expect like relative navigation and even context-aware hooks! To make this possible, you must register your router type using TypeScripts' [Declaration Merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) feature. This is done by extending the `Register` interface on your framework's router module. For example, if you are using React, you would extend the `Register` interface on `@tanstack/react-router` with a `router` property that has the type of your `router` instance: +TanStack Router provides amazing support for TypeScript, even for things you wouldn't expect like relative navigation and even context-aware hooks! To make this possible, you must register your router type using TypeScripts' [Declaration Merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) feature. This is done by extending the `Register` interface on your framework's router module. For example, if you are using React, you would extend the `Register` interface on `@tanstack/router` with a `router` property that has the type of your `router` instance: ```tsx -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { // This infers the type of our router and registers it across your entire project router: typeof router @@ -81,7 +81,7 @@ With your router type registered, you'll now get type-safety across your entire ## All together now! ```ts -import { RootRoute, Route, ReactRouter } from '@tanstack/react-router' +import { RootRoute, Route, Router } from '@tanstack/router' let rootRoute = new RootRoute() const indexRoute = new Route({ getParentRoute: () => rootRoute, path: '/' }) @@ -93,9 +93,9 @@ const routeTree = rootRoute.addChildren([ blogRoute.addChildren([postRoute]), ]) -const router = new ReactRouter({ routeTree }) +const router = new Router({ routeTree }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/docs/guide/type-safety.md b/docs/guide/type-safety.md index 6c72dab0ce..63aba22fec 100644 --- a/docs/guide/type-safety.md +++ b/docs/guide/type-safety.md @@ -27,7 +27,7 @@ const router = new Router({ // ... }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/docs/quick-start.md b/docs/quick-start.md index f01e685092..a4f759d3ed 100644 --- a/docs/quick-start.md +++ b/docs/quick-start.md @@ -11,10 +11,10 @@ import { Outlet, RouterProvider, Link, - ReactRouter, + Router, Route, RootRoute, -} from '@tanstack/react-router' +} from '@tanstack/router' // Create a root route const rootRoute = new RootRoute({ @@ -62,10 +62,10 @@ function About() { const routeTree = rootRoute.addChildren([indexRoute, aboutRoute]) // Create the router using your route tree -const router = new ReactRouter({ routeTree }) +const router = new Router({ routeTree }) // Register your router for maximum type safety -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/basic-ssr-generated-wip/package.json b/examples/react/basic-ssr-generated-wip/package.json index 98a7b3b3ba..2f9171ab55 100644 --- a/examples/react/basic-ssr-generated-wip/package.json +++ b/examples/react/basic-ssr-generated-wip/package.json @@ -16,8 +16,8 @@ }, "dependencies": { "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@tanstack/router-cli": "0.0.1-beta.69", "axios": "^1.1.3", "react": "^18.2.0", diff --git a/examples/react/basic-ssr-generated-wip/src/entry-server.tsx b/examples/react/basic-ssr-generated-wip/src/entry-server.tsx index c3cdd713f7..df74382b10 100644 --- a/examples/react/basic-ssr-generated-wip/src/entry-server.tsx +++ b/examples/react/basic-ssr-generated-wip/src/entry-server.tsx @@ -1,6 +1,6 @@ import * as React from 'react' import ReactDOMServer from 'react-dom/server' -import { createMemoryHistory, Router } from '@tanstack/react-router' +import { createMemoryHistory, Router } from '@tanstack/router' import jsesc from 'jsesc' import { ServerResponse } from 'http' import { createLoaderClient } from './loaderClient' diff --git a/examples/react/basic-ssr-generated-wip/src/index.tsx b/examples/react/basic-ssr-generated-wip/src/index.tsx index 4fd8efe362..ec74f2c499 100644 --- a/examples/react/basic-ssr-generated-wip/src/index.tsx +++ b/examples/react/basic-ssr-generated-wip/src/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import { RegisteredRouter, RouterProvider } from '@tanstack/react-router' +import { RegisteredRouter, RouterProvider } from '@tanstack/router' import { LoaderClientProvider, RegisteredLoaderClient, diff --git a/examples/react/basic-ssr-generated-wip/src/router.tsx b/examples/react/basic-ssr-generated-wip/src/router.tsx index f4389efb8c..98fff160eb 100644 --- a/examples/react/basic-ssr-generated-wip/src/router.tsx +++ b/examples/react/basic-ssr-generated-wip/src/router.tsx @@ -1,5 +1,5 @@ import { RegisteredLoaderClient } from '@tanstack/react-loaders' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { loaderClient } from './loaderClient' import { routeTree } from './routeTree' @@ -7,14 +7,14 @@ export interface RouterContext { loaderClient: RegisteredLoaderClient } -export const router = new ReactRouter({ +export const router = new Router({ routeTree, context: { loaderClient, }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.client.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.client.tsx index adb7c582c5..b48635882f 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.client.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.client.tsx @@ -1,24 +1,32 @@ -import { lazy } from '@tanstack/react-router'; -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'; -import * as React from 'react'; -import { Link, Outlet, RootRoute } from '@tanstack/react-router'; -import { RouterContext } from '../router'; +import { lazy } from '@tanstack/router' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' +import * as React from 'react' +import { Link, Outlet, RootRoute } from '@tanstack/router' +import { RouterContext } from '../router' export const rootRoute = RootRoute.withRouterContext()({ - component: Root -}); + component: Root, +}) function Root() { - return <> + return ( + <>
- + Home {' '} - + Posts
@@ -26,6 +34,7 @@ function Root() { {/* Start rendering router matches */} - ; + + ) } -export { route, route as rootRoute }; \ No newline at end of file +export { route, route as rootRoute } diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.tsx index 7b5c2a78ae..d8312966ec 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/__root.tsx @@ -1,7 +1,7 @@ -import { lazy } from '@tanstack/react-router' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { lazy } from '@tanstack/router' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import * as React from 'react' -import { Link, Outlet, RootRoute } from '@tanstack/react-router' +import { Link, Outlet, RootRoute } from '@tanstack/router' import { RouterContext } from '../router' export const rootRoute = RootRoute.withRouterContext()({ component: Root, diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/index.client.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/index.client.tsx index e4a0aad180..47c9d12ae5 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/index.client.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/index.client.tsx @@ -1,6 +1,6 @@ -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' import { route as parentRoute } from './__root.client' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' export const indexRoute = new Route({ diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/index.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/index.tsx index 634aae2a1d..6f008d4162 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/index.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/index.tsx @@ -1,6 +1,6 @@ -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' import { route as parentRoute } from './__root' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' export const indexRoute = new Route({ diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.client.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.client.tsx index 3d894a96a9..eaaac684a9 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.client.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.client.tsx @@ -1,7 +1,7 @@ -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' import { route as parentRoute } from './__root.client' import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' // import { loaderClient } from '../entry-client' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.tsx index 523486f177..86dcd52f9a 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts.tsx @@ -1,7 +1,7 @@ -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' import { route as parentRoute } from './__root' import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' // import { loaderClient } from '../entry-client' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.client.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.client.tsx index 8c4b08e562..8736eefce7 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.client.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.client.tsx @@ -1,59 +1,56 @@ -import { lazy } from '@tanstack/react-router'; -import { route as parentRoute } from "../posts.client"; -import { Loader, useLoaderInstance } from '@tanstack/react-loaders'; -import { Route, useParams } from '@tanstack/react-router'; -import * as React from 'react'; -import { postsLoader, postsRoute } from '../posts'; +import { lazy } from '@tanstack/router' +import { route as parentRoute } from '../posts.client' +import { Loader, useLoaderInstance } from '@tanstack/react-loaders' +import { Route, useParams } from '@tanstack/router' +import * as React from 'react' +import { postsLoader, postsRoute } from '../posts' export type PostType = { - id: string; - title: string; - body: string; -}; + id: string + title: string + body: string +} export const postLoader = new Loader({ key: 'post', loader: async (postId: string) => { - console.log(`Fetching post with id ${postId}...`); - await new Promise(r => setTimeout(r, Math.round(Math.random() * 300))); - return fetch(`https://jsonplaceholder.typicode.com/posts/${postId}`).then(r => (r.json() as Promise)); + console.log(`Fetching post with id ${postId}...`) + await new Promise((r) => setTimeout(r, Math.round(Math.random() * 300))) + return fetch(`https://jsonplaceholder.typicode.com/posts/${postId}`).then( + (r) => r.json() as Promise, + ) }, onAllInvalidate: async () => { - await postsLoader.invalidateAll(); - } -}); + await postsLoader.invalidateAll() + }, +}) export const postIdRoute = new Route({ getParentRoute: () => postsRoute, path: '$postId', component: Post, - onLoad: async ({ - params: { - postId - }, - preload, - context - }) => context.loaderClient.getLoader({ - key: 'post' - }).load({ - variables: postId, - preload - }) -}); + onLoad: async ({ params: { postId }, preload, context }) => + context.loaderClient + .getLoader({ + key: 'post', + }) + .load({ + variables: postId, + preload, + }), +}) function Post() { + const { postId } = useParams({ + from: postIdRoute.id, + }) const { - postId - } = useParams({ - from: postIdRoute.id - }); - const { - state: { - data: post - } + state: { data: post }, } = useLoaderInstance({ key: 'post', - variables: postId - }); - return
+ variables: postId, + }) + return ( +

{post.title}

{post.body}
-
; +
+ ) } -export { route, route as postspostIdRoute }; \ No newline at end of file +export { route, route as postspostIdRoute } diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.tsx index 7a7bdfe376..678a28fb7e 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/$postId.tsx @@ -1,59 +1,56 @@ -import { lazy } from '@tanstack/react-router'; -import { route as parentRoute } from "../posts"; -import { Loader, useLoaderInstance } from '@tanstack/react-loaders'; -import { Route, useParams } from '@tanstack/react-router'; -import * as React from 'react'; -import { postsLoader, postsRoute } from '../posts'; +import { lazy } from '@tanstack/router' +import { route as parentRoute } from '../posts' +import { Loader, useLoaderInstance } from '@tanstack/react-loaders' +import { Route, useParams } from '@tanstack/router' +import * as React from 'react' +import { postsLoader, postsRoute } from '../posts' export type PostType = { - id: string; - title: string; - body: string; -}; + id: string + title: string + body: string +} export const postLoader = new Loader({ key: 'post', loader: async (postId: string) => { - console.log(`Fetching post with id ${postId}...`); - await new Promise(r => setTimeout(r, Math.round(Math.random() * 300))); - return fetch(`https://jsonplaceholder.typicode.com/posts/${postId}`).then(r => (r.json() as Promise)); + console.log(`Fetching post with id ${postId}...`) + await new Promise((r) => setTimeout(r, Math.round(Math.random() * 300))) + return fetch(`https://jsonplaceholder.typicode.com/posts/${postId}`).then( + (r) => r.json() as Promise, + ) }, onAllInvalidate: async () => { - await postsLoader.invalidateAll(); - } -}); + await postsLoader.invalidateAll() + }, +}) export const postIdRoute = new Route({ getParentRoute: () => postsRoute, path: '$postId', component: Post, - onLoad: async ({ - params: { - postId - }, - preload, - context - }) => context.loaderClient.getLoader({ - key: 'post' - }).load({ - variables: postId, - preload - }) -}); + onLoad: async ({ params: { postId }, preload, context }) => + context.loaderClient + .getLoader({ + key: 'post', + }) + .load({ + variables: postId, + preload, + }), +}) function Post() { + const { postId } = useParams({ + from: postIdRoute.id, + }) const { - postId - } = useParams({ - from: postIdRoute.id - }); - const { - state: { - data: post - } + state: { data: post }, } = useLoaderInstance({ key: 'post', - variables: postId - }); - return
+ variables: postId, + }) + return ( +

{post.title}

{post.body}
-
; +
+ ) } -export { route }; \ No newline at end of file +export { route } diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.client.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.client.tsx index 8850b40899..0e764946f1 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.client.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.client.tsx @@ -1,6 +1,6 @@ -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' import { route as parentRoute } from '../posts.client' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { postsRoute } from '../posts' export const postsIndexRoute = new Route({ diff --git a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.tsx b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.tsx index df26e505e0..94a454991d 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes.generated/posts/index.tsx @@ -1,6 +1,6 @@ -import { lazy } from '@tanstack/react-router' +import { lazy } from '@tanstack/router' import { route as parentRoute } from '../posts' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { postsRoute } from '../posts' export const postsIndexRoute = new Route({ diff --git a/examples/react/basic-ssr-generated-wip/src/routes/__root.tsx b/examples/react/basic-ssr-generated-wip/src/routes/__root.tsx index 9c5add7ce4..7c12d078ce 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes/__root.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes/__root.tsx @@ -1,6 +1,6 @@ -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import * as React from 'react' -import { Link, Outlet, RootRoute } from '@tanstack/react-router' +import { Link, Outlet, RootRoute } from '@tanstack/router' import { RouterContext } from '../router' export const rootRoute = RootRoute.withRouterContext()({ diff --git a/examples/react/basic-ssr-generated-wip/src/routes/index.tsx b/examples/react/basic-ssr-generated-wip/src/routes/index.tsx index d14cba8216..8c42554efd 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes/index.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes/index.tsx @@ -1,5 +1,5 @@ import { Route } from '../routes.generated/index' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' export const indexRoute = new Route({ diff --git a/examples/react/basic-ssr-generated-wip/src/routes/posts.tsx b/examples/react/basic-ssr-generated-wip/src/routes/posts.tsx index 9958d4771a..5e81b44d4b 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes/posts.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes/posts.tsx @@ -1,6 +1,6 @@ import { Route } from '../routes.generated/posts' import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' // import { loaderClient } from '../entry-client' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' diff --git a/examples/react/basic-ssr-generated-wip/src/routes/posts/$postId.tsx b/examples/react/basic-ssr-generated-wip/src/routes/posts/$postId.tsx index 540a079991..877f78e6bb 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes/posts/$postId.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes/posts/$postId.tsx @@ -1,6 +1,6 @@ import { Route } from '../../routes.generated/posts/$postId' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' -import { Route, useParams } from '@tanstack/react-router' +import { Route, useParams } from '@tanstack/router' import * as React from 'react' import { postsLoader, postsRoute } from '../posts' export type PostType = { diff --git a/examples/react/basic-ssr-generated-wip/src/routes/posts/index.tsx b/examples/react/basic-ssr-generated-wip/src/routes/posts/index.tsx index ac36443b9e..d0d3fd2341 100644 --- a/examples/react/basic-ssr-generated-wip/src/routes/posts/index.tsx +++ b/examples/react/basic-ssr-generated-wip/src/routes/posts/index.tsx @@ -1,5 +1,5 @@ import { Route } from '../../routes.generated/posts/index' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { postsRoute } from '../posts' export const postsIndexRoute = new Route({ diff --git a/examples/react/basic-ssr-streaming/package.json b/examples/react/basic-ssr-streaming/package.json index 56b6c9a7db..a0fd5b941b 100644 --- a/examples/react/basic-ssr-streaming/package.json +++ b/examples/react/basic-ssr-streaming/package.json @@ -13,8 +13,8 @@ }, "dependencies": { "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@tanstack/router-cli": "0.0.1-beta.69", "axios": "^1.1.3", "react": "^18.2.0", diff --git a/examples/react/basic-ssr-streaming/src/entry-server.tsx b/examples/react/basic-ssr-streaming/src/entry-server.tsx index 9d993f2610..ea948bcb54 100644 --- a/examples/react/basic-ssr-streaming/src/entry-server.tsx +++ b/examples/react/basic-ssr-streaming/src/entry-server.tsx @@ -1,10 +1,6 @@ import * as React from 'react' import ReactDOMServer from 'react-dom/server' -import { - createMemoryHistory, - Router, - RouterProvider, -} from '@tanstack/react-router' +import { createMemoryHistory, Router, RouterProvider } from '@tanstack/router' import isbot from 'isbot' import jsesc from 'jsesc' import { ServerResponse } from 'http' diff --git a/examples/react/basic-ssr-streaming/src/index.tsx b/examples/react/basic-ssr-streaming/src/index.tsx index 4fd8efe362..ec74f2c499 100644 --- a/examples/react/basic-ssr-streaming/src/index.tsx +++ b/examples/react/basic-ssr-streaming/src/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import { RegisteredRouter, RouterProvider } from '@tanstack/react-router' +import { RegisteredRouter, RouterProvider } from '@tanstack/router' import { LoaderClientProvider, RegisteredLoaderClient, diff --git a/examples/react/basic-ssr-streaming/src/router.tsx b/examples/react/basic-ssr-streaming/src/router.tsx index f4389efb8c..98fff160eb 100644 --- a/examples/react/basic-ssr-streaming/src/router.tsx +++ b/examples/react/basic-ssr-streaming/src/router.tsx @@ -1,5 +1,5 @@ import { RegisteredLoaderClient } from '@tanstack/react-loaders' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { loaderClient } from './loaderClient' import { routeTree } from './routeTree' @@ -7,14 +7,14 @@ export interface RouterContext { loaderClient: RegisteredLoaderClient } -export const router = new ReactRouter({ +export const router = new Router({ routeTree, context: { loaderClient, }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/basic-ssr-streaming/src/routes/__root.tsx b/examples/react/basic-ssr-streaming/src/routes/__root.tsx index 6158648cfb..af9354a75c 100644 --- a/examples/react/basic-ssr-streaming/src/routes/__root.tsx +++ b/examples/react/basic-ssr-streaming/src/routes/__root.tsx @@ -1,6 +1,6 @@ -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import * as React from 'react' -import { Link, Outlet, RootRoute, useRouter } from '@tanstack/react-router' +import { Link, Outlet, RootRoute, useRouter } from '@tanstack/router' import { RouterContext } from '../router' import { useHead } from '../head' diff --git a/examples/react/basic-ssr-streaming/src/routes/index.tsx b/examples/react/basic-ssr-streaming/src/routes/index.tsx index 2c4a1a6941..7e9ac4067a 100644 --- a/examples/react/basic-ssr-streaming/src/routes/index.tsx +++ b/examples/react/basic-ssr-streaming/src/routes/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' diff --git a/examples/react/basic-ssr-streaming/src/routes/posts.tsx b/examples/react/basic-ssr-streaming/src/routes/posts.tsx index f89921bb41..2ec0e84ca1 100644 --- a/examples/react/basic-ssr-streaming/src/routes/posts.tsx +++ b/examples/react/basic-ssr-streaming/src/routes/posts.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' import { useLoaderInstance } from '@tanstack/react-loaders' import { postIdRoute } from './posts/$postId' diff --git a/examples/react/basic-ssr-streaming/src/routes/posts/$postId.tsx b/examples/react/basic-ssr-streaming/src/routes/posts/$postId.tsx index f7a0276583..c3f3a91542 100644 --- a/examples/react/basic-ssr-streaming/src/routes/posts/$postId.tsx +++ b/examples/react/basic-ssr-streaming/src/routes/posts/$postId.tsx @@ -1,5 +1,5 @@ import { useLoaderInstance } from '@tanstack/react-loaders' -import { Route, useParams } from '@tanstack/react-router' +import { Route, useParams } from '@tanstack/router' import * as React from 'react' // import { loaderClient } from '../../entry-client' import { postsRoute } from '../posts' diff --git a/examples/react/basic-ssr-streaming/src/routes/posts/index.tsx b/examples/react/basic-ssr-streaming/src/routes/posts/index.tsx index 579b05edfb..aa96f1fbb5 100644 --- a/examples/react/basic-ssr-streaming/src/routes/posts/index.tsx +++ b/examples/react/basic-ssr-streaming/src/routes/posts/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { postsRoute } from '../posts' diff --git a/examples/react/basic-ssr-with-html/package.json b/examples/react/basic-ssr-with-html/package.json index 996450e1b6..d1424b4a40 100644 --- a/examples/react/basic-ssr-with-html/package.json +++ b/examples/react/basic-ssr-with-html/package.json @@ -13,8 +13,8 @@ }, "dependencies": { "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@tanstack/router-cli": "0.0.1-beta.69", "axios": "^1.1.3", "react": "^18.2.0", diff --git a/examples/react/basic-ssr-with-html/src/entry-server.tsx b/examples/react/basic-ssr-with-html/src/entry-server.tsx index 0220eb5594..e0807dc044 100644 --- a/examples/react/basic-ssr-with-html/src/entry-server.tsx +++ b/examples/react/basic-ssr-with-html/src/entry-server.tsx @@ -1,6 +1,6 @@ import * as React from 'react' import ReactDOMServer from 'react-dom/server' -import { createMemoryHistory, Router } from '@tanstack/react-router' +import { createMemoryHistory, Router } from '@tanstack/router' import jsesc from 'jsesc' import { ServerResponse } from 'http' import { createLoaderClient } from './loaderClient' diff --git a/examples/react/basic-ssr-with-html/src/index.tsx b/examples/react/basic-ssr-with-html/src/index.tsx index e70b8a3485..aa94f2c619 100644 --- a/examples/react/basic-ssr-with-html/src/index.tsx +++ b/examples/react/basic-ssr-with-html/src/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import { RegisteredRouter, RouterProvider } from '@tanstack/react-router' +import { RegisteredRouter, RouterProvider } from '@tanstack/router' import { LoaderClientProvider, RegisteredLoaderClient, diff --git a/examples/react/basic-ssr-with-html/src/router.tsx b/examples/react/basic-ssr-with-html/src/router.tsx index f4389efb8c..98fff160eb 100644 --- a/examples/react/basic-ssr-with-html/src/router.tsx +++ b/examples/react/basic-ssr-with-html/src/router.tsx @@ -1,5 +1,5 @@ import { RegisteredLoaderClient } from '@tanstack/react-loaders' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { loaderClient } from './loaderClient' import { routeTree } from './routeTree' @@ -7,14 +7,14 @@ export interface RouterContext { loaderClient: RegisteredLoaderClient } -export const router = new ReactRouter({ +export const router = new Router({ routeTree, context: { loaderClient, }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/basic-ssr-with-html/src/routes/__root.tsx b/examples/react/basic-ssr-with-html/src/routes/__root.tsx index 79632c4ed5..e5af0b8cb8 100644 --- a/examples/react/basic-ssr-with-html/src/routes/__root.tsx +++ b/examples/react/basic-ssr-with-html/src/routes/__root.tsx @@ -1,6 +1,6 @@ -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import * as React from 'react' -import { Link, Outlet, RootRoute, useRouter } from '@tanstack/react-router' +import { Link, Outlet, RootRoute, useRouter } from '@tanstack/router' import { RouterContext } from '../router' import { useHead } from '../head' diff --git a/examples/react/basic-ssr-with-html/src/routes/index.tsx b/examples/react/basic-ssr-with-html/src/routes/index.tsx index b01a039fd2..6d8a3bd6d8 100644 --- a/examples/react/basic-ssr-with-html/src/routes/index.tsx +++ b/examples/react/basic-ssr-with-html/src/routes/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' diff --git a/examples/react/basic-ssr-with-html/src/routes/posts.tsx b/examples/react/basic-ssr-with-html/src/routes/posts.tsx index 14ff5de574..82b72a3c2d 100644 --- a/examples/react/basic-ssr-with-html/src/routes/posts.tsx +++ b/examples/react/basic-ssr-with-html/src/routes/posts.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' // import { loaderClient } from '../entry-client' import { useLoaderInstance } from '@tanstack/react-loaders' diff --git a/examples/react/basic-ssr-with-html/src/routes/posts/$postId.tsx b/examples/react/basic-ssr-with-html/src/routes/posts/$postId.tsx index 9686efdf12..207f7b372a 100644 --- a/examples/react/basic-ssr-with-html/src/routes/posts/$postId.tsx +++ b/examples/react/basic-ssr-with-html/src/routes/posts/$postId.tsx @@ -5,7 +5,7 @@ import { useParams, useRouter, useRouterContext, -} from '@tanstack/react-router' +} from '@tanstack/router' import * as React from 'react' // import { loaderClient } from '../../entry-client' import { postsRoute } from '../posts' diff --git a/examples/react/basic-ssr-with-html/src/routes/posts/index.tsx b/examples/react/basic-ssr-with-html/src/routes/posts/index.tsx index 579b05edfb..aa96f1fbb5 100644 --- a/examples/react/basic-ssr-with-html/src/routes/posts/index.tsx +++ b/examples/react/basic-ssr-with-html/src/routes/posts/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { postsRoute } from '../posts' diff --git a/examples/react/basic-ssr/package.json b/examples/react/basic-ssr/package.json index 9c2922d393..56f6a6199b 100644 --- a/examples/react/basic-ssr/package.json +++ b/examples/react/basic-ssr/package.json @@ -13,8 +13,8 @@ }, "dependencies": { "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@tanstack/router-cli": "0.0.1-beta.69", "axios": "^1.1.3", "react": "^18.2.0", diff --git a/examples/react/basic-ssr/src/entry-server.tsx b/examples/react/basic-ssr/src/entry-server.tsx index 024716f28b..80074363d0 100644 --- a/examples/react/basic-ssr/src/entry-server.tsx +++ b/examples/react/basic-ssr/src/entry-server.tsx @@ -1,6 +1,6 @@ import * as React from 'react' import ReactDOMServer from 'react-dom/server' -import { createMemoryHistory, Router } from '@tanstack/react-router' +import { createMemoryHistory, Router } from '@tanstack/router' import jsesc from 'jsesc' import { ServerResponse } from 'http' import { createLoaderClient } from './loaderClient' diff --git a/examples/react/basic-ssr/src/index.tsx b/examples/react/basic-ssr/src/index.tsx index 910c563687..b0d723e54f 100644 --- a/examples/react/basic-ssr/src/index.tsx +++ b/examples/react/basic-ssr/src/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react' -import { RegisteredRouter, RouterProvider } from '@tanstack/react-router' +import { RegisteredRouter, RouterProvider } from '@tanstack/router' import { LoaderClientProvider, RegisteredLoaderClient, diff --git a/examples/react/basic-ssr/src/router.tsx b/examples/react/basic-ssr/src/router.tsx index f4389efb8c..98fff160eb 100644 --- a/examples/react/basic-ssr/src/router.tsx +++ b/examples/react/basic-ssr/src/router.tsx @@ -1,5 +1,5 @@ import { RegisteredLoaderClient } from '@tanstack/react-loaders' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { loaderClient } from './loaderClient' import { routeTree } from './routeTree' @@ -7,14 +7,14 @@ export interface RouterContext { loaderClient: RegisteredLoaderClient } -export const router = new ReactRouter({ +export const router = new Router({ routeTree, context: { loaderClient, }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/basic-ssr/src/routes/__root.tsx b/examples/react/basic-ssr/src/routes/__root.tsx index 4f1de14d76..826d6f3373 100644 --- a/examples/react/basic-ssr/src/routes/__root.tsx +++ b/examples/react/basic-ssr/src/routes/__root.tsx @@ -1,6 +1,6 @@ -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import * as React from 'react' -import { Link, Outlet, RootRoute } from '@tanstack/react-router' +import { Link, Outlet, RootRoute } from '@tanstack/router' import { RouterContext } from '../router' export const rootRoute = RootRoute.withRouterContext()({ diff --git a/examples/react/basic-ssr/src/routes/index.tsx b/examples/react/basic-ssr/src/routes/index.tsx index 2c4a1a6941..7e9ac4067a 100644 --- a/examples/react/basic-ssr/src/routes/index.tsx +++ b/examples/react/basic-ssr/src/routes/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' diff --git a/examples/react/basic-ssr/src/routes/posts.tsx b/examples/react/basic-ssr/src/routes/posts.tsx index a174097469..11bbe7b793 100644 --- a/examples/react/basic-ssr/src/routes/posts.tsx +++ b/examples/react/basic-ssr/src/routes/posts.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' // import { loaderClient } from '../entry-client' import { useLoaderInstance } from '@tanstack/react-loaders' diff --git a/examples/react/basic-ssr/src/routes/posts/$postId.tsx b/examples/react/basic-ssr/src/routes/posts/$postId.tsx index f7a0276583..c3f3a91542 100644 --- a/examples/react/basic-ssr/src/routes/posts/$postId.tsx +++ b/examples/react/basic-ssr/src/routes/posts/$postId.tsx @@ -1,5 +1,5 @@ import { useLoaderInstance } from '@tanstack/react-loaders' -import { Route, useParams } from '@tanstack/react-router' +import { Route, useParams } from '@tanstack/router' import * as React from 'react' // import { loaderClient } from '../../entry-client' import { postsRoute } from '../posts' diff --git a/examples/react/basic-ssr/src/routes/posts/index.tsx b/examples/react/basic-ssr/src/routes/posts/index.tsx index 579b05edfb..aa96f1fbb5 100644 --- a/examples/react/basic-ssr/src/routes/posts/index.tsx +++ b/examples/react/basic-ssr/src/routes/posts/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { postsRoute } from '../posts' diff --git a/examples/react/basic/package.json b/examples/react/basic/package.json index 6f5cb90794..681c488f23 100644 --- a/examples/react/basic/package.json +++ b/examples/react/basic/package.json @@ -9,10 +9,10 @@ "start": "vite" }, "dependencies": { - "@tanstack/react-router": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", "@tanstack/react-actions": "0.0.1-beta.81", "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@vitejs/plugin-react": "^1.1.3", "axios": "^1.1.3", "immer": "^9.0.15", diff --git a/examples/react/basic/src/main.tsx b/examples/react/basic/src/main.tsx index 9661daf996..cba75a6d2a 100644 --- a/examples/react/basic/src/main.tsx +++ b/examples/react/basic/src/main.tsx @@ -3,24 +3,23 @@ import ReactDOM from 'react-dom/client' import { Outlet, RouterProvider, - ReactRouter, + Router, Link, useParams, RootRoute, Route, ErrorComponent, createHashHistory, - lazy, -} from '@tanstack/react-router' + useMatch, +} from '@tanstack/router' +import { TanStackRouterDevtools } from '../../../../packages/router-devtools/build/types' +import axios from 'axios' import { - Loader, LoaderClient, + Loader, LoaderClientProvider, useLoaderInstance, } from '@tanstack/react-loaders' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' - -import axios from 'axios' type PostType = { id: string @@ -28,37 +27,44 @@ type PostType = { body: string } -const fetchPosts = server$(async () => { +const fetchPosts = async () => { console.log('Fetching posts...') await new Promise((r) => setTimeout(r, 500)) return axios .get('https://jsonplaceholder.typicode.com/posts') .then((r) => r.data.slice(0, 10)) -}) +} + +const fetchPost = async (postId: string) => { + console.log(`Fetching post with id ${postId}...`) + await new Promise((r) => setTimeout(r, 500)) + const post = await axios + .get(`https://jsonplaceholder.typicode.com/posts/${postId}`) + .then((r) => r.data) + + if (!post) { + throw new NotFoundError(postId) + } + + return post +} const postsLoader = new Loader({ - key: 'posts', - loader: fetchPosts, + fn: fetchPosts, }) const postLoader = new Loader({ - key: 'post', - loader: server$(async (postId: string) => { - console.log(`Fetching post with id ${postId}...`) - await new Promise((r) => setTimeout(r, 500)) - const post = await axios - .get(`https://jsonplaceholder.typicode.com/posts/${postId}`) - .then((r) => r.data) - - return post - }), - onAllInvalidate: async () => { - await postsLoader.invalidateAll() + fn: fetchPost, + onInvalidate: () => { + postsLoader.invalidate() }, }) const loaderClient = new LoaderClient({ - getLoaders: () => [postsLoader, postLoader], + getLoaders: () => ({ + posts: postsLoader, + post: postLoader, + }), }) declare module '@tanstack/react-loaders' { @@ -67,7 +73,11 @@ declare module '@tanstack/react-loaders' { } } -const rootRoute = new RootRoute({ +type RouterContext = { + loaderClient: typeof loaderClient +} + +const rootRoute = RootRoute.withRouterContext()({ component: () => { return ( <> @@ -114,55 +124,47 @@ const indexRoute = new Route({ const postsRoute = new Route({ getParentRoute: () => rootRoute, path: 'posts', - onLoad: ({ preload }) => - loaderClient.getLoader({ key: 'posts' }).load({ preload }), - component: lazy( - split$(() => { - const postsLoaderInstance = useLoaderInstance({ - key: postsLoader.key, - }) + onLoad: async ({ context }) => context.loaderClient.loaders.posts.load(), + component: () => { + const match = useMatch({ from: postsRoute.id }) + const postsLoader = useLoaderInstance({ + loader: match.context.loaderClient.loaders.posts, + }) - return ( -
-
    - {[ - ...postsLoaderInstance.state.data, - { id: 'i-do-not-exist', title: 'Non-existent Post' }, - ]?.map((post) => { - return ( -
  • - -
    {post.title.substring(0, 20)}
    - -
  • - ) - })} -
-
- -
- ) - }), - ), + return ( +
+
    + {[ + ...postsLoader.state.data, + { id: 'i-do-not-exist', title: 'Non-existent Post' }, + ]?.map((post) => { + return ( +
  • + +
    {post.title.substring(0, 20)}
    + +
  • + ) + })} +
+
+ +
+ ) + }, }) -const PostsIndexRoute = new Route({ +const postsIndexRoute = new Route({ getParentRoute: () => postsRoute, path: '/', - component: () => { - return ( - <> -
Select a post.
- - ) - }, + component: () =>
Select a post.
, }) class NotFoundError extends Error { @@ -176,12 +178,17 @@ class NotFoundError extends Error { const postRoute = new Route({ getParentRoute: () => postsRoute, path: '$postId', - onLoad: async ({ params: { postId } }) => { - try { - await postLoader.load({ variables: postId }) - } catch (err) { - throw new NotFoundError(postId) - } + onLoad: async ({ context: { loaderClient }, params: { postId } }) => { + await loaderClient.loaders.post.load({ + variables: postId, + }) + + // Return a hook! + return () => + useLoaderInstance({ + loader: loaderClient.loaders.post, + variables: postId, + }) }, errorComponent: ({ error }) => { if (error instanceof NotFoundError) { @@ -191,14 +198,9 @@ const postRoute = new Route({ return }, component: () => { - const { postId } = useParams({ from: postRoute.id }) - const postLoaderInstance = useLoaderInstance({ - key: postLoader.key, - variables: postId, - // strict: false, - }) - - const post = postLoaderInstance.state.data + const { + state: { data }, + } = postRoute.useLoader()() return (
@@ -210,21 +212,21 @@ const postRoute = new Route({ }) const routeTree = rootRoute.addChildren([ - postsRoute.addChildren([postRoute, PostsIndexRoute]), + postsRoute.addChildren([postRoute, postsIndexRoute]), indexRoute, ]) -const hashHistory = createHashHistory() - -// Set up a ReactRouter instance -const router = new ReactRouter({ - history: hashHistory, +// Set up a Router instance +const router = new Router({ routeTree, defaultPreload: 'intent', + context: { + loaderClient, + }, }) // Register things for typesafety -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/kitchen-sink-multi-file/package.json b/examples/react/kitchen-sink-multi-file/package.json index b2752ea7d7..eb6c1fd1bb 100644 --- a/examples/react/kitchen-sink-multi-file/package.json +++ b/examples/react/kitchen-sink-multi-file/package.json @@ -9,10 +9,10 @@ "start": "vite" }, "dependencies": { - "@tanstack/react-router": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", "@tanstack/react-loaders": "0.0.1-beta.81", "@tanstack/react-actions": "0.0.1-beta.81", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@vitejs/plugin-react": "^1.1.3", "axios": "^1.1.3", "immer": "^9.0.15", diff --git a/examples/react/kitchen-sink-multi-file/src/main.tsx b/examples/react/kitchen-sink-multi-file/src/main.tsx index 07f925ebe2..7ae46036f5 100644 --- a/examples/react/kitchen-sink-multi-file/src/main.tsx +++ b/examples/react/kitchen-sink-multi-file/src/main.tsx @@ -1,6 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom/client' -import { RouterProvider } from '@tanstack/react-router' +import { RouterProvider } from '@tanstack/router' import { LoaderClientProvider } from '@tanstack/react-loaders' import { ActionClientProvider } from '@tanstack/react-actions' diff --git a/examples/react/kitchen-sink-multi-file/src/mockTodos.ts b/examples/react/kitchen-sink-multi-file/src/mockTodos.ts index e480808758..d6ac7cef6f 100644 --- a/examples/react/kitchen-sink-multi-file/src/mockTodos.ts +++ b/examples/react/kitchen-sink-multi-file/src/mockTodos.ts @@ -1,4 +1,4 @@ -import { PickAsRequired } from '@tanstack/react-router' +import { PickAsRequired } from '@tanstack/router' import axios from 'axios' import { produce } from 'immer' import { actionDelayFn, loaderDelayFn, shuffle } from './utils' diff --git a/examples/react/kitchen-sink-multi-file/src/router.tsx b/examples/react/kitchen-sink-multi-file/src/router.tsx index ff937a3c1c..5ebe492119 100644 --- a/examples/react/kitchen-sink-multi-file/src/router.tsx +++ b/examples/react/kitchen-sink-multi-file/src/router.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { rootRoute } from './routes/__root' import { indexRoute } from './routes' @@ -39,7 +39,7 @@ const routeTree = rootRoute.addChildren([ layoutRoute.addChildren([layoutRouteA, layoutRouteB]), ]) -export const router = new ReactRouter({ +export const router = new Router({ routeTree, defaultPendingComponent: () => (
@@ -52,7 +52,7 @@ export const router = new ReactRouter({ }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/kitchen-sink-multi-file/src/routes/__root.tsx b/examples/react/kitchen-sink-multi-file/src/routes/__root.tsx index a771d5b50e..eee87db83f 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/__root.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/__root.tsx @@ -1,7 +1,7 @@ import * as React from 'react' -import { Link, Outlet, RootRoute, useRouter } from '@tanstack/react-router' +import { Link, Outlet, RootRoute, useRouter } from '@tanstack/router' import { Spinner } from '../components/Spinner' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { useLoaderClient } from '@tanstack/react-loaders' export const rootRoute = new RootRoute({ diff --git a/examples/react/kitchen-sink-multi-file/src/routes/authenticated/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/authenticated/index.tsx index 06c55fb8dd..72b8529f18 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/authenticated/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/authenticated/index.tsx @@ -1,4 +1,4 @@ -import { Outlet, Route } from '@tanstack/react-router' +import { Outlet, Route } from '@tanstack/router' import * as React from 'react' import { useAuth } from '../../main' import { rootRoute } from '../__root' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/dashboard.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/dashboard.tsx index f3653b08f2..da39adc435 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/dashboard.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/dashboard.tsx @@ -1,5 +1,5 @@ import { useLoaderInstance } from '@tanstack/react-loaders' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { dashboardRoute, invoicesLoader } from '.' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/index.tsx index 6f6f045159..4a0fb56b3f 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/index.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { fetchInvoices } from '../../mockTodos' import { rootRoute } from '../__root' import { Loader } from '@tanstack/react-loaders' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/index.tsx index e08a346ff2..8d233f3a54 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/index.tsx @@ -1,4 +1,4 @@ -import { Link, Outlet, MatchRoute, Route } from '@tanstack/react-router' +import { Link, Outlet, MatchRoute, Route } from '@tanstack/router' import * as React from 'react' import { Spinner } from '../../../components/Spinner' import { dashboardRoute, invoicesLoader } from '..' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoice.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoice.tsx index 9d3fce4dc8..156fca01af 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoice.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoice.tsx @@ -9,7 +9,7 @@ import { Link, useParams, Route, -} from '@tanstack/react-router' +} from '@tanstack/router' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' import { Action, useAction } from '@tanstack/react-actions' import { invoicesLoader } from '..' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoices.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoices.tsx index bf6fea03f5..0c4cc82236 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoices.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/invoices/invoices.tsx @@ -4,7 +4,7 @@ import { InvoiceFields } from '../../../components/InvoiceFields' import { invoicesRoute } from '.' import { Action, useAction } from '@tanstack/react-actions' import { invoicesLoader } from '..' -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' export const createInvoiceAction = new Action({ key: 'createInvoice', diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/index.tsx index 1faeafa475..5821589d43 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/index.tsx @@ -6,7 +6,7 @@ import { useMatch, useNavigate, useSearch, -} from '@tanstack/react-router' +} from '@tanstack/router' import * as React from 'react' import { z } from 'zod' import { Spinner } from '../../../components/Spinner' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/user.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/user.tsx index ac9feb7e47..13e1738926 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/user.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/user.tsx @@ -2,7 +2,7 @@ import * as React from 'react' import { fetchUserById } from '../../../mockTodos' import { usersRoute } from '.' import { Loader, useLoaderInstance } from '@tanstack/react-loaders' -import { Route, useParams } from '@tanstack/react-router' +import { Route, useParams } from '@tanstack/router' import { loaderClient } from '../../../loaderClient' export const userLoader = new Loader({ diff --git a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/users.tsx b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/users.tsx index dd72a7f9aa..c7a5df6261 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/users.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/dashboard/users/users.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { usersRoute } from '.' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/expensive/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/expensive/index.tsx index 2b7a4af8c1..0f8f0a5b7b 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/expensive/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/expensive/index.tsx @@ -1,4 +1,4 @@ -import { lazy, Route } from '@tanstack/react-router' +import { lazy, Route } from '@tanstack/router' import { loaderDelayFn } from '../../utils' import { rootRoute } from '../__root' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/index.tsx index 5e1350beb7..7a1e75a62a 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/index.tsx @@ -1,4 +1,4 @@ -import { Link, Route } from '@tanstack/react-router' +import { Link, Route } from '@tanstack/router' import * as React from 'react' import { rootRoute } from './__root' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/layout/index.tsx b/examples/react/kitchen-sink-multi-file/src/routes/layout/index.tsx index d96fb98aa5..8b7adee826 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/layout/index.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/layout/index.tsx @@ -1,5 +1,5 @@ import { Loader, useLoaderInstance } from '@tanstack/react-loaders' -import { Outlet, Route } from '@tanstack/react-router' +import { Outlet, Route } from '@tanstack/router' import * as React from 'react' import { fetchRandomNumber } from '../../mockTodos' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-a.tsx b/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-a.tsx index 97db4c2666..0daaada319 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-a.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-a.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { layoutRoute } from '.' diff --git a/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-b.tsx b/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-b.tsx index cde681dd49..98ee8b6d58 100644 --- a/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-b.tsx +++ b/examples/react/kitchen-sink-multi-file/src/routes/layout/layout-b.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import * as React from 'react' import { layoutRoute } from '.' diff --git a/examples/react/kitchen-sink-route-gen-wip/package.json b/examples/react/kitchen-sink-route-gen-wip/package.json index c3b9def831..dfdba79c2f 100644 --- a/examples/react/kitchen-sink-route-gen-wip/package.json +++ b/examples/react/kitchen-sink-route-gen-wip/package.json @@ -9,9 +9,9 @@ "start": "vite" }, "dependencies": { - "@tanstack/react-router": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@tanstack/router-cli": "0.0.1-beta.69", "@vitejs/plugin-react": "^1.1.3", "axios": "^1.1.3", diff --git a/examples/react/kitchen-sink-route-gen-wip/src/actions.ts b/examples/react/kitchen-sink-route-gen-wip/src/actions.ts index bda383e2ce..521209e331 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/actions.ts +++ b/examples/react/kitchen-sink-route-gen-wip/src/actions.ts @@ -1,4 +1,4 @@ -import { Action } from '@tanstack/react-router' +import { Action } from '@tanstack/router' import { patchInvoice, postInvoice } from './mockTodos' import { router } from './router' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/main.tsx b/examples/react/kitchen-sink-route-gen-wip/src/main.tsx index 46a994ad95..e066db43b4 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/main.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/main.tsx @@ -1,6 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom/client' -import { RouterProvider } from '@tanstack/react-router' +import { RouterProvider } from '@tanstack/router' import { router } from './router' import { useSessionStorage } from './utils' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/mockTodos.ts b/examples/react/kitchen-sink-route-gen-wip/src/mockTodos.ts index 414a19a8dd..8d07147df9 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/mockTodos.ts +++ b/examples/react/kitchen-sink-route-gen-wip/src/mockTodos.ts @@ -1,4 +1,4 @@ -import { PickAsRequired } from '@tanstack/react-router' +import { PickAsRequired } from '@tanstack/router' import { actionDelayFn, loaderDelayFn, shuffle } from './utils' export type Invoice = { id: number diff --git a/examples/react/kitchen-sink-route-gen-wip/src/router.tsx b/examples/react/kitchen-sink-route-gen-wip/src/router.tsx index 5077550fff..8e71467519 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/router.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/router.tsx @@ -1,10 +1,10 @@ import * as React from 'react' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { routeConfig } from './routes.generated/routeConfig' import { Spinner } from './components/Spinner' -export const router = new ReactRouter({ +export const router = new Router({ routeConfig: routeConfig, defaultPreload: 'intent', // useServerData: true, @@ -15,7 +15,7 @@ export const router = new ReactRouter({ ), }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/__layout.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/__layout.tsx index 9174c64eed..982dee4813 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/__layout.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/__layout.tsx @@ -1,5 +1,5 @@ import { routeConfig } from '../routes.generated/__layout' -import { Outlet, useLoaderInstance, useMatch } from '@tanstack/react-router' +import { Outlet, useLoaderInstance, useMatch } from '@tanstack/router' import * as React from 'react' import { loaderDelayFn } from '../utils' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/__root.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/__root.tsx index 6aca29fe2d..2cab547a5d 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/__root.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/__root.tsx @@ -1,7 +1,7 @@ import * as React from 'react' -import { route, Link, Outlet, useRouter } from '@tanstack/react-router' +import { route, Link, Outlet, useRouter } from '@tanstack/router' import { Spinner } from '../components/Spinner' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' route({ component: () => { diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/authenticated.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/authenticated.tsx index b220918cef..9ea95d2610 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/authenticated.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/authenticated.tsx @@ -1,4 +1,4 @@ -import { Outlet } from '@tanstack/react-router' +import { Outlet } from '@tanstack/router' import * as React from 'react' import { useAuth } from '../main' import { routeConfig } from '../routes.generated/authenticated' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard.tsx index a524e66a50..2e163d6485 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { Link, Outlet } from '@tanstack/react-router' +import { Link, Outlet } from '@tanstack/router' import { fetchInvoices } from '../mockTodos' import { routeConfig } from '../routes.generated/dashboard' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/index.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/index.tsx index be4c4913fb..251f67a0f0 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/index.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/index.tsx @@ -1,4 +1,4 @@ -import { useLoaderInstance, useMatch } from '@tanstack/react-router' +import { useLoaderInstance, useMatch } from '@tanstack/router' import * as React from 'react' import { routeConfig } from '../../routes.generated/dashboard/index' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices.tsx index 79562ea93b..ba50097712 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices.tsx @@ -6,7 +6,7 @@ import { useLoaderInstance, useMatch, useRoute, -} from '@tanstack/react-router' +} from '@tanstack/router' import * as React from 'react' import { createInvoiceAction, updateInvoiceAction } from '../../actions' import { Spinner } from '../../components/Spinner' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/$invoiceId.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/$invoiceId.tsx index 520a304cf8..5c06d9b46b 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/$invoiceId.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/$invoiceId.tsx @@ -8,7 +8,7 @@ import { useLoaderInstance, useNavigate, useSearch, -} from '@tanstack/react-router' +} from '@tanstack/router' import { routeConfig } from '../../../routes.generated/dashboard/invoices/$invoiceId' import { updateInvoiceAction } from '../../../actions' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/index.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/index.tsx index c9980b3941..8d2b639e3e 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/index.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/invoices/index.tsx @@ -2,7 +2,7 @@ import { routeConfig } from '../../../routes.generated/dashboard/invoices/index' import * as React from 'react' import { Invoice } from '../../../mockTodos' import { InvoiceFields } from '../../../components/InvoiceFields' -import { useAction } from '@tanstack/react-router' +import { useAction } from '@tanstack/router' import { createInvoiceAction } from '../../../actions' routeConfig.generate({ diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users.tsx index f6b67161f7..4cab48f05c 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users.tsx @@ -5,7 +5,7 @@ import { useLoaderInstance, useNavigate, useSearch, -} from '@tanstack/react-router' +} from '@tanstack/router' import * as React from 'react' import { z } from 'zod' import { Spinner } from '../../components/Spinner' diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users/$userId.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users/$userId.tsx index 8517301e74..9b324f3abd 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users/$userId.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/dashboard/users/$userId.tsx @@ -1,7 +1,7 @@ import * as React from 'react' import { fetchUserById } from '../../../mockTodos' import { routeConfig } from '../../../routes.generated/dashboard/users/$userId' -import { useLoaderInstance, useMatch } from '@tanstack/react-router' +import { useLoaderInstance, useMatch } from '@tanstack/router' routeConfig.generate({ parseParams: ({ userId }) => ({ diff --git a/examples/react/kitchen-sink-route-gen-wip/src/routes/index.tsx b/examples/react/kitchen-sink-route-gen-wip/src/routes/index.tsx index a24e05fd2b..11d9ec3b39 100644 --- a/examples/react/kitchen-sink-route-gen-wip/src/routes/index.tsx +++ b/examples/react/kitchen-sink-route-gen-wip/src/routes/index.tsx @@ -1,4 +1,4 @@ -import { Link } from '@tanstack/react-router' +import { Link } from '@tanstack/router' import * as React from 'react' import { fetchUsers } from '../mockTodos' import { routeConfig } from '../routes.generated/index' diff --git a/examples/react/kitchen-sink-single-file/package.json b/examples/react/kitchen-sink-single-file/package.json index 6c4a8dbfaf..2df9541b09 100644 --- a/examples/react/kitchen-sink-single-file/package.json +++ b/examples/react/kitchen-sink-single-file/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-loaders": "0.0.1-beta.81", "@tanstack/react-actions": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@vitejs/plugin-react": "^1.1.3", "axios": "^1.1.3", "immer": "^9.0.15", diff --git a/examples/react/kitchen-sink-single-file/src/main.tsx b/examples/react/kitchen-sink-single-file/src/main.tsx index 227462411b..f5737ba80b 100644 --- a/examples/react/kitchen-sink-single-file/src/main.tsx +++ b/examples/react/kitchen-sink-single-file/src/main.tsx @@ -8,11 +8,11 @@ import { MatchRoute, useNavigate, useSearch, - ReactRouter, + Router, useParams, RootRoute, Route, -} from '@tanstack/react-router' +} from '@tanstack/router' import { Action, ActionClient, @@ -26,7 +26,7 @@ import { useLoaderClient, LoaderClientProvider, } from '@tanstack/react-loaders' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { fetchInvoices, @@ -571,6 +571,149 @@ const invoiceRoute = new Route({ }, }) +const usersRoute = new Route({ + getParentRoute: () => dashboardRoute, + path: 'users', + onLoad: ({ preload }) => usersLoader.load({ preload }), + validateSearch: z.object({ + usersView: z + .object({ + sortBy: z.enum(['name', 'id', 'email']).optional(), + filterBy: z.string().optional(), + }) + .optional(), + }).parse, + preSearchFilters: [ + // Persist (or set as default) the usersView search param + // while navigating within or to this route (or it's children!) + (search) => ({ + ...search, + usersView: { + ...search.usersView, + }, + }), + ], + component: () => { + const usersLoaderInstance = useLoaderInstance({ key: usersLoader.key }) + const users = usersLoaderInstance.state.data + + const { usersView } = useSearch({ from: usersRoute.id }) + const navigate = useNavigate({ from: usersRoute.id }) + + const sortBy = usersView?.sortBy ?? 'name' + const filterBy = usersView?.filterBy + + const [filterDraft, setFilterDraft] = React.useState(filterBy ?? '') + + const sortedUsers = React.useMemo(() => { + if (!users) return [] + + return !sortBy + ? users + : [...users].sort((a, b) => { + return a[sortBy] > b[sortBy] ? 1 : -1 + }) + }, [users, sortBy]) + + const filteredUsers = React.useMemo(() => { + if (!filterBy) return sortedUsers + + return sortedUsers.filter((user) => + user.name.toLowerCase().includes(filterBy.toLowerCase()), + ) + }, [sortedUsers, filterBy]) + + const setSortBy = (sortBy: UsersViewSortBy) => + navigate({ + search: (old) => { + return { + ...old, + usersView: { + ...(old?.usersView ?? {}), + sortBy, + }, + } + }, + replace: true, + }) + + React.useEffect(() => { + navigate({ + search: (old) => { + return { + ...old, + usersView: { + ...old?.usersView, + filterBy: filterDraft || undefined, + }, + } + }, + replace: true, + }) + }, [filterDraft]) + + return ( +
+
+
+
Sort By:
+ +
+
+
Filter By:
+ setFilterDraft(e.target.value)} + placeholder="Search Names..." + className="min-w-0 flex-1 border p-1 px-2 rounded" + /> +
+ {filteredUsers?.map((user) => { + return ( +
+ ({ + ...d, + userId: user.id, + })} + className="block py-2 px-3 text-blue-700" + activeProps={{ className: `font-bold` }} + > +
+                    {user.name}{' '}
+                     ({
+                        ...d,
+                        userId: user.id,
+                      })}
+                      pending
+                    >
+                      
+                    
+                  
+ +
+ ) + })} +
+
+ +
+
+ ) + }, +}) + const usersIndexRoute = new Route({ getParentRoute: () => usersRoute, path: '/', @@ -791,7 +934,7 @@ const routeTree = rootRoute.addChildren([ layoutRoute.addChildren([layoutARoute, layoutBRoute]), ]) -const router = new ReactRouter({ +const router = new Router({ routeTree, defaultPendingComponent: () => (
@@ -806,7 +949,7 @@ const router = new ReactRouter({ }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/kitchen-sink-single-file/src/mockTodos.ts b/examples/react/kitchen-sink-single-file/src/mockTodos.ts index a12c67b1dd..38df40e333 100644 --- a/examples/react/kitchen-sink-single-file/src/mockTodos.ts +++ b/examples/react/kitchen-sink-single-file/src/mockTodos.ts @@ -1,4 +1,4 @@ -import { PickAsPartial, PickAsRequired } from '@tanstack/react-router' +import { PickAsPartial, PickAsRequired } from '@tanstack/router' import { match } from 'assert' import axios from 'axios' import { produce } from 'immer' diff --git a/examples/react/quickstart/package.json b/examples/react/quickstart/package.json index 3ccdaba44a..ddb16f19bc 100644 --- a/examples/react/quickstart/package.json +++ b/examples/react/quickstart/package.json @@ -9,8 +9,8 @@ "start": "vite" }, "dependencies": { - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@vitejs/plugin-react": "^1.1.3", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/examples/react/quickstart/src/main.tsx b/examples/react/quickstart/src/main.tsx index b02626c2dc..339135e1c8 100644 --- a/examples/react/quickstart/src/main.tsx +++ b/examples/react/quickstart/src/main.tsx @@ -4,10 +4,10 @@ import { Outlet, RouterProvider, Link, - ReactRouter, + Router, Route, RootRoute, -} from '@tanstack/react-router' +} from '@tanstack/router' const rootRoute = new RootRoute({ component: () => ( @@ -35,9 +35,9 @@ const aboutRoute = new Route({ const routeTree = rootRoute.addChildren([indexRoute, aboutRoute]) -const router = new ReactRouter({ routeTree }) +const router = new Router({ routeTree }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/start-kitchen-sink-single-file/package.json b/examples/react/start-kitchen-sink-single-file/package.json index 73ded94cea..707139a682 100644 --- a/examples/react/start-kitchen-sink-single-file/package.json +++ b/examples/react/start-kitchen-sink-single-file/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-loaders": "0.0.1-beta.81", "@tanstack/react-actions": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@vitejs/plugin-react": "^1.1.3", "axios": "^1.1.3", "immer": "^9.0.15", diff --git a/examples/react/start-kitchen-sink-single-file/src/main.tsx b/examples/react/start-kitchen-sink-single-file/src/main.tsx index 04833ae737..f5737ba80b 100644 --- a/examples/react/start-kitchen-sink-single-file/src/main.tsx +++ b/examples/react/start-kitchen-sink-single-file/src/main.tsx @@ -8,11 +8,11 @@ import { MatchRoute, useNavigate, useSearch, - ReactRouter, + Router, useParams, RootRoute, Route, -} from '@tanstack/react-router' +} from '@tanstack/router' import { Action, ActionClient, @@ -26,7 +26,7 @@ import { useLoaderClient, LoaderClientProvider, } from '@tanstack/react-loaders' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { fetchInvoices, @@ -934,7 +934,7 @@ const routeTree = rootRoute.addChildren([ layoutRoute.addChildren([layoutARoute, layoutBRoute]), ]) -const router = new ReactRouter({ +const router = new Router({ routeTree, defaultPendingComponent: () => (
@@ -949,7 +949,7 @@ const router = new ReactRouter({ }, }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/start-kitchen-sink-single-file/src/mockTodos.ts b/examples/react/start-kitchen-sink-single-file/src/mockTodos.ts index a12c67b1dd..38df40e333 100644 --- a/examples/react/start-kitchen-sink-single-file/src/mockTodos.ts +++ b/examples/react/start-kitchen-sink-single-file/src/mockTodos.ts @@ -1,4 +1,4 @@ -import { PickAsPartial, PickAsRequired } from '@tanstack/react-router' +import { PickAsPartial, PickAsRequired } from '@tanstack/router' import { match } from 'assert' import axios from 'axios' import { produce } from 'immer' diff --git a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.880c3073.mjs b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.880c3073.mjs index bb41f97840..09058f1566 100644 --- a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.880c3073.mjs +++ b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.880c3073.mjs @@ -1,18 +1,26 @@ -import { _ as __astro_tag_component__, H as Hydrate } from './Hydrate.ff008fd4.mjs'; -import { R as ReactRouter, r as routeTree, L as LoaderClientProvider, a as RouterProvider } from './routeTree.2e12cfef.mjs'; -import { loaderClient } from './loaderClient.1e71ba34.mjs'; -import { jsx } from 'react/jsx-runtime'; -import 'react'; -import 'jsesc'; -import 'use-sync-external-store/shim/with-selector.js'; +import { + _ as __astro_tag_component__, + H as Hydrate, +} from './Hydrate.ff008fd4.mjs' +import { + R as Router, + r as routeTree, + L as LoaderClientProvider, + a as RouterProvider, +} from './routeTree.2e12cfef.mjs' +import { loaderClient } from './loaderClient.1e71ba34.mjs' +import { jsx } from 'react/jsx-runtime' +import 'react' +import 'jsesc' +import 'use-sync-external-store/shim/with-selector.js' -const router = new ReactRouter({ +const router = new Router({ routeTree, context: { - loaderClient + loaderClient, }, - defaultPreload: "intent" -}); + defaultPreload: 'intent', +}) function App() { return /* @__PURE__ */ jsx(Hydrate, { @@ -21,11 +29,11 @@ function App() { children: /* @__PURE__ */ jsx(LoaderClientProvider, { loaderClient, children: /* @__PURE__ */ jsx(RouterProvider, { - router - }) - }) - }); + router, + }), + }), + }) } -__astro_tag_component__(App, "@astrojs/react"); +__astro_tag_component__(App, '@astrojs/react') -export { App }; +export { App } diff --git a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.8def3af9.mjs b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.8def3af9.mjs index 2704395d04..c841a6124d 100644 --- a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.8def3af9.mjs +++ b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.8def3af9.mjs @@ -1,18 +1,26 @@ -import { _ as __astro_tag_component__, H as Hydrate } from './Hydrate.f13f5eaa.mjs'; -import { R as ReactRouter, r as routeTree, L as LoaderClientProvider, a as RouterProvider } from './routeTree.c870053d.mjs'; -import { loaderClient } from './loaderClient.a6c93954.mjs'; -import { jsx } from 'react/jsx-runtime'; -import 'react'; -import 'jsesc'; -import 'use-sync-external-store/shim/with-selector.js'; +import { + _ as __astro_tag_component__, + H as Hydrate, +} from './Hydrate.f13f5eaa.mjs' +import { + R as Router, + r as routeTree, + L as LoaderClientProvider, + a as RouterProvider, +} from './routeTree.c870053d.mjs' +import { loaderClient } from './loaderClient.a6c93954.mjs' +import { jsx } from 'react/jsx-runtime' +import 'react' +import 'jsesc' +import 'use-sync-external-store/shim/with-selector.js' -const router = new ReactRouter({ +const router = new Router({ routeTree, context: { - loaderClient + loaderClient, }, - defaultPreload: "intent" -}); + defaultPreload: 'intent', +}) function App() { return /* @__PURE__ */ jsx(Hydrate, { @@ -21,11 +29,11 @@ function App() { children: /* @__PURE__ */ jsx(LoaderClientProvider, { loaderClient, children: /* @__PURE__ */ jsx(RouterProvider, { - router - }) - }) - }); + router, + }), + }), + }) } -__astro_tag_component__(App, "@astrojs/react"); +__astro_tag_component__(App, '@astrojs/react') -export { App }; +export { App } diff --git a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.f72c7d3d.mjs b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.f72c7d3d.mjs index f05e56c946..c24c93b60b 100644 --- a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.f72c7d3d.mjs +++ b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/App.f72c7d3d.mjs @@ -1,20 +1,25 @@ -import { H as Hydrate, _ as __astro_tag_component__ } from '../entry.mjs'; -import { R as ReactRouter, r as routeTree, L as LoaderClientProvider, a as RouterProvider } from './routeTree.f436718c.mjs'; -import { loaderClient } from './loaderClient.50d6b99a.mjs'; -import { jsx } from 'react/jsx-runtime'; -import '@astrojs/netlify/netlify-functions.js'; -import 'react'; -import 'react-dom/server'; -import 'jsesc'; -import 'use-sync-external-store/shim/with-selector.js'; +import { H as Hydrate, _ as __astro_tag_component__ } from '../entry.mjs' +import { + R as Router, + r as routeTree, + L as LoaderClientProvider, + a as RouterProvider, +} from './routeTree.f436718c.mjs' +import { loaderClient } from './loaderClient.50d6b99a.mjs' +import { jsx } from 'react/jsx-runtime' +import '@astrojs/netlify/netlify-functions.js' +import 'react' +import 'react-dom/server' +import 'jsesc' +import 'use-sync-external-store/shim/with-selector.js' -const router = new ReactRouter({ +const router = new Router({ routeTree, context: { - loaderClient + loaderClient, }, - defaultPreload: "intent" -}); + defaultPreload: 'intent', +}) function App() { return /* @__PURE__ */ jsx(Hydrate, { @@ -23,11 +28,11 @@ function App() { children: /* @__PURE__ */ jsx(LoaderClientProvider, { loaderClient, children: /* @__PURE__ */ jsx(RouterProvider, { - router - }) - }) - }); + router, + }), + }), + }) } -__astro_tag_component__(App, "@astrojs/react"); +__astro_tag_component__(App, '@astrojs/react') -export { App }; +export { App } diff --git a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.2e12cfef.mjs b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.2e12cfef.mjs index c216434bf3..8691437139 100644 --- a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.2e12cfef.mjs +++ b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.2e12cfef.mjs @@ -1,7 +1,16 @@ -import { s as shallow, i as invariant, R as Router, l as last, f as functionalUpdate, a as RootRoute, b as RouterScripts, c as Route } from './Hydrate.ff008fd4.mjs'; -import * as React from 'react'; -import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'; -import { jsx, jsxs } from 'react/jsx-runtime'; +import { + s as shallow, + i as invariant, + R as Router, + l as last, + f as functionalUpdate, + a as RootRoute, + b as RouterScripts, + c as Route, +} from './Hydrate.ff008fd4.mjs' +import * as React from 'react' +import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js' +import { jsx, jsxs } from 'react/jsx-runtime' /** * react-store @@ -14,9 +23,15 @@ import { jsx, jsxs } from 'react/jsx-runtime'; * @license MIT */ -function useStore(store, selector = d => d, compareShallow) { - const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined); - return slice; +function useStore(store, selector = (d) => d, compareShallow) { + const slice = useSyncExternalStoreWithSelector( + store.subscribe, + () => store.state, + () => store.state, + selector, + compareShallow ? shallow : undefined, + ) + return slice } /** @@ -32,19 +47,19 @@ function useStore(store, selector = d => d, compareShallow) { // -const loaderClientContext = /*#__PURE__*/React.createContext(null); -function LoaderClientProvider({ - loaderClient, - children, - ...rest -}) { +const loaderClientContext = /*#__PURE__*/ React.createContext(null) +function LoaderClientProvider({ loaderClient, children, ...rest }) { loaderClient.options = { ...loaderClient.options, - ...rest - }; - return /*#__PURE__*/React.createElement(loaderClientContext.Provider, { - value: loaderClient - }, children); + ...rest, + } + return /*#__PURE__*/ React.createElement( + loaderClientContext.Provider, + { + value: loaderClient, + }, + children, + ) } function useLoaderInstance(opts) { // opts as typeof opts & { @@ -52,49 +67,57 @@ function useLoaderInstance(opts) { // loader?: Loader // } - const loaderClient = React.useContext(loaderClientContext); - const optsKey = opts.key; - const optsLoader = opts.loader; - invariant(loaderClient || optsLoader, 'useLoaderInstance must be used inside a component!'); - const loader = optsLoader ?? loaderClient.getLoader({ - key: optsKey - }); + const loaderClient = React.useContext(loaderClientContext) + const optsKey = opts.key + const optsLoader = opts.loader + invariant( + loaderClient || optsLoader, + 'useLoaderInstance must be used inside a component!', + ) + const loader = + optsLoader ?? + loaderClient.getLoader({ + key: optsKey, + }) const loaderInstance = loader.getInstance({ - variables: opts?.variables - }); + variables: opts?.variables, + }) if (loaderInstance.state.status === 'error' && (opts.throwOnError ?? true)) { - throw loaderInstance.state.error; + throw loaderInstance.state.error } if (opts?.strict ?? true) { - invariant(typeof loaderInstance.state.data !== 'undefined', `useLoaderInstance: + invariant( + typeof loaderInstance.state.data !== 'undefined', + `useLoaderInstance: Loader instance { key: ${loader.key}, variables: ${opts.variables} }) is currently in a "${loaderInstance.state.status}" state. By default useLoaderInstance will throw an error if the loader instance is not in a "success" state. To avoid this error: - Load the loader instance before using it (e.g. via your router's onLoad or loader option) - - Set opts.strict to false and handle the loading state in your component`); + - Set opts.strict to false and handle the loading state in your component`, + ) } React.useEffect(() => { - loaderInstance.load(); - }, [loaderInstance]); - useStore(loaderInstance.__store, d => opts?.track?.(d) ?? d, true); - return loaderInstance; + loaderInstance.load() + }, [loaderInstance]) + useStore(loaderInstance.__store, (d) => opts?.track?.(d) ?? d, true) + return loaderInstance } -var isProduction = process.env.NODE_ENV === 'production'; +var isProduction = process.env.NODE_ENV === 'production' function warning(condition, message) { if (!isProduction) { if (condition) { - return; + return } - var text = "Warning: " + message; + var text = 'Warning: ' + message if (typeof console !== 'undefined') { - console.warn(text); + console.warn(text) } try { - throw Error(text); + throw Error(text) } catch (x) {} } } @@ -111,30 +134,32 @@ function warning(condition, message) { */ function _extends() { - _extends = Object.assign ? Object.assign.bind() : function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; + _extends = Object.assign + ? Object.assign.bind() + : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key] + } + } } + return target } - } - return target; - }; - return _extends.apply(this, arguments); + return _extends.apply(this, arguments) } // function useLinkProps(options) { - const router = useRouterContext(); + const router = useRouterContext() const { // custom props type, children, target, activeProps = () => ({ - className: 'active' + className: 'active', }), inactiveProps = () => ({}), activeOptions, @@ -156,15 +181,13 @@ function useLinkProps(options) { onMouseLeave, onTouchStart, ...rest - } = options; - const linkInfo = router.buildLink(options); + } = options + const linkInfo = router.buildLink(options) if (linkInfo.type === 'external') { - const { - href - } = linkInfo; + const { href } = linkInfo return { - href - }; + href, + } } const { handleClick, @@ -173,31 +196,35 @@ function useLinkProps(options) { handleLeave, handleTouchStart, isActive, - next - } = linkInfo; - const reactHandleClick = e => { + next, + } = linkInfo + const reactHandleClick = (e) => { if (React.startTransition) { // This is a hack for react < 18 React.startTransition(() => { - handleClick(e); - }); + handleClick(e) + }) } else { - handleClick(e); + handleClick(e) } - }; - const composeHandlers = handlers => e => { - if (e.persist) e.persist(); - handlers.filter(Boolean).forEach(handler => { - if (e.defaultPrevented) return; - handler(e); - }); - }; + } + const composeHandlers = (handlers) => (e) => { + if (e.persist) e.persist() + handlers.filter(Boolean).forEach((handler) => { + if (e.defaultPrevented) return + handler(e) + }) + } // Get the active props - const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {}; + const resolvedActiveProps = isActive + ? functionalUpdate(activeProps, {}) ?? {} + : {} // Get the inactive props - const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}; + const resolvedInactiveProps = isActive + ? {} + : functionalUpdate(inactiveProps, {}) ?? {} return { ...resolvedActiveProps, ...resolvedInactiveProps, @@ -212,134 +239,188 @@ function useLinkProps(options) { style: { ...style, ...resolvedActiveProps.style, - ...resolvedInactiveProps.style + ...resolvedInactiveProps.style, }, - className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined, - ...(disabled ? { - role: 'link', - 'aria-disabled': true - } : undefined), - ['data-status']: isActive ? 'active' : undefined - }; + className: + [ + className, + resolvedActiveProps.className, + resolvedInactiveProps.className, + ] + .filter(Boolean) + .join(' ') || undefined, + ...(disabled + ? { + role: 'link', + 'aria-disabled': true, + } + : undefined), + ['data-status']: isActive ? 'active' : undefined, + } } -const Link = /*#__PURE__*/React.forwardRef((props, ref) => { - const linkProps = useLinkProps(props); - return /*#__PURE__*/React.createElement("a", _extends({ - ref: ref - }, linkProps, { - children: typeof props.children === 'function' ? props.children({ - isActive: linkProps['data-status'] === 'active' - }) : props.children - })); -}); -const matchesContext = /*#__PURE__*/React.createContext(null); -const routerContext = /*#__PURE__*/React.createContext(null); -class ReactRouter extends Router { +const Link = /*#__PURE__*/ React.forwardRef((props, ref) => { + const linkProps = useLinkProps(props) + return /*#__PURE__*/ React.createElement( + 'a', + _extends( + { + ref: ref, + }, + linkProps, + { + children: + typeof props.children === 'function' + ? props.children({ + isActive: linkProps['data-status'] === 'active', + }) + : props.children, + }, + ), + ) +}) +const matchesContext = /*#__PURE__*/ React.createContext(null) +const routerContext = /*#__PURE__*/ React.createContext(null) +class Router extends Router { constructor(opts) { super({ ...opts, - loadComponent: async component => { + loadComponent: async (component) => { if (component.preload) { - await component.preload(); + await component.preload() } - return component; - } - }); + return component + }, + }) } } -function RouterProvider({ - router, - ...rest -}) { - router.update(rest); - const currentMatches = useStore(router.__store, s => s.currentMatches); - React.useEffect(router.mount, [router]); - return /*#__PURE__*/React.createElement(routerContext.Provider, { - value: { - router: router - } - }, /*#__PURE__*/React.createElement(matchesContext.Provider, { - value: [undefined, ...currentMatches] - }, /*#__PURE__*/React.createElement(CatchBoundary, { - errorComponent: ErrorComponent, - onCatch: () => { - warning(false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`); - } - }, /*#__PURE__*/React.createElement(Outlet, null)))); +function RouterProvider({ router, ...rest }) { + router.update(rest) + const currentMatches = useStore(router.__store, (s) => s.currentMatches) + React.useEffect(router.mount, [router]) + return /*#__PURE__*/ React.createElement( + routerContext.Provider, + { + value: { + router: router, + }, + }, + /*#__PURE__*/ React.createElement( + matchesContext.Provider, + { + value: [undefined, ...currentMatches], + }, + /*#__PURE__*/ React.createElement( + CatchBoundary, + { + errorComponent: ErrorComponent, + onCatch: () => { + warning( + false, + `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`, + ) + }, + }, + /*#__PURE__*/ React.createElement(Outlet, null), + ), + ), + ) } function useRouterContext() { - const value = React.useContext(routerContext); - warning(value, 'useRouter must be used inside a component!'); - useStore(value.router.__store); - return value.router; + const value = React.useContext(routerContext) + warning(value, 'useRouter must be used inside a component!') + useStore(value.router.__store) + return value.router } -function useRouter(track, shallow) { - const router = useRouterContext(); - useStore(router.__store, track, shallow); - return router; +function useRouter(track) { + const router = useRouterContext() + useStore(router.__store, track) + return router } function useMatches() { - return React.useContext(matchesContext); + return React.useContext(matchesContext) } function useParams(opts) { - const router = useRouterContext(); - useStore(router.__store, d => { - const params = last(d.currentMatches)?.params; - return opts?.track?.(params) ?? params; - }, true); - return last(router.state.currentMatches)?.params; + const router = useRouterContext() + useStore( + router.__store, + (d) => { + const params = last(d.currentMatches)?.params + return opts?.track?.(params) ?? params + }, + true, + ) + return last(router.state.currentMatches)?.params } function Outlet() { - const matches = useMatches().slice(1); - const match = matches[0]; + const matches = useMatches().slice(1) + const match = matches[0] if (!match) { - return null; + return null } - return /*#__PURE__*/React.createElement(SubOutlet, { + return /*#__PURE__*/ React.createElement(SubOutlet, { matches: matches, - match: match - }); + match: match, + }) } -function SubOutlet({ - matches, - match -}) { - const router = useRouterContext(); - useStore(match.__store, store => [store.status, store.error], true); - const defaultPending = React.useCallback(() => null, []); - const PendingComponent = match.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending; - const errorComponent = match.errorComponent ?? router.options.defaultErrorComponent; - const ResolvedSuspenseBoundary = match.route.options.wrapInSuspense ?? true ? React.Suspense : SafeFragment; - const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment; - return /*#__PURE__*/React.createElement(matchesContext.Provider, { - value: matches - }, /*#__PURE__*/React.createElement(ResolvedSuspenseBoundary, { - fallback: /*#__PURE__*/React.createElement(PendingComponent, null) - }, /*#__PURE__*/React.createElement(ResolvedCatchBoundary, { - key: match.route.id, - errorComponent: errorComponent, - onCatch: () => { - warning(false, `Error in route match: ${match.id}`); - } - }, /*#__PURE__*/React.createElement(Inner, { - match: match - })))); +function SubOutlet({ matches, match }) { + const router = useRouterContext() + useStore(match.__store, (store) => [store.status, store.error], true) + const defaultPending = React.useCallback(() => null, []) + const PendingComponent = + match.pendingComponent ?? + router.options.defaultPendingComponent ?? + defaultPending + const errorComponent = + match.errorComponent ?? router.options.defaultErrorComponent + const ResolvedSuspenseBoundary = + match.route.options.wrapInSuspense ?? true ? React.Suspense : SafeFragment + const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment + return /*#__PURE__*/ React.createElement( + matchesContext.Provider, + { + value: matches, + }, + /*#__PURE__*/ React.createElement( + ResolvedSuspenseBoundary, + { + fallback: /*#__PURE__*/ React.createElement(PendingComponent, null), + }, + /*#__PURE__*/ React.createElement( + ResolvedCatchBoundary, + { + key: match.route.id, + errorComponent: errorComponent, + onCatch: () => { + warning(false, `Error in route match: ${match.id}`) + }, + }, + /*#__PURE__*/ React.createElement(Inner, { + match: match, + }), + ), + ), + ) } function Inner(props) { - const router = useRouterContext(); + const router = useRouterContext() if (props.match.state.status === 'error') { - throw props.match.state.error; + throw props.match.state.error } if (props.match.state.status === 'success') { - return /*#__PURE__*/React.createElement(props.match.component ?? router.options.defaultComponent ?? Outlet); + return /*#__PURE__*/ React.createElement( + props.match.component ?? router.options.defaultComponent ?? Outlet, + ) } if (props.match.state.status === 'pending') { - throw props.match.__loadPromise; + throw props.match.__loadPromise } - invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!'); + invariant( + false, + 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!', + ) } function SafeFragment(props) { - return /*#__PURE__*/React.createElement(React.Fragment, null, props.children); + return /*#__PURE__*/ React.createElement(React.Fragment, null, props.children) } // This is the messiest thing ever... I'm either seriously tired (likely) or @@ -349,261 +430,320 @@ function SafeFragment(props) { class CatchBoundary extends React.Component { state = { error: false, - info: undefined - }; + info: undefined, + } componentDidCatch(error, info) { - this.props.onCatch(error, info); - console.error(error); + this.props.onCatch(error, info) + console.error(error) this.setState({ error, - info - }); + info, + }) } render() { - return /*#__PURE__*/React.createElement(CatchBoundaryInner, _extends({}, this.props, { - errorState: this.state, - reset: () => this.setState({}) - })); + return /*#__PURE__*/ React.createElement( + CatchBoundaryInner, + _extends({}, this.props, { + errorState: this.state, + reset: () => this.setState({}), + }), + ) } } function CatchBoundaryInner(props) { - const [activeErrorState, setActiveErrorState] = React.useState(props.errorState); - const router = useRouterContext(); - const errorComponent = props.errorComponent ?? ErrorComponent; - const prevKeyRef = React.useRef(''); + const [activeErrorState, setActiveErrorState] = React.useState( + props.errorState, + ) + const router = useRouterContext() + const errorComponent = props.errorComponent ?? ErrorComponent + const prevKeyRef = React.useRef('') React.useEffect(() => { if (activeErrorState) { if (router.state.currentLocation.key !== prevKeyRef.current) { - setActiveErrorState({}); + setActiveErrorState({}) } } - prevKeyRef.current = router.state.currentLocation.key; - }, [activeErrorState, router.state.currentLocation.key]); + prevKeyRef.current = router.state.currentLocation.key + }, [activeErrorState, router.state.currentLocation.key]) React.useEffect(() => { if (props.errorState.error) { - setActiveErrorState(props.errorState); + setActiveErrorState(props.errorState) } // props.reset() - }, [props.errorState.error]); + }, [props.errorState.error]) if (props.errorState.error && activeErrorState.error) { - return /*#__PURE__*/React.createElement(errorComponent, activeErrorState); + return /*#__PURE__*/ React.createElement(errorComponent, activeErrorState) } - return props.children; + return props.children } -function ErrorComponent({ - error -}) { - return /*#__PURE__*/React.createElement("div", { - style: { - padding: '.5rem', - maxWidth: '100%' - } - }, /*#__PURE__*/React.createElement("strong", { - style: { - fontSize: '1.2rem' - } - }, "Something went wrong!"), /*#__PURE__*/React.createElement("div", { - style: { - height: '.5rem' - } - }), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", { - style: { - fontSize: '.7em', - border: '1px solid red', - borderRadius: '.25rem', - padding: '.5rem', - color: 'red', - overflow: 'auto' - } - }, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null))); +function ErrorComponent({ error }) { + return /*#__PURE__*/ React.createElement( + 'div', + { + style: { + padding: '.5rem', + maxWidth: '100%', + }, + }, + /*#__PURE__*/ React.createElement( + 'strong', + { + style: { + fontSize: '1.2rem', + }, + }, + 'Something went wrong!', + ), + /*#__PURE__*/ React.createElement('div', { + style: { + height: '.5rem', + }, + }), + /*#__PURE__*/ React.createElement( + 'div', + null, + /*#__PURE__*/ React.createElement( + 'pre', + { + style: { + fontSize: '.7em', + border: '1px solid red', + borderRadius: '.25rem', + padding: '.5rem', + color: 'red', + overflow: 'auto', + }, + }, + error.message + ? /*#__PURE__*/ React.createElement('code', null, error.message) + : null, + ), + ), + ) } const rootRoute = RootRoute.withRouterContext()({ component: Root, wrapInSuspense: false, - errorComponent: ({ - error - }) => /* @__PURE__ */ jsx(ErrorComponent, { - error - }) -}); + errorComponent: ({ error }) => + /* @__PURE__ */ jsx(ErrorComponent, { + error, + }), +}) function Root() { - const router = useRouter(); - const titleMatch = [...router.state.currentMatches].reverse().find((d) => d.routeContext?.getTitle); - const title = titleMatch?.context?.getTitle?.() ?? "Astro + TanStack Router"; - return /* @__PURE__ */ jsxs("html", { - lang: "en", - children: [/* @__PURE__ */ jsxs("head", { - children: [/* @__PURE__ */ jsx("meta", { - charSet: "UTF-8" - }), /* @__PURE__ */ jsx("meta", { - name: "viewport", - content: "width=device-width, initial-scale=1.0" - }), /* @__PURE__ */ jsx("title", { - children: title - }), /* @__PURE__ */ jsx("script", { - src: "https://cdn.tailwindcss.com" - })] - }), /* @__PURE__ */ jsxs("body", { - children: [/* @__PURE__ */ jsxs("div", { - className: "p-2 flex gap-2 text-lg", - children: [/* @__PURE__ */ jsx(Link, { - to: "/", - activeProps: { - className: "font-bold" - }, - activeOptions: { - exact: true - }, - children: "Home" - }), " ", /* @__PURE__ */ jsx(Link, { - to: "/posts", - activeProps: { - className: "font-bold" - }, - children: "Posts" - })] - }), /* @__PURE__ */ jsx("hr", {}), /* @__PURE__ */ jsx(Outlet, {}), " ", /* @__PURE__ */ jsx(RouterScripts, {})] - })] - }); + const router = useRouter() + const titleMatch = [...router.state.currentMatches] + .reverse() + .find((d) => d.routeContext?.getTitle) + const title = titleMatch?.context?.getTitle?.() ?? 'Astro + TanStack Router' + return /* @__PURE__ */ jsxs('html', { + lang: 'en', + children: [ + /* @__PURE__ */ jsxs('head', { + children: [ + /* @__PURE__ */ jsx('meta', { + charSet: 'UTF-8', + }), + /* @__PURE__ */ jsx('meta', { + name: 'viewport', + content: 'width=device-width, initial-scale=1.0', + }), + /* @__PURE__ */ jsx('title', { + children: title, + }), + /* @__PURE__ */ jsx('script', { + src: 'https://cdn.tailwindcss.com', + }), + ], + }), + /* @__PURE__ */ jsxs('body', { + children: [ + /* @__PURE__ */ jsxs('div', { + className: 'p-2 flex gap-2 text-lg', + children: [ + /* @__PURE__ */ jsx(Link, { + to: '/', + activeProps: { + className: 'font-bold', + }, + activeOptions: { + exact: true, + }, + children: 'Home', + }), + ' ', + /* @__PURE__ */ jsx(Link, { + to: '/posts', + activeProps: { + className: 'font-bold', + }, + children: 'Posts', + }), + ], + }), + /* @__PURE__ */ jsx('hr', {}), + /* @__PURE__ */ jsx(Outlet, {}), + ' ', + /* @__PURE__ */ jsx(RouterScripts, {}), + ], + }), + ], + }) } const indexRoute = new Route({ getParentRoute: () => rootRoute, - path: "/", - component: () => /* @__PURE__ */ jsx("div", { - className: "p-2", - children: /* @__PURE__ */ jsx("h3", { - children: "Welcome Home!" - }) - }) -}); + path: '/', + component: () => + /* @__PURE__ */ jsx('div', { + className: 'p-2', + children: /* @__PURE__ */ jsx('h3', { + children: 'Welcome Home!', + }), + }), +}) const postIdRoute = new Route({ getParentRoute: () => postsRoute, - path: "$postId", - getContext: ({ - context, - params: { - postId - } - }) => ({ - getTitle: () => context.loaderClient.getLoader({ - key: "post" - }).getInstance({ - variables: postId - }).state.data?.title + path: '$postId', + getContext: ({ context, params: { postId } }) => ({ + getTitle: () => + context.loaderClient + .getLoader({ + key: 'post', + }) + .getInstance({ + variables: postId, + }).state.data?.title, }), - onLoad: async ({ - params: { - postId - }, - preload, - context - }) => context.loaderClient.getLoader({ - key: "post" - }).load({ - variables: postId, - preload - }), - component: Post -}); + onLoad: async ({ params: { postId }, preload, context }) => + context.loaderClient + .getLoader({ + key: 'post', + }) + .load({ + variables: postId, + preload, + }), + component: Post, +}) function Post() { + const { postId } = useParams({ + from: postIdRoute.id, + }) const { - postId - } = useParams({ - from: postIdRoute.id - }); - const { - state: { - data: post - } + state: { data: post }, } = useLoaderInstance({ - key: "post", - variables: postId - }); - return /* @__PURE__ */ jsxs("div", { - className: "space-y-2", - children: [/* @__PURE__ */ jsx("h4", { - className: "text-xl font-bold underline", - children: post.title - }), /* @__PURE__ */ jsx("div", { - className: "text-sm", - children: post.body - })] - }); + key: 'post', + variables: postId, + }) + return /* @__PURE__ */ jsxs('div', { + className: 'space-y-2', + children: [ + /* @__PURE__ */ jsx('h4', { + className: 'text-xl font-bold underline', + children: post.title, + }), + /* @__PURE__ */ jsx('div', { + className: 'text-sm', + children: post.body, + }), + ], + }) } const postsRoute = new Route({ getParentRoute: () => rootRoute, - path: "posts", - onLoad: ({ - context, - preload - }) => context.loaderClient.getLoader({ - key: "posts" - }).load({ - preload - }), + path: 'posts', + onLoad: ({ context, preload }) => + context.loaderClient + .getLoader({ + key: 'posts', + }) + .load({ + preload, + }), component: Posts, - getContext: ({ - context - }) => ({ - getTitle: () => `${context.loaderClient.getLoader({ - key: "posts" - }).getInstance().state.data?.length} Posts` - }) -}); + getContext: ({ context }) => ({ + getTitle: () => + `${ + context.loaderClient + .getLoader({ + key: 'posts', + }) + .getInstance().state.data?.length + } Posts`, + }), +}) function Posts() { const { - state: { - data: posts - } + state: { data: posts }, } = useLoaderInstance({ - key: "posts" - }); - return /* @__PURE__ */ jsxs("div", { - className: "p-2 flex gap-2", - children: [/* @__PURE__ */ jsx("ul", { - className: "list-disc pl-4", - children: posts.map((post) => { - return /* @__PURE__ */ jsx("li", { - className: "whitespace-nowrap", - children: /* @__PURE__ */ jsx(Link, { - to: postIdRoute.fullPath, - params: { - postId: post.id - }, - className: "block py-1 text-blue-800 hover:text-blue-600", - activeProps: { - className: "text-black font-bold" + key: 'posts', + }) + return /* @__PURE__ */ jsxs('div', { + className: 'p-2 flex gap-2', + children: [ + /* @__PURE__ */ jsx('ul', { + className: 'list-disc pl-4', + children: posts.map((post) => { + return /* @__PURE__ */ jsx( + 'li', + { + className: 'whitespace-nowrap', + children: /* @__PURE__ */ jsx(Link, { + to: postIdRoute.fullPath, + params: { + postId: post.id, + }, + className: 'block py-1 text-blue-800 hover:text-blue-600', + activeProps: { + className: 'text-black font-bold', + }, + children: /* @__PURE__ */ jsx('div', { + children: post.title.substring(0, 20), + }), + }), }, - children: /* @__PURE__ */ jsx("div", { - children: post.title.substring(0, 20) - }) - }) - }, post.id); - }) - }), /* @__PURE__ */ jsx("hr", {}), /* @__PURE__ */ jsx(Outlet, {})] - }); + post.id, + ) + }), + }), + /* @__PURE__ */ jsx('hr', {}), + /* @__PURE__ */ jsx(Outlet, {}), + ], + }) } const postsIndexRoute = new Route({ getParentRoute: () => postsRoute, - path: "/", - component: () => /* @__PURE__ */ jsx("div", { - children: "Select a post." - }) -}); + path: '/', + component: () => + /* @__PURE__ */ jsx('div', { + children: 'Select a post.', + }), +}) const routeTree = rootRoute.addChildren([ indexRoute, - postsRoute.addChildren([postsIndexRoute, postIdRoute]) -]); + postsRoute.addChildren([postsIndexRoute, postIdRoute]), +]) -const routeTree$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ - __proto__: null, - routeTree -}, Symbol.toStringTag, { value: 'Module' })); +const routeTree$1 = /*#__PURE__*/ Object.freeze( + /*#__PURE__*/ Object.defineProperty( + { + __proto__: null, + routeTree, + }, + Symbol.toStringTag, + { value: 'Module' }, + ), +) -export { LoaderClientProvider as L, ReactRouter as R, RouterProvider as a, routeTree$1 as b, routeTree as r }; +export { + LoaderClientProvider as L, + Router as R, + RouterProvider as a, + routeTree$1 as b, + routeTree as r, +} diff --git a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.c870053d.mjs b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.c870053d.mjs index 3bd28566d8..7c17e99f93 100644 --- a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.c870053d.mjs +++ b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.c870053d.mjs @@ -1,7 +1,16 @@ -import { s as shallow, i as invariant, R as Router, l as last, f as functionalUpdate, a as RootRoute, b as RouterScripts, c as Route } from './Hydrate.f13f5eaa.mjs'; -import * as React from 'react'; -import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'; -import { jsx, jsxs } from 'react/jsx-runtime'; +import { + s as shallow, + i as invariant, + R as Router, + l as last, + f as functionalUpdate, + a as RootRoute, + b as RouterScripts, + c as Route, +} from './Hydrate.f13f5eaa.mjs' +import * as React from 'react' +import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js' +import { jsx, jsxs } from 'react/jsx-runtime' /** * react-store @@ -14,9 +23,15 @@ import { jsx, jsxs } from 'react/jsx-runtime'; * @license MIT */ -function useStore(store, selector = d => d, compareShallow) { - const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined); - return slice; +function useStore(store, selector = (d) => d, compareShallow) { + const slice = useSyncExternalStoreWithSelector( + store.subscribe, + () => store.state, + () => store.state, + selector, + compareShallow ? shallow : undefined, + ) + return slice } /** @@ -32,19 +47,19 @@ function useStore(store, selector = d => d, compareShallow) { // -const loaderClientContext = /*#__PURE__*/React.createContext(null); -function LoaderClientProvider({ - loaderClient, - children, - ...rest -}) { +const loaderClientContext = /*#__PURE__*/ React.createContext(null) +function LoaderClientProvider({ loaderClient, children, ...rest }) { loaderClient.options = { ...loaderClient.options, - ...rest - }; - return /*#__PURE__*/React.createElement(loaderClientContext.Provider, { - value: loaderClient - }, children); + ...rest, + } + return /*#__PURE__*/ React.createElement( + loaderClientContext.Provider, + { + value: loaderClient, + }, + children, + ) } function useLoaderInstance(opts) { // opts as typeof opts & { @@ -52,49 +67,57 @@ function useLoaderInstance(opts) { // loader?: Loader // } - const loaderClient = React.useContext(loaderClientContext); - const optsKey = opts.key; - const optsLoader = opts.loader; - invariant(loaderClient || optsLoader, 'useLoaderInstance must be used inside a component!'); - const loader = optsLoader ?? loaderClient.getLoader({ - key: optsKey - }); + const loaderClient = React.useContext(loaderClientContext) + const optsKey = opts.key + const optsLoader = opts.loader + invariant( + loaderClient || optsLoader, + 'useLoaderInstance must be used inside a component!', + ) + const loader = + optsLoader ?? + loaderClient.getLoader({ + key: optsKey, + }) const loaderInstance = loader.getInstance({ - variables: opts?.variables - }); + variables: opts?.variables, + }) if (loaderInstance.state.status === 'error' && (opts.throwOnError ?? true)) { - throw loaderInstance.state.error; + throw loaderInstance.state.error } if (opts?.strict ?? true) { - invariant(typeof loaderInstance.state.data !== 'undefined', `useLoaderInstance: + invariant( + typeof loaderInstance.state.data !== 'undefined', + `useLoaderInstance: Loader instance { key: ${loader.key}, variables: ${opts.variables} }) is currently in a "${loaderInstance.state.status}" state. By default useLoaderInstance will throw an error if the loader instance is not in a "success" state. To avoid this error: - Load the loader instance before using it (e.g. via your router's onLoad or loader option) - - Set opts.strict to false and handle the loading state in your component`); + - Set opts.strict to false and handle the loading state in your component`, + ) } React.useEffect(() => { - loaderInstance.load(); - }, [loaderInstance]); - useStore(loaderInstance.__store, d => opts?.track?.(d) ?? d, true); - return loaderInstance; + loaderInstance.load() + }, [loaderInstance]) + useStore(loaderInstance.__store, (d) => opts?.track?.(d) ?? d, true) + return loaderInstance } -var isProduction = process.env.NODE_ENV === 'production'; +var isProduction = process.env.NODE_ENV === 'production' function warning(condition, message) { if (!isProduction) { if (condition) { - return; + return } - var text = "Warning: " + message; + var text = 'Warning: ' + message if (typeof console !== 'undefined') { - console.warn(text); + console.warn(text) } try { - throw Error(text); + throw Error(text) } catch (x) {} } } @@ -111,30 +134,32 @@ function warning(condition, message) { */ function _extends() { - _extends = Object.assign ? Object.assign.bind() : function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; + _extends = Object.assign + ? Object.assign.bind() + : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key] + } + } } + return target } - } - return target; - }; - return _extends.apply(this, arguments); + return _extends.apply(this, arguments) } // function useLinkProps(options) { - const router = useRouterContext(); + const router = useRouterContext() const { // custom props type, children, target, activeProps = () => ({ - className: 'active' + className: 'active', }), inactiveProps = () => ({}), activeOptions, @@ -156,15 +181,13 @@ function useLinkProps(options) { onMouseLeave, onTouchStart, ...rest - } = options; - const linkInfo = router.buildLink(options); + } = options + const linkInfo = router.buildLink(options) if (linkInfo.type === 'external') { - const { - href - } = linkInfo; + const { href } = linkInfo return { - href - }; + href, + } } const { handleClick, @@ -173,31 +196,35 @@ function useLinkProps(options) { handleLeave, handleTouchStart, isActive, - next - } = linkInfo; - const reactHandleClick = e => { + next, + } = linkInfo + const reactHandleClick = (e) => { if (React.startTransition) { // This is a hack for react < 18 React.startTransition(() => { - handleClick(e); - }); + handleClick(e) + }) } else { - handleClick(e); + handleClick(e) } - }; - const composeHandlers = handlers => e => { - if (e.persist) e.persist(); - handlers.filter(Boolean).forEach(handler => { - if (e.defaultPrevented) return; - handler(e); - }); - }; + } + const composeHandlers = (handlers) => (e) => { + if (e.persist) e.persist() + handlers.filter(Boolean).forEach((handler) => { + if (e.defaultPrevented) return + handler(e) + }) + } // Get the active props - const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {}; + const resolvedActiveProps = isActive + ? functionalUpdate(activeProps, {}) ?? {} + : {} // Get the inactive props - const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}; + const resolvedInactiveProps = isActive + ? {} + : functionalUpdate(inactiveProps, {}) ?? {} return { ...resolvedActiveProps, ...resolvedInactiveProps, @@ -212,134 +239,188 @@ function useLinkProps(options) { style: { ...style, ...resolvedActiveProps.style, - ...resolvedInactiveProps.style + ...resolvedInactiveProps.style, }, - className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined, - ...(disabled ? { - role: 'link', - 'aria-disabled': true - } : undefined), - ['data-status']: isActive ? 'active' : undefined - }; + className: + [ + className, + resolvedActiveProps.className, + resolvedInactiveProps.className, + ] + .filter(Boolean) + .join(' ') || undefined, + ...(disabled + ? { + role: 'link', + 'aria-disabled': true, + } + : undefined), + ['data-status']: isActive ? 'active' : undefined, + } } -const Link = /*#__PURE__*/React.forwardRef((props, ref) => { - const linkProps = useLinkProps(props); - return /*#__PURE__*/React.createElement("a", _extends({ - ref: ref - }, linkProps, { - children: typeof props.children === 'function' ? props.children({ - isActive: linkProps['data-status'] === 'active' - }) : props.children - })); -}); -const matchesContext = /*#__PURE__*/React.createContext(null); -const routerContext = /*#__PURE__*/React.createContext(null); -class ReactRouter extends Router { +const Link = /*#__PURE__*/ React.forwardRef((props, ref) => { + const linkProps = useLinkProps(props) + return /*#__PURE__*/ React.createElement( + 'a', + _extends( + { + ref: ref, + }, + linkProps, + { + children: + typeof props.children === 'function' + ? props.children({ + isActive: linkProps['data-status'] === 'active', + }) + : props.children, + }, + ), + ) +}) +const matchesContext = /*#__PURE__*/ React.createContext(null) +const routerContext = /*#__PURE__*/ React.createContext(null) +class Router extends Router { constructor(opts) { super({ ...opts, - loadComponent: async component => { + loadComponent: async (component) => { if (component.preload) { - await component.preload(); + await component.preload() } - return component; - } - }); + return component + }, + }) } } -function RouterProvider({ - router, - ...rest -}) { - router.update(rest); - const currentMatches = useStore(router.__store, s => s.currentMatches); - React.useEffect(router.mount, [router]); - return /*#__PURE__*/React.createElement(routerContext.Provider, { - value: { - router: router - } - }, /*#__PURE__*/React.createElement(matchesContext.Provider, { - value: [undefined, ...currentMatches] - }, /*#__PURE__*/React.createElement(CatchBoundary, { - errorComponent: ErrorComponent, - onCatch: () => { - warning(false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`); - } - }, /*#__PURE__*/React.createElement(Outlet, null)))); +function RouterProvider({ router, ...rest }) { + router.update(rest) + const currentMatches = useStore(router.__store, (s) => s.currentMatches) + React.useEffect(router.mount, [router]) + return /*#__PURE__*/ React.createElement( + routerContext.Provider, + { + value: { + router: router, + }, + }, + /*#__PURE__*/ React.createElement( + matchesContext.Provider, + { + value: [undefined, ...currentMatches], + }, + /*#__PURE__*/ React.createElement( + CatchBoundary, + { + errorComponent: ErrorComponent, + onCatch: () => { + warning( + false, + `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`, + ) + }, + }, + /*#__PURE__*/ React.createElement(Outlet, null), + ), + ), + ) } function useRouterContext() { - const value = React.useContext(routerContext); - warning(value, 'useRouter must be used inside a component!'); - useStore(value.router.__store); - return value.router; + const value = React.useContext(routerContext) + warning(value, 'useRouter must be used inside a component!') + useStore(value.router.__store) + return value.router } -function useRouter(track, shallow) { - const router = useRouterContext(); - useStore(router.__store, track, shallow); - return router; +function useRouter(track) { + const router = useRouterContext() + useStore(router.__store, track) + return router } function useMatches() { - return React.useContext(matchesContext); + return React.useContext(matchesContext) } function useParams(opts) { - const router = useRouterContext(); - useStore(router.__store, d => { - const params = last(d.currentMatches)?.params; - return opts?.track?.(params) ?? params; - }, true); - return last(router.state.currentMatches)?.params; + const router = useRouterContext() + useStore( + router.__store, + (d) => { + const params = last(d.currentMatches)?.params + return opts?.track?.(params) ?? params + }, + true, + ) + return last(router.state.currentMatches)?.params } function Outlet() { - const matches = useMatches().slice(1); - const match = matches[0]; + const matches = useMatches().slice(1) + const match = matches[0] if (!match) { - return null; + return null } - return /*#__PURE__*/React.createElement(SubOutlet, { + return /*#__PURE__*/ React.createElement(SubOutlet, { matches: matches, - match: match - }); + match: match, + }) } -function SubOutlet({ - matches, - match -}) { - const router = useRouterContext(); - useStore(match.__store, store => [store.status, store.error], true); - const defaultPending = React.useCallback(() => null, []); - const PendingComponent = match.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending; - const errorComponent = match.errorComponent ?? router.options.defaultErrorComponent; - const ResolvedSuspenseBoundary = match.route.options.wrapInSuspense ?? true ? React.Suspense : SafeFragment; - const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment; - return /*#__PURE__*/React.createElement(matchesContext.Provider, { - value: matches - }, /*#__PURE__*/React.createElement(ResolvedSuspenseBoundary, { - fallback: /*#__PURE__*/React.createElement(PendingComponent, null) - }, /*#__PURE__*/React.createElement(ResolvedCatchBoundary, { - key: match.route.id, - errorComponent: errorComponent, - onCatch: () => { - warning(false, `Error in route match: ${match.id}`); - } - }, /*#__PURE__*/React.createElement(Inner, { - match: match - })))); +function SubOutlet({ matches, match }) { + const router = useRouterContext() + useStore(match.__store, (store) => [store.status, store.error], true) + const defaultPending = React.useCallback(() => null, []) + const PendingComponent = + match.pendingComponent ?? + router.options.defaultPendingComponent ?? + defaultPending + const errorComponent = + match.errorComponent ?? router.options.defaultErrorComponent + const ResolvedSuspenseBoundary = + match.route.options.wrapInSuspense ?? true ? React.Suspense : SafeFragment + const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment + return /*#__PURE__*/ React.createElement( + matchesContext.Provider, + { + value: matches, + }, + /*#__PURE__*/ React.createElement( + ResolvedSuspenseBoundary, + { + fallback: /*#__PURE__*/ React.createElement(PendingComponent, null), + }, + /*#__PURE__*/ React.createElement( + ResolvedCatchBoundary, + { + key: match.route.id, + errorComponent: errorComponent, + onCatch: () => { + warning(false, `Error in route match: ${match.id}`) + }, + }, + /*#__PURE__*/ React.createElement(Inner, { + match: match, + }), + ), + ), + ) } function Inner(props) { - const router = useRouterContext(); + const router = useRouterContext() if (props.match.state.status === 'error') { - throw props.match.state.error; + throw props.match.state.error } if (props.match.state.status === 'success') { - return /*#__PURE__*/React.createElement(props.match.component ?? router.options.defaultComponent ?? Outlet); + return /*#__PURE__*/ React.createElement( + props.match.component ?? router.options.defaultComponent ?? Outlet, + ) } if (props.match.state.status === 'pending') { - throw props.match.__loadPromise; + throw props.match.__loadPromise } - invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!'); + invariant( + false, + 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!', + ) } function SafeFragment(props) { - return /*#__PURE__*/React.createElement(React.Fragment, null, props.children); + return /*#__PURE__*/ React.createElement(React.Fragment, null, props.children) } // This is the messiest thing ever... I'm either seriously tired (likely) or @@ -349,261 +430,320 @@ function SafeFragment(props) { class CatchBoundary extends React.Component { state = { error: false, - info: undefined - }; + info: undefined, + } componentDidCatch(error, info) { - this.props.onCatch(error, info); - console.error(error); + this.props.onCatch(error, info) + console.error(error) this.setState({ error, - info - }); + info, + }) } render() { - return /*#__PURE__*/React.createElement(CatchBoundaryInner, _extends({}, this.props, { - errorState: this.state, - reset: () => this.setState({}) - })); + return /*#__PURE__*/ React.createElement( + CatchBoundaryInner, + _extends({}, this.props, { + errorState: this.state, + reset: () => this.setState({}), + }), + ) } } function CatchBoundaryInner(props) { - const [activeErrorState, setActiveErrorState] = React.useState(props.errorState); - const router = useRouterContext(); - const errorComponent = props.errorComponent ?? ErrorComponent; - const prevKeyRef = React.useRef(''); + const [activeErrorState, setActiveErrorState] = React.useState( + props.errorState, + ) + const router = useRouterContext() + const errorComponent = props.errorComponent ?? ErrorComponent + const prevKeyRef = React.useRef('') React.useEffect(() => { if (activeErrorState) { if (router.state.currentLocation.key !== prevKeyRef.current) { - setActiveErrorState({}); + setActiveErrorState({}) } } - prevKeyRef.current = router.state.currentLocation.key; - }, [activeErrorState, router.state.currentLocation.key]); + prevKeyRef.current = router.state.currentLocation.key + }, [activeErrorState, router.state.currentLocation.key]) React.useEffect(() => { if (props.errorState.error) { - setActiveErrorState(props.errorState); + setActiveErrorState(props.errorState) } // props.reset() - }, [props.errorState.error]); + }, [props.errorState.error]) if (props.errorState.error && activeErrorState.error) { - return /*#__PURE__*/React.createElement(errorComponent, activeErrorState); + return /*#__PURE__*/ React.createElement(errorComponent, activeErrorState) } - return props.children; + return props.children } -function ErrorComponent({ - error -}) { - return /*#__PURE__*/React.createElement("div", { - style: { - padding: '.5rem', - maxWidth: '100%' - } - }, /*#__PURE__*/React.createElement("strong", { - style: { - fontSize: '1.2rem' - } - }, "Something went wrong!"), /*#__PURE__*/React.createElement("div", { - style: { - height: '.5rem' - } - }), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", { - style: { - fontSize: '.7em', - border: '1px solid red', - borderRadius: '.25rem', - padding: '.5rem', - color: 'red', - overflow: 'auto' - } - }, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null))); +function ErrorComponent({ error }) { + return /*#__PURE__*/ React.createElement( + 'div', + { + style: { + padding: '.5rem', + maxWidth: '100%', + }, + }, + /*#__PURE__*/ React.createElement( + 'strong', + { + style: { + fontSize: '1.2rem', + }, + }, + 'Something went wrong!', + ), + /*#__PURE__*/ React.createElement('div', { + style: { + height: '.5rem', + }, + }), + /*#__PURE__*/ React.createElement( + 'div', + null, + /*#__PURE__*/ React.createElement( + 'pre', + { + style: { + fontSize: '.7em', + border: '1px solid red', + borderRadius: '.25rem', + padding: '.5rem', + color: 'red', + overflow: 'auto', + }, + }, + error.message + ? /*#__PURE__*/ React.createElement('code', null, error.message) + : null, + ), + ), + ) } const rootRoute = RootRoute.withRouterContext()({ component: Root, wrapInSuspense: false, - errorComponent: ({ - error - }) => /* @__PURE__ */ jsx(ErrorComponent, { - error - }) -}); + errorComponent: ({ error }) => + /* @__PURE__ */ jsx(ErrorComponent, { + error, + }), +}) function Root() { - const router = useRouter(); - const titleMatch = [...router.state.currentMatches].reverse().find((d) => d.routeContext?.getTitle); - const title = titleMatch?.context?.getTitle?.() ?? "Astro + TanStack Router"; - return /* @__PURE__ */ jsxs("html", { - lang: "en", - children: [/* @__PURE__ */ jsxs("head", { - children: [/* @__PURE__ */ jsx("meta", { - charSet: "UTF-8" - }), /* @__PURE__ */ jsx("meta", { - name: "viewport", - content: "width=device-width, initial-scale=1.0" - }), /* @__PURE__ */ jsx("title", { - children: title - }), /* @__PURE__ */ jsx("script", { - src: "https://cdn.tailwindcss.com" - })] - }), /* @__PURE__ */ jsxs("body", { - children: [/* @__PURE__ */ jsxs("div", { - className: "p-2 flex gap-2 text-lg", - children: [/* @__PURE__ */ jsx(Link, { - to: "/", - activeProps: { - className: "font-bold" - }, - activeOptions: { - exact: true - }, - children: "Home" - }), " ", /* @__PURE__ */ jsx(Link, { - to: "/posts", - activeProps: { - className: "font-bold" - }, - children: "Posts" - })] - }), /* @__PURE__ */ jsx("hr", {}), /* @__PURE__ */ jsx(Outlet, {}), " ", /* @__PURE__ */ jsx(RouterScripts, {})] - })] - }); + const router = useRouter() + const titleMatch = [...router.state.currentMatches] + .reverse() + .find((d) => d.routeContext?.getTitle) + const title = titleMatch?.context?.getTitle?.() ?? 'Astro + TanStack Router' + return /* @__PURE__ */ jsxs('html', { + lang: 'en', + children: [ + /* @__PURE__ */ jsxs('head', { + children: [ + /* @__PURE__ */ jsx('meta', { + charSet: 'UTF-8', + }), + /* @__PURE__ */ jsx('meta', { + name: 'viewport', + content: 'width=device-width, initial-scale=1.0', + }), + /* @__PURE__ */ jsx('title', { + children: title, + }), + /* @__PURE__ */ jsx('script', { + src: 'https://cdn.tailwindcss.com', + }), + ], + }), + /* @__PURE__ */ jsxs('body', { + children: [ + /* @__PURE__ */ jsxs('div', { + className: 'p-2 flex gap-2 text-lg', + children: [ + /* @__PURE__ */ jsx(Link, { + to: '/', + activeProps: { + className: 'font-bold', + }, + activeOptions: { + exact: true, + }, + children: 'Home', + }), + ' ', + /* @__PURE__ */ jsx(Link, { + to: '/posts', + activeProps: { + className: 'font-bold', + }, + children: 'Posts', + }), + ], + }), + /* @__PURE__ */ jsx('hr', {}), + /* @__PURE__ */ jsx(Outlet, {}), + ' ', + /* @__PURE__ */ jsx(RouterScripts, {}), + ], + }), + ], + }) } const indexRoute = new Route({ getParentRoute: () => rootRoute, - path: "/", - component: () => /* @__PURE__ */ jsx("div", { - className: "p-2", - children: /* @__PURE__ */ jsx("h3", { - children: "Welcome Home!" - }) - }) -}); + path: '/', + component: () => + /* @__PURE__ */ jsx('div', { + className: 'p-2', + children: /* @__PURE__ */ jsx('h3', { + children: 'Welcome Home!', + }), + }), +}) const postIdRoute = new Route({ getParentRoute: () => postsRoute, - path: "$postId", - getContext: ({ - context, - params: { - postId - } - }) => ({ - getTitle: () => context.loaderClient.getLoader({ - key: "post" - }).getInstance({ - variables: postId - }).state.data?.title + path: '$postId', + getContext: ({ context, params: { postId } }) => ({ + getTitle: () => + context.loaderClient + .getLoader({ + key: 'post', + }) + .getInstance({ + variables: postId, + }).state.data?.title, }), - onLoad: async ({ - params: { - postId - }, - preload, - context - }) => context.loaderClient.getLoader({ - key: "post" - }).load({ - variables: postId, - preload - }), - component: Post -}); + onLoad: async ({ params: { postId }, preload, context }) => + context.loaderClient + .getLoader({ + key: 'post', + }) + .load({ + variables: postId, + preload, + }), + component: Post, +}) function Post() { + const { postId } = useParams({ + from: postIdRoute.id, + }) const { - postId - } = useParams({ - from: postIdRoute.id - }); - const { - state: { - data: post - } + state: { data: post }, } = useLoaderInstance({ - key: "post", - variables: postId - }); - return /* @__PURE__ */ jsxs("div", { - className: "space-y-2", - children: [/* @__PURE__ */ jsx("h4", { - className: "text-xl font-bold underline", - children: post.title - }), /* @__PURE__ */ jsx("div", { - className: "text-sm", - children: post.body - })] - }); + key: 'post', + variables: postId, + }) + return /* @__PURE__ */ jsxs('div', { + className: 'space-y-2', + children: [ + /* @__PURE__ */ jsx('h4', { + className: 'text-xl font-bold underline', + children: post.title, + }), + /* @__PURE__ */ jsx('div', { + className: 'text-sm', + children: post.body, + }), + ], + }) } const postsRoute = new Route({ getParentRoute: () => rootRoute, - path: "posts", - onLoad: ({ - context, - preload - }) => context.loaderClient.getLoader({ - key: "posts" - }).load({ - preload - }), + path: 'posts', + onLoad: ({ context, preload }) => + context.loaderClient + .getLoader({ + key: 'posts', + }) + .load({ + preload, + }), component: Posts, - getContext: ({ - context - }) => ({ - getTitle: () => `${context.loaderClient.getLoader({ - key: "posts" - }).getInstance().state.data?.length} Posts` - }) -}); + getContext: ({ context }) => ({ + getTitle: () => + `${ + context.loaderClient + .getLoader({ + key: 'posts', + }) + .getInstance().state.data?.length + } Posts`, + }), +}) function Posts() { const { - state: { - data: posts - } + state: { data: posts }, } = useLoaderInstance({ - key: "posts" - }); - return /* @__PURE__ */ jsxs("div", { - className: "p-2 flex gap-2", - children: [/* @__PURE__ */ jsx("ul", { - className: "list-disc pl-4", - children: posts.map((post) => { - return /* @__PURE__ */ jsx("li", { - className: "whitespace-nowrap", - children: /* @__PURE__ */ jsx(Link, { - to: postIdRoute.fullPath, - params: { - postId: post.id - }, - className: "block py-1 text-blue-800 hover:text-blue-600", - activeProps: { - className: "text-black font-bold" + key: 'posts', + }) + return /* @__PURE__ */ jsxs('div', { + className: 'p-2 flex gap-2', + children: [ + /* @__PURE__ */ jsx('ul', { + className: 'list-disc pl-4', + children: posts.map((post) => { + return /* @__PURE__ */ jsx( + 'li', + { + className: 'whitespace-nowrap', + children: /* @__PURE__ */ jsx(Link, { + to: postIdRoute.fullPath, + params: { + postId: post.id, + }, + className: 'block py-1 text-blue-800 hover:text-blue-600', + activeProps: { + className: 'text-black font-bold', + }, + children: /* @__PURE__ */ jsx('div', { + children: post.title.substring(0, 20), + }), + }), }, - children: /* @__PURE__ */ jsx("div", { - children: post.title.substring(0, 20) - }) - }) - }, post.id); - }) - }), /* @__PURE__ */ jsx("hr", {}), /* @__PURE__ */ jsx(Outlet, {})] - }); + post.id, + ) + }), + }), + /* @__PURE__ */ jsx('hr', {}), + /* @__PURE__ */ jsx(Outlet, {}), + ], + }) } const postsIndexRoute = new Route({ getParentRoute: () => postsRoute, - path: "/", - component: () => /* @__PURE__ */ jsx("div", { - children: "Select a post." - }) -}); + path: '/', + component: () => + /* @__PURE__ */ jsx('div', { + children: 'Select a post.', + }), +}) const routeTree = rootRoute.addChildren([ indexRoute, - postsRoute.addChildren([postsIndexRoute, postIdRoute]) -]); + postsRoute.addChildren([postsIndexRoute, postIdRoute]), +]) -const routeTree$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ - __proto__: null, - routeTree -}, Symbol.toStringTag, { value: 'Module' })); +const routeTree$1 = /*#__PURE__*/ Object.freeze( + /*#__PURE__*/ Object.defineProperty( + { + __proto__: null, + routeTree, + }, + Symbol.toStringTag, + { value: 'Module' }, + ), +) -export { LoaderClientProvider as L, ReactRouter as R, RouterProvider as a, routeTree$1 as b, routeTree as r }; +export { + LoaderClientProvider as L, + Router as R, + RouterProvider as a, + routeTree$1 as b, + routeTree as r, +} diff --git a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.f436718c.mjs b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.f436718c.mjs index bc8d41f40e..226bda98e4 100644 --- a/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.f436718c.mjs +++ b/examples/react/with-astro-ssr/.netlify/functions-internal/chunks/routeTree.f436718c.mjs @@ -1,23 +1,32 @@ -import { s as shallow, i as invariant, R as Router, l as last, f as functionalUpdate, a as RootRoute, b as RouterScripts, c as Route } from '../entry.mjs'; -import * as React from 'react'; -import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'; -import { jsx, jsxs } from 'react/jsx-runtime'; +import { + s as shallow, + i as invariant, + R as Router, + l as last, + f as functionalUpdate, + a as RootRoute, + b as RouterScripts, + c as Route, +} from '../entry.mjs' +import * as React from 'react' +import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js' +import { jsx, jsxs } from 'react/jsx-runtime' -var isProduction = process.env.NODE_ENV === 'production'; +var isProduction = process.env.NODE_ENV === 'production' function warning(condition, message) { if (!isProduction) { if (condition) { - return; + return } - var text = "Warning: " + message; + var text = 'Warning: ' + message if (typeof console !== 'undefined') { - console.warn(text); + console.warn(text) } try { - throw Error(text); + throw Error(text) } catch (x) {} } } @@ -33,9 +42,15 @@ function warning(condition, message) { * @license MIT */ -function useStore(store, selector = d => d, compareShallow) { - const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined); - return slice; +function useStore(store, selector = (d) => d, compareShallow) { + const slice = useSyncExternalStoreWithSelector( + store.subscribe, + () => store.state, + () => store.state, + selector, + compareShallow ? shallow : undefined, + ) + return slice } /** @@ -51,19 +66,19 @@ function useStore(store, selector = d => d, compareShallow) { // -const loaderClientContext = /*#__PURE__*/React.createContext(null); -function LoaderClientProvider({ - loaderClient, - children, - ...rest -}) { +const loaderClientContext = /*#__PURE__*/ React.createContext(null) +function LoaderClientProvider({ loaderClient, children, ...rest }) { loaderClient.options = { ...loaderClient.options, - ...rest - }; - return /*#__PURE__*/React.createElement(loaderClientContext.Provider, { - value: loaderClient - }, children); + ...rest, + } + return /*#__PURE__*/ React.createElement( + loaderClientContext.Provider, + { + value: loaderClient, + }, + children, + ) } function useLoaderInstance(opts) { // opts as typeof opts & { @@ -71,32 +86,40 @@ function useLoaderInstance(opts) { // loader?: Loader // } - const loaderClient = React.useContext(loaderClientContext); - const optsKey = opts.key; - const optsLoader = opts.loader; - invariant(loaderClient || optsLoader, 'useLoaderInstance must be used inside a component!'); - const loader = optsLoader ?? loaderClient.getLoader({ - key: optsKey - }); + const loaderClient = React.useContext(loaderClientContext) + const optsKey = opts.key + const optsLoader = opts.loader + invariant( + loaderClient || optsLoader, + 'useLoaderInstance must be used inside a component!', + ) + const loader = + optsLoader ?? + loaderClient.getLoader({ + key: optsKey, + }) const loaderInstance = loader.getInstance({ - variables: opts?.variables - }); + variables: opts?.variables, + }) if (loaderInstance.state.status === 'error' && (opts.throwOnError ?? true)) { - throw loaderInstance.state.error; + throw loaderInstance.state.error } if (opts?.strict ?? true) { - invariant(typeof loaderInstance.state.data !== 'undefined', `useLoaderInstance: + invariant( + typeof loaderInstance.state.data !== 'undefined', + `useLoaderInstance: Loader instance { key: ${loader.key}, variables: ${opts.variables} }) is currently in a "${loaderInstance.state.status}" state. By default useLoaderInstance will throw an error if the loader instance is not in a "success" state. To avoid this error: - Load the loader instance before using it (e.g. via your router's onLoad or loader option) - - Set opts.strict to false and handle the loading state in your component`); + - Set opts.strict to false and handle the loading state in your component`, + ) } React.useEffect(() => { - loaderInstance.load(); - }, [loaderInstance]); - useStore(loaderInstance.__store, d => opts?.track?.(d) ?? d, true); - return loaderInstance; + loaderInstance.load() + }, [loaderInstance]) + useStore(loaderInstance.__store, (d) => opts?.track?.(d) ?? d, true) + return loaderInstance } /** @@ -111,30 +134,32 @@ function useLoaderInstance(opts) { */ function _extends() { - _extends = Object.assign ? Object.assign.bind() : function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; + _extends = Object.assign + ? Object.assign.bind() + : function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key] + } + } } + return target } - } - return target; - }; - return _extends.apply(this, arguments); + return _extends.apply(this, arguments) } // function useLinkProps(options) { - const router = useRouterContext(); + const router = useRouterContext() const { // custom props type, children, target, activeProps = () => ({ - className: 'active' + className: 'active', }), inactiveProps = () => ({}), activeOptions, @@ -156,15 +181,13 @@ function useLinkProps(options) { onMouseLeave, onTouchStart, ...rest - } = options; - const linkInfo = router.buildLink(options); + } = options + const linkInfo = router.buildLink(options) if (linkInfo.type === 'external') { - const { - href - } = linkInfo; + const { href } = linkInfo return { - href - }; + href, + } } const { handleClick, @@ -173,31 +196,35 @@ function useLinkProps(options) { handleLeave, handleTouchStart, isActive, - next - } = linkInfo; - const reactHandleClick = e => { + next, + } = linkInfo + const reactHandleClick = (e) => { if (React.startTransition) { // This is a hack for react < 18 React.startTransition(() => { - handleClick(e); - }); + handleClick(e) + }) } else { - handleClick(e); + handleClick(e) } - }; - const composeHandlers = handlers => e => { - if (e.persist) e.persist(); - handlers.filter(Boolean).forEach(handler => { - if (e.defaultPrevented) return; - handler(e); - }); - }; + } + const composeHandlers = (handlers) => (e) => { + if (e.persist) e.persist() + handlers.filter(Boolean).forEach((handler) => { + if (e.defaultPrevented) return + handler(e) + }) + } // Get the active props - const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {}; + const resolvedActiveProps = isActive + ? functionalUpdate(activeProps, {}) ?? {} + : {} // Get the inactive props - const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {}; + const resolvedInactiveProps = isActive + ? {} + : functionalUpdate(inactiveProps, {}) ?? {} return { ...resolvedActiveProps, ...resolvedInactiveProps, @@ -212,134 +239,188 @@ function useLinkProps(options) { style: { ...style, ...resolvedActiveProps.style, - ...resolvedInactiveProps.style + ...resolvedInactiveProps.style, }, - className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined, - ...(disabled ? { - role: 'link', - 'aria-disabled': true - } : undefined), - ['data-status']: isActive ? 'active' : undefined - }; + className: + [ + className, + resolvedActiveProps.className, + resolvedInactiveProps.className, + ] + .filter(Boolean) + .join(' ') || undefined, + ...(disabled + ? { + role: 'link', + 'aria-disabled': true, + } + : undefined), + ['data-status']: isActive ? 'active' : undefined, + } } -const Link = /*#__PURE__*/React.forwardRef((props, ref) => { - const linkProps = useLinkProps(props); - return /*#__PURE__*/React.createElement("a", _extends({ - ref: ref - }, linkProps, { - children: typeof props.children === 'function' ? props.children({ - isActive: linkProps['data-status'] === 'active' - }) : props.children - })); -}); -const matchesContext = /*#__PURE__*/React.createContext(null); -const routerContext = /*#__PURE__*/React.createContext(null); -class ReactRouter extends Router { +const Link = /*#__PURE__*/ React.forwardRef((props, ref) => { + const linkProps = useLinkProps(props) + return /*#__PURE__*/ React.createElement( + 'a', + _extends( + { + ref: ref, + }, + linkProps, + { + children: + typeof props.children === 'function' + ? props.children({ + isActive: linkProps['data-status'] === 'active', + }) + : props.children, + }, + ), + ) +}) +const matchesContext = /*#__PURE__*/ React.createContext(null) +const routerContext = /*#__PURE__*/ React.createContext(null) +class Router extends Router { constructor(opts) { super({ ...opts, - loadComponent: async component => { + loadComponent: async (component) => { if (component.preload) { - await component.preload(); + await component.preload() } - return component; - } - }); + return component + }, + }) } } -function RouterProvider({ - router, - ...rest -}) { - router.update(rest); - const currentMatches = useStore(router.__store, s => s.currentMatches); - React.useEffect(router.mount, [router]); - return /*#__PURE__*/React.createElement(routerContext.Provider, { - value: { - router: router - } - }, /*#__PURE__*/React.createElement(matchesContext.Provider, { - value: [undefined, ...currentMatches] - }, /*#__PURE__*/React.createElement(CatchBoundary, { - errorComponent: ErrorComponent, - onCatch: () => { - warning(false, `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`); - } - }, /*#__PURE__*/React.createElement(Outlet, null)))); +function RouterProvider({ router, ...rest }) { + router.update(rest) + const currentMatches = useStore(router.__store, (s) => s.currentMatches) + React.useEffect(router.mount, [router]) + return /*#__PURE__*/ React.createElement( + routerContext.Provider, + { + value: { + router: router, + }, + }, + /*#__PURE__*/ React.createElement( + matchesContext.Provider, + { + value: [undefined, ...currentMatches], + }, + /*#__PURE__*/ React.createElement( + CatchBoundary, + { + errorComponent: ErrorComponent, + onCatch: () => { + warning( + false, + `Error in router! Consider setting an 'errorComponent' in your RootRoute! 👍`, + ) + }, + }, + /*#__PURE__*/ React.createElement(Outlet, null), + ), + ), + ) } function useRouterContext() { - const value = React.useContext(routerContext); - warning(value, 'useRouter must be used inside a component!'); - useStore(value.router.__store); - return value.router; + const value = React.useContext(routerContext) + warning(value, 'useRouter must be used inside a component!') + useStore(value.router.__store) + return value.router } -function useRouter(track, shallow) { - const router = useRouterContext(); - useStore(router.__store, track, shallow); - return router; +function useRouter(track) { + const router = useRouterContext() + useStore(router.__store, track) + return router } function useMatches() { - return React.useContext(matchesContext); + return React.useContext(matchesContext) } function useParams(opts) { - const router = useRouterContext(); - useStore(router.__store, d => { - const params = last(d.currentMatches)?.params; - return opts?.track?.(params) ?? params; - }, true); - return last(router.state.currentMatches)?.params; + const router = useRouterContext() + useStore( + router.__store, + (d) => { + const params = last(d.currentMatches)?.params + return opts?.track?.(params) ?? params + }, + true, + ) + return last(router.state.currentMatches)?.params } function Outlet() { - const matches = useMatches().slice(1); - const match = matches[0]; + const matches = useMatches().slice(1) + const match = matches[0] if (!match) { - return null; + return null } - return /*#__PURE__*/React.createElement(SubOutlet, { + return /*#__PURE__*/ React.createElement(SubOutlet, { matches: matches, - match: match - }); + match: match, + }) } -function SubOutlet({ - matches, - match -}) { - const router = useRouterContext(); - useStore(match.__store, store => [store.status, store.error], true); - const defaultPending = React.useCallback(() => null, []); - const PendingComponent = match.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending; - const errorComponent = match.errorComponent ?? router.options.defaultErrorComponent; - const ResolvedSuspenseBoundary = match.route.options.wrapInSuspense ?? true ? React.Suspense : SafeFragment; - const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment; - return /*#__PURE__*/React.createElement(matchesContext.Provider, { - value: matches - }, /*#__PURE__*/React.createElement(ResolvedSuspenseBoundary, { - fallback: /*#__PURE__*/React.createElement(PendingComponent, null) - }, /*#__PURE__*/React.createElement(ResolvedCatchBoundary, { - key: match.route.id, - errorComponent: errorComponent, - onCatch: () => { - warning(false, `Error in route match: ${match.id}`); - } - }, /*#__PURE__*/React.createElement(Inner, { - match: match - })))); +function SubOutlet({ matches, match }) { + const router = useRouterContext() + useStore(match.__store, (store) => [store.status, store.error], true) + const defaultPending = React.useCallback(() => null, []) + const PendingComponent = + match.pendingComponent ?? + router.options.defaultPendingComponent ?? + defaultPending + const errorComponent = + match.errorComponent ?? router.options.defaultErrorComponent + const ResolvedSuspenseBoundary = + match.route.options.wrapInSuspense ?? true ? React.Suspense : SafeFragment + const ResolvedCatchBoundary = errorComponent ? CatchBoundary : SafeFragment + return /*#__PURE__*/ React.createElement( + matchesContext.Provider, + { + value: matches, + }, + /*#__PURE__*/ React.createElement( + ResolvedSuspenseBoundary, + { + fallback: /*#__PURE__*/ React.createElement(PendingComponent, null), + }, + /*#__PURE__*/ React.createElement( + ResolvedCatchBoundary, + { + key: match.route.id, + errorComponent: errorComponent, + onCatch: () => { + warning(false, `Error in route match: ${match.id}`) + }, + }, + /*#__PURE__*/ React.createElement(Inner, { + match: match, + }), + ), + ), + ) } function Inner(props) { - const router = useRouterContext(); + const router = useRouterContext() if (props.match.state.status === 'error') { - throw props.match.state.error; + throw props.match.state.error } if (props.match.state.status === 'success') { - return /*#__PURE__*/React.createElement(props.match.component ?? router.options.defaultComponent ?? Outlet); + return /*#__PURE__*/ React.createElement( + props.match.component ?? router.options.defaultComponent ?? Outlet, + ) } if (props.match.state.status === 'pending') { - throw props.match.__loadPromise; + throw props.match.__loadPromise } - invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!'); + invariant( + false, + 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!', + ) } function SafeFragment(props) { - return /*#__PURE__*/React.createElement(React.Fragment, null, props.children); + return /*#__PURE__*/ React.createElement(React.Fragment, null, props.children) } // This is the messiest thing ever... I'm either seriously tired (likely) or @@ -349,261 +430,320 @@ function SafeFragment(props) { class CatchBoundary extends React.Component { state = { error: false, - info: undefined - }; + info: undefined, + } componentDidCatch(error, info) { - this.props.onCatch(error, info); - console.error(error); + this.props.onCatch(error, info) + console.error(error) this.setState({ error, - info - }); + info, + }) } render() { - return /*#__PURE__*/React.createElement(CatchBoundaryInner, _extends({}, this.props, { - errorState: this.state, - reset: () => this.setState({}) - })); + return /*#__PURE__*/ React.createElement( + CatchBoundaryInner, + _extends({}, this.props, { + errorState: this.state, + reset: () => this.setState({}), + }), + ) } } function CatchBoundaryInner(props) { - const [activeErrorState, setActiveErrorState] = React.useState(props.errorState); - const router = useRouterContext(); - const errorComponent = props.errorComponent ?? ErrorComponent; - const prevKeyRef = React.useRef(''); + const [activeErrorState, setActiveErrorState] = React.useState( + props.errorState, + ) + const router = useRouterContext() + const errorComponent = props.errorComponent ?? ErrorComponent + const prevKeyRef = React.useRef('') React.useEffect(() => { if (activeErrorState) { if (router.state.currentLocation.key !== prevKeyRef.current) { - setActiveErrorState({}); + setActiveErrorState({}) } } - prevKeyRef.current = router.state.currentLocation.key; - }, [activeErrorState, router.state.currentLocation.key]); + prevKeyRef.current = router.state.currentLocation.key + }, [activeErrorState, router.state.currentLocation.key]) React.useEffect(() => { if (props.errorState.error) { - setActiveErrorState(props.errorState); + setActiveErrorState(props.errorState) } // props.reset() - }, [props.errorState.error]); + }, [props.errorState.error]) if (props.errorState.error && activeErrorState.error) { - return /*#__PURE__*/React.createElement(errorComponent, activeErrorState); + return /*#__PURE__*/ React.createElement(errorComponent, activeErrorState) } - return props.children; + return props.children } -function ErrorComponent({ - error -}) { - return /*#__PURE__*/React.createElement("div", { - style: { - padding: '.5rem', - maxWidth: '100%' - } - }, /*#__PURE__*/React.createElement("strong", { - style: { - fontSize: '1.2rem' - } - }, "Something went wrong!"), /*#__PURE__*/React.createElement("div", { - style: { - height: '.5rem' - } - }), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", { - style: { - fontSize: '.7em', - border: '1px solid red', - borderRadius: '.25rem', - padding: '.5rem', - color: 'red', - overflow: 'auto' - } - }, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null))); +function ErrorComponent({ error }) { + return /*#__PURE__*/ React.createElement( + 'div', + { + style: { + padding: '.5rem', + maxWidth: '100%', + }, + }, + /*#__PURE__*/ React.createElement( + 'strong', + { + style: { + fontSize: '1.2rem', + }, + }, + 'Something went wrong!', + ), + /*#__PURE__*/ React.createElement('div', { + style: { + height: '.5rem', + }, + }), + /*#__PURE__*/ React.createElement( + 'div', + null, + /*#__PURE__*/ React.createElement( + 'pre', + { + style: { + fontSize: '.7em', + border: '1px solid red', + borderRadius: '.25rem', + padding: '.5rem', + color: 'red', + overflow: 'auto', + }, + }, + error.message + ? /*#__PURE__*/ React.createElement('code', null, error.message) + : null, + ), + ), + ) } const rootRoute = RootRoute.withRouterContext()({ component: Root, wrapInSuspense: false, - errorComponent: ({ - error - }) => /* @__PURE__ */ jsx(ErrorComponent, { - error - }) -}); + errorComponent: ({ error }) => + /* @__PURE__ */ jsx(ErrorComponent, { + error, + }), +}) function Root() { - const router = useRouter(); - const titleMatch = [...router.state.currentMatches].reverse().find((d) => d.routeContext?.getTitle); - const title = titleMatch?.context?.getTitle?.() ?? "Astro + TanStack Router"; - return /* @__PURE__ */ jsxs("html", { - lang: "en", - children: [/* @__PURE__ */ jsxs("head", { - children: [/* @__PURE__ */ jsx("meta", { - charSet: "UTF-8" - }), /* @__PURE__ */ jsx("meta", { - name: "viewport", - content: "width=device-width, initial-scale=1.0" - }), /* @__PURE__ */ jsx("title", { - children: title - }), /* @__PURE__ */ jsx("script", { - src: "https://cdn.tailwindcss.com" - })] - }), /* @__PURE__ */ jsxs("body", { - children: [/* @__PURE__ */ jsxs("div", { - className: "p-2 flex gap-2 text-lg", - children: [/* @__PURE__ */ jsx(Link, { - to: "/", - activeProps: { - className: "font-bold" - }, - activeOptions: { - exact: true - }, - children: "Home" - }), " ", /* @__PURE__ */ jsx(Link, { - to: "/posts", - activeProps: { - className: "font-bold" - }, - children: "Posts" - })] - }), /* @__PURE__ */ jsx("hr", {}), /* @__PURE__ */ jsx(Outlet, {}), " ", /* @__PURE__ */ jsx(RouterScripts, {})] - })] - }); + const router = useRouter() + const titleMatch = [...router.state.currentMatches] + .reverse() + .find((d) => d.routeContext?.getTitle) + const title = titleMatch?.context?.getTitle?.() ?? 'Astro + TanStack Router' + return /* @__PURE__ */ jsxs('html', { + lang: 'en', + children: [ + /* @__PURE__ */ jsxs('head', { + children: [ + /* @__PURE__ */ jsx('meta', { + charSet: 'UTF-8', + }), + /* @__PURE__ */ jsx('meta', { + name: 'viewport', + content: 'width=device-width, initial-scale=1.0', + }), + /* @__PURE__ */ jsx('title', { + children: title, + }), + /* @__PURE__ */ jsx('script', { + src: 'https://cdn.tailwindcss.com', + }), + ], + }), + /* @__PURE__ */ jsxs('body', { + children: [ + /* @__PURE__ */ jsxs('div', { + className: 'p-2 flex gap-2 text-lg', + children: [ + /* @__PURE__ */ jsx(Link, { + to: '/', + activeProps: { + className: 'font-bold', + }, + activeOptions: { + exact: true, + }, + children: 'Home', + }), + ' ', + /* @__PURE__ */ jsx(Link, { + to: '/posts', + activeProps: { + className: 'font-bold', + }, + children: 'Posts', + }), + ], + }), + /* @__PURE__ */ jsx('hr', {}), + /* @__PURE__ */ jsx(Outlet, {}), + ' ', + /* @__PURE__ */ jsx(RouterScripts, {}), + ], + }), + ], + }) } const indexRoute = new Route({ getParentRoute: () => rootRoute, - path: "/", - component: () => /* @__PURE__ */ jsx("div", { - className: "p-2", - children: /* @__PURE__ */ jsx("h3", { - children: "Welcome Home!" - }) - }) -}); + path: '/', + component: () => + /* @__PURE__ */ jsx('div', { + className: 'p-2', + children: /* @__PURE__ */ jsx('h3', { + children: 'Welcome Home!', + }), + }), +}) const postIdRoute = new Route({ getParentRoute: () => postsRoute, - path: "$postId", - getContext: ({ - context, - params: { - postId - } - }) => ({ - getTitle: () => context.loaderClient.getLoader({ - key: "post" - }).getInstance({ - variables: postId - }).state.data?.title + path: '$postId', + getContext: ({ context, params: { postId } }) => ({ + getTitle: () => + context.loaderClient + .getLoader({ + key: 'post', + }) + .getInstance({ + variables: postId, + }).state.data?.title, }), - onLoad: async ({ - params: { - postId - }, - preload, - context - }) => context.loaderClient.getLoader({ - key: "post" - }).load({ - variables: postId, - preload - }), - component: Post -}); + onLoad: async ({ params: { postId }, preload, context }) => + context.loaderClient + .getLoader({ + key: 'post', + }) + .load({ + variables: postId, + preload, + }), + component: Post, +}) function Post() { + const { postId } = useParams({ + from: postIdRoute.id, + }) const { - postId - } = useParams({ - from: postIdRoute.id - }); - const { - state: { - data: post - } + state: { data: post }, } = useLoaderInstance({ - key: "post", - variables: postId - }); - return /* @__PURE__ */ jsxs("div", { - className: "space-y-2", - children: [/* @__PURE__ */ jsx("h4", { - className: "text-xl font-bold underline", - children: post.title - }), /* @__PURE__ */ jsx("div", { - className: "text-sm", - children: post.body - })] - }); + key: 'post', + variables: postId, + }) + return /* @__PURE__ */ jsxs('div', { + className: 'space-y-2', + children: [ + /* @__PURE__ */ jsx('h4', { + className: 'text-xl font-bold underline', + children: post.title, + }), + /* @__PURE__ */ jsx('div', { + className: 'text-sm', + children: post.body, + }), + ], + }) } const postsRoute = new Route({ getParentRoute: () => rootRoute, - path: "posts", - onLoad: ({ - context, - preload - }) => context.loaderClient.getLoader({ - key: "posts" - }).load({ - preload - }), + path: 'posts', + onLoad: ({ context, preload }) => + context.loaderClient + .getLoader({ + key: 'posts', + }) + .load({ + preload, + }), component: Posts, - getContext: ({ - context - }) => ({ - getTitle: () => `${context.loaderClient.getLoader({ - key: "posts" - }).getInstance().state.data?.length} Posts` - }) -}); + getContext: ({ context }) => ({ + getTitle: () => + `${ + context.loaderClient + .getLoader({ + key: 'posts', + }) + .getInstance().state.data?.length + } Posts`, + }), +}) function Posts() { const { - state: { - data: posts - } + state: { data: posts }, } = useLoaderInstance({ - key: "posts" - }); - return /* @__PURE__ */ jsxs("div", { - className: "p-2 flex gap-2", - children: [/* @__PURE__ */ jsx("ul", { - className: "list-disc pl-4", - children: posts.map((post) => { - return /* @__PURE__ */ jsx("li", { - className: "whitespace-nowrap", - children: /* @__PURE__ */ jsx(Link, { - to: postIdRoute.fullPath, - params: { - postId: post.id - }, - className: "block py-1 text-blue-800 hover:text-blue-600", - activeProps: { - className: "text-black font-bold" + key: 'posts', + }) + return /* @__PURE__ */ jsxs('div', { + className: 'p-2 flex gap-2', + children: [ + /* @__PURE__ */ jsx('ul', { + className: 'list-disc pl-4', + children: posts.map((post) => { + return /* @__PURE__ */ jsx( + 'li', + { + className: 'whitespace-nowrap', + children: /* @__PURE__ */ jsx(Link, { + to: postIdRoute.fullPath, + params: { + postId: post.id, + }, + className: 'block py-1 text-blue-800 hover:text-blue-600', + activeProps: { + className: 'text-black font-bold', + }, + children: /* @__PURE__ */ jsx('div', { + children: post.title.substring(0, 20), + }), + }), }, - children: /* @__PURE__ */ jsx("div", { - children: post.title.substring(0, 20) - }) - }) - }, post.id); - }) - }), /* @__PURE__ */ jsx("hr", {}), /* @__PURE__ */ jsx(Outlet, {})] - }); + post.id, + ) + }), + }), + /* @__PURE__ */ jsx('hr', {}), + /* @__PURE__ */ jsx(Outlet, {}), + ], + }) } const postsIndexRoute = new Route({ getParentRoute: () => postsRoute, - path: "/", - component: () => /* @__PURE__ */ jsx("div", { - children: "Select a post." - }) -}); + path: '/', + component: () => + /* @__PURE__ */ jsx('div', { + children: 'Select a post.', + }), +}) const routeTree = rootRoute.addChildren([ indexRoute, - postsRoute.addChildren([postsIndexRoute, postIdRoute]) -]); + postsRoute.addChildren([postsIndexRoute, postIdRoute]), +]) -const routeTree$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({ - __proto__: null, - routeTree -}, Symbol.toStringTag, { value: 'Module' })); +const routeTree$1 = /*#__PURE__*/ Object.freeze( + /*#__PURE__*/ Object.defineProperty( + { + __proto__: null, + routeTree, + }, + Symbol.toStringTag, + { value: 'Module' }, + ), +) -export { LoaderClientProvider as L, ReactRouter as R, RouterProvider as a, routeTree$1 as b, routeTree as r }; +export { + LoaderClientProvider as L, + Router as R, + RouterProvider as a, + routeTree$1 as b, + routeTree as r, +} diff --git a/examples/react/with-astro-ssr/package.json b/examples/react/with-astro-ssr/package.json index 1e7a936b97..8439efc091 100644 --- a/examples/react/with-astro-ssr/package.json +++ b/examples/react/with-astro-ssr/package.json @@ -14,8 +14,8 @@ "@astrojs/netlify": "^1.2.1", "@astrojs/react": "^1.2.2", "@tanstack/react-loaders": "0.0.1-beta.81", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@tanstack/router": "0.0.1-beta.82", "astro": "^1.6.12", "concurrently": "^7.6.0", diff --git a/examples/react/with-astro-ssr/src/app/App.tsx b/examples/react/with-astro-ssr/src/app/App.tsx index 91e87169c3..e3a3341c4d 100644 --- a/examples/react/with-astro-ssr/src/app/App.tsx +++ b/examples/react/with-astro-ssr/src/app/App.tsx @@ -1,6 +1,6 @@ import * as React from 'react' import { LoaderClientProvider } from '@tanstack/react-loaders' -import { RouterProvider } from '@tanstack/react-router' +import { RouterProvider } from '@tanstack/router' import { loaderClient } from './loaderClient' import { router } from './router' import { Hydrate } from './Hydrate' diff --git a/examples/react/with-astro-ssr/src/app/router.tsx b/examples/react/with-astro-ssr/src/app/router.tsx index b14094f4c7..e59ad02567 100644 --- a/examples/react/with-astro-ssr/src/app/router.tsx +++ b/examples/react/with-astro-ssr/src/app/router.tsx @@ -1,5 +1,5 @@ import type { RegisteredLoaderClient } from '@tanstack/react-loaders' -import { ReactRouter } from '@tanstack/react-router' +import { Router } from '@tanstack/router' import { loaderClient } from './loaderClient' import { routeTree } from './routeTree' @@ -7,7 +7,7 @@ export interface RouterContext { loaderClient: RegisteredLoaderClient } -export const router = new ReactRouter({ +export const router = new Router({ routeTree, context: { loaderClient, @@ -15,7 +15,7 @@ export const router = new ReactRouter({ defaultPreload: 'intent', }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/with-astro-ssr/src/app/routes/__root.tsx b/examples/react/with-astro-ssr/src/app/routes/__root.tsx index 9b9982bda5..db8d39fe63 100644 --- a/examples/react/with-astro-ssr/src/app/routes/__root.tsx +++ b/examples/react/with-astro-ssr/src/app/routes/__root.tsx @@ -1,11 +1,11 @@ -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { ErrorComponent, Link, Outlet, RootRoute, useRouter, -} from '@tanstack/react-router' +} from '@tanstack/router' import type { RouterContext } from '../router' import { RouterScripts } from '../Hydrate' diff --git a/examples/react/with-astro-ssr/src/app/routes/index.tsx b/examples/react/with-astro-ssr/src/app/routes/index.tsx index 059b2ae72f..27379f263b 100644 --- a/examples/react/with-astro-ssr/src/app/routes/index.tsx +++ b/examples/react/with-astro-ssr/src/app/routes/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { rootRoute } from './__root' export const indexRoute = new Route({ diff --git a/examples/react/with-astro-ssr/src/app/routes/posts.tsx b/examples/react/with-astro-ssr/src/app/routes/posts.tsx index 3f0ebdaecb..7d83afc43e 100644 --- a/examples/react/with-astro-ssr/src/app/routes/posts.tsx +++ b/examples/react/with-astro-ssr/src/app/routes/posts.tsx @@ -1,4 +1,4 @@ -import { Link, Outlet, Route } from '@tanstack/react-router' +import { Link, Outlet, Route } from '@tanstack/router' import { rootRoute } from './__root' import { useLoaderInstance } from '@tanstack/react-loaders' diff --git a/examples/react/with-astro-ssr/src/app/routes/posts/$postId.tsx b/examples/react/with-astro-ssr/src/app/routes/posts/$postId.tsx index 43d4759604..42e091f81b 100644 --- a/examples/react/with-astro-ssr/src/app/routes/posts/$postId.tsx +++ b/examples/react/with-astro-ssr/src/app/routes/posts/$postId.tsx @@ -1,5 +1,5 @@ import { useLoaderInstance } from '@tanstack/react-loaders' -import { Route, useParams } from '@tanstack/react-router' +import { Route, useParams } from '@tanstack/router' import { postsRoute } from '../posts' export const postIdRoute = new Route({ diff --git a/examples/react/with-astro-ssr/src/app/routes/posts/index.tsx b/examples/react/with-astro-ssr/src/app/routes/posts/index.tsx index 7defee4f9a..08e9dcff13 100644 --- a/examples/react/with-astro-ssr/src/app/routes/posts/index.tsx +++ b/examples/react/with-astro-ssr/src/app/routes/posts/index.tsx @@ -1,4 +1,4 @@ -import { Route } from '@tanstack/react-router' +import { Route } from '@tanstack/router' import { postsRoute } from '../posts' export const postsIndexRoute = new Route({ diff --git a/examples/react/with-react-query/package.json b/examples/react/with-react-query/package.json index 144fac48de..05336cd1dd 100644 --- a/examples/react/with-react-query/package.json +++ b/examples/react/with-react-query/package.json @@ -11,8 +11,8 @@ "dependencies": { "@tanstack/react-query": "^4.14.1", "@tanstack/react-query-devtools": "^4.14.1", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@vitejs/plugin-react": "^1.1.3", "axios": "^1.1.3", "immer": "^9.0.15", diff --git a/examples/react/with-react-query/src/main.tsx b/examples/react/with-react-query/src/main.tsx index c159089a67..c32f37f45c 100644 --- a/examples/react/with-react-query/src/main.tsx +++ b/examples/react/with-react-query/src/main.tsx @@ -3,13 +3,13 @@ import ReactDOM from 'react-dom/client' import { Outlet, RouterProvider, - ReactRouter, + Router, Route, Link, useParams, RootRoute, -} from '@tanstack/react-router' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +} from '@tanstack/router' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { useQuery, useQueryClient, @@ -142,13 +142,13 @@ const routeTree = rootRoute.addChildren([ postsRoute.addChildren([postsIndexRoute, postRoute]), ]) -// Set up a ReactRouter instance -const router = new ReactRouter({ +// Set up a Router instance +const router = new Router({ routeTree, defaultPreload: 'intent', }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/with-trpc-react-query/client/main.tsx b/examples/react/with-trpc-react-query/client/main.tsx index 87add64b49..2718a708cf 100644 --- a/examples/react/with-trpc-react-query/client/main.tsx +++ b/examples/react/with-trpc-react-query/client/main.tsx @@ -3,14 +3,14 @@ import ReactDOM from 'react-dom/client' import { Outlet, RouterProvider, - ReactRouter, + Router, Link, useParams, RootRoute, Route, -} from '@tanstack/react-router' +} from '@tanstack/router' import { AppRouter } from '../server/server' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { httpBatchLink } from '@trpc/client' import { createTRPCReact } from '@trpc/react-query' @@ -146,13 +146,13 @@ const routeTree = rootRoute.addChildren([ postsRoute.addChildren([postsIndexRoute, postRoute]), ]) -// Set up a ReactRouter instance -const router = new ReactRouter({ +// Set up a Router instance +const router = new Router({ routeTree, defaultPreload: 'intent', }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/with-trpc-react-query/package.json b/examples/react/with-trpc-react-query/package.json index 394fdb2f61..867d840885 100644 --- a/examples/react/with-trpc-react-query/package.json +++ b/examples/react/with-trpc-react-query/package.json @@ -13,8 +13,8 @@ "dependencies": { "@tanstack/react-query": "^4.14.1", "@tanstack/react-query-devtools": "^4.14.1", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@trpc/client": "^10.0.0-rc.6", "@trpc/react-query": "^10.0.0-rc.6", "@trpc/server": "^10.0.0-rc.6", diff --git a/examples/react/with-trpc/client/main.tsx b/examples/react/with-trpc/client/main.tsx index 48b8abebed..e6f31b03fd 100644 --- a/examples/react/with-trpc/client/main.tsx +++ b/examples/react/with-trpc/client/main.tsx @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client' import { Outlet, RouterProvider, - ReactRouter, + Router, Link, MatchRoute, useSearch, @@ -12,7 +12,7 @@ import { Route, useParams, useRouter, -} from '@tanstack/react-router' +} from '@tanstack/router' import { Loader, LoaderClient, @@ -21,7 +21,7 @@ import { useLoaderInstance, } from '@tanstack/react-loaders' import { AppRouter } from '../server/server' -import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' +import { TanStackRouterDevtools } from '@tanstack/router-devtools' import { createTRPCProxyClient, httpBatchLink } from '@trpc/client' import { z } from 'zod' @@ -381,7 +381,7 @@ const routeTree = rootRoute.addChildren([ ]), ]) -const router = new ReactRouter({ +const router = new Router({ routeTree, defaultPendingComponent: () => (
@@ -390,7 +390,7 @@ const router = new ReactRouter({ ), }) -declare module '@tanstack/react-router' { +declare module '@tanstack/router' { interface Register { router: typeof router } diff --git a/examples/react/with-trpc/package.json b/examples/react/with-trpc/package.json index 69e5b2cf66..e8dbdce883 100644 --- a/examples/react/with-trpc/package.json +++ b/examples/react/with-trpc/package.json @@ -14,8 +14,8 @@ "@tanstack/react-loaders": "0.0.1-beta.81", "@tanstack/react-query": "^4.14.1", "@tanstack/react-query-devtools": "^4.14.1", - "@tanstack/react-router": "0.0.1-beta.82", - "@tanstack/react-router-devtools": "0.0.1-beta.82", + "@tanstack/router": "0.0.1-beta.82", + "@tanstack/router-devtools": "0.0.1-beta.82", "@trpc/client": "^10.0.0-rc.6", "@trpc/react-query": "^10.0.0-rc.6", "@trpc/server": "^10.0.0-rc.6", diff --git a/examples/solid/basic/.gitignore b/examples/solid/basic/.gitignore deleted file mode 100644 index 76add878f8..0000000000 --- a/examples/solid/basic/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -dist \ No newline at end of file diff --git a/examples/solid/basic/README.md b/examples/solid/basic/README.md deleted file mode 100644 index 434f7bb9df..0000000000 --- a/examples/solid/basic/README.md +++ /dev/null @@ -1,34 +0,0 @@ -## Usage - -Those templates dependencies are maintained via [pnpm](https://pnpm.io) via `pnpm up -Lri`. - -This is the reason you see a `pnpm-lock.yaml`. That being said, any package manager will work. This file can be safely be removed once you clone a template. - -```bash -$ npm install # or pnpm install or yarn install -``` - -### Learn more on the [Solid Website](https://solidjs.com) and come chat with us on our [Discord](https://discord.com/invite/solidjs) - -## Available Scripts - -In the project directory, you can run: - -### `npm dev` or `npm start` - -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.
- -### `npm run build` - -Builds the app for production to the `dist` folder.
-It correctly bundles Solid in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -## Deployment - -You can deploy the `dist` folder to any static host provider (netlify, surge, now, etc.) diff --git a/examples/solid/basic/index.html b/examples/solid/basic/index.html deleted file mode 100644 index 0cd6aab7c0..0000000000 --- a/examples/solid/basic/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - Solid-Router Basic - - - - -
- - - - diff --git a/examples/solid/basic/package.json b/examples/solid/basic/package.json deleted file mode 100644 index be0c0d851f..0000000000 --- a/examples/solid/basic/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "tanstack-solid-router_basic", - "version": "0.0.0", - "description": "", - "scripts": { - "start": "vite", - "dev": "vite", - "build": "vite build", - "serve": "vite preview" - }, - "license": "MIT", - "devDependencies": { - "typescript": "^4.9.5", - "vite": "^4.1.1", - "vite-plugin-solid": "^2.5.0" - }, - "dependencies": { - "@tanstack/solid-router": "workspace:*", - "@tanstack/solid-loaders": "workspace:*", - "solid-js": "^1.6.10" - } -} diff --git a/examples/solid/basic/src/index.css b/examples/solid/basic/src/index.css deleted file mode 100644 index d01438c81d..0000000000 --- a/examples/solid/basic/src/index.css +++ /dev/null @@ -1,9 +0,0 @@ -body { - margin: 0; - padding: 5px -} - -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; -} diff --git a/examples/solid/basic/src/index.tsx b/examples/solid/basic/src/index.tsx deleted file mode 100644 index e0af26b782..0000000000 --- a/examples/solid/basic/src/index.tsx +++ /dev/null @@ -1,211 +0,0 @@ -/* @refresh reload */ -import { render } from 'solid-js/web' - -import './index.css' - -import { - Loader, - LoaderClient, - LoaderClientProvider, - useLoaderInstance, -} from '@tanstack/solid-loaders' -import { - ErrorComponent, - Link, - Outlet, - RootRoute, - Route, - RouterProvider, - SolidRouter, - useParams, -} from '@tanstack/solid-router' -import { Component, For } from 'solid-js' - -type PostType = { - id: string - title: string - body: string -} - -const postsLoader = new Loader({ - key: 'posts', - loader: async () => { - console.log('Fetching posts...') - await new Promise((r) => setTimeout(r, 500)) - return await fetch('https://jsonplaceholder.typicode.com/posts') - .then((response) => response.json() as Promise) - .then((r) => r.slice(0, 10)) - }, -}) - -const postLoader = new Loader({ - key: 'post', - loader: async (postId: string) => { - console.log(`Fetching post with id ${postId}...`) - - await new Promise((r) => setTimeout(r, 500)) - - if (postId === '5') { - throw new Error('Postid === 5. Example Error Boundary catching request') - } - - return await fetch( - `https://jsonplaceholder.typicode.com/posts/${postId}`, - ).then((response) => response.json() as Promise) - }, - onAllInvalidate: async () => { - await postsLoader.invalidateAll() - }, -}) - -const loaderClient = new LoaderClient({ - getLoaders: () => [postsLoader, postLoader], -}) - -declare module '@tanstack/solid-loaders' { - interface Register { - loaderClient: typeof loaderClient - } -} - -const rootRoute = new RootRoute({ - component: () => { - return ( - <> -
- - Home - {' '} - - Posts - -
-
- - - ) - }, -}) - -const indexRoute = new Route({ - getParentRoute: () => rootRoute, - path: '/', - component: () => { - return ( -
-

Welcome Home!

-
- ) - }, -}) - -const Spinner = () =>
- -const postsRoute = new Route({ - getParentRoute: () => rootRoute, - path: '/posts', - pendingComponent: Spinner, - onLoad: ({ preload }) => - loaderClient.getLoader({ key: 'posts' }).load({ preload }), - component: () => { - const postsLoaderInstance = useLoaderInstance({ - key: postsLoader.key, - }) - - return ( -
-
    - - {(post) => ( -
  • - -
    {post.title.substring(0, 20)}
    - -
  • - )} -
    -
-
- -
- ) - }, -}) - -const PostsIndexRoute = new Route({ - getParentRoute: () => postsRoute, - path: '/', - component: () => { - return ( - <> -
Select a post.
- - ) - }, -}) - -const postRoute = new Route({ - getParentRoute: () => postsRoute, - path: 'post/$postId', - wrapInSuspense: true, - pendingComponent: Spinner, - onLoad: async ({ params: { postId } }) => - postLoader.load({ variables: postId }), - errorComponent: ErrorComponent, - component: () => { - const params = useParams({ from: postRoute.id }) - - const postLoaderInstance = useLoaderInstance({ - key: postLoader.key, - variables: params.postId, - // strict: false, - }) - - return ( -
-

- {postLoaderInstance.state.data.title} -

-
{postLoaderInstance.state.data.body}
-
- ) - }, -}) - -const routeTree = rootRoute.addChildren([ - indexRoute, - postsRoute.addChildren([PostsIndexRoute, postRoute]), -]) - -const router = new SolidRouter({ - routeTree, - defaultPreload: 'intent', -}) - -const App: Component = () => { - return ( - - - - ) -} - -render(() => , document.getElementById('root') as HTMLElement) diff --git a/examples/solid/basic/tsconfig.json b/examples/solid/basic/tsconfig.json deleted file mode 100644 index 249b2732a7..0000000000 --- a/examples/solid/basic/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "strict": true, - "target": "ESNext", - "module": "ESNext", - "moduleResolution": "node", - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "jsx": "preserve", - "jsxImportSource": "solid-js", - "types": ["vite/client"], - "noEmit": true, - "isolatedModules": true - } -} diff --git a/examples/solid/basic/vite.config.ts b/examples/solid/basic/vite.config.ts deleted file mode 100644 index 9ff59a1722..0000000000 --- a/examples/solid/basic/vite.config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { defineConfig } from 'vite'; -import solidPlugin from 'vite-plugin-solid'; - -export default defineConfig({ - plugins: [solidPlugin()], - server: { - port: 3000, - }, - build: { - target: 'esnext', - }, -}); diff --git a/examples/solid/kitchen-sink-multi-file/.gitignore b/examples/solid/kitchen-sink-multi-file/.gitignore deleted file mode 100644 index d451ff16c1..0000000000 --- a/examples/solid/kitchen-sink-multi-file/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -node_modules -.DS_Store -dist -dist-ssr -*.local diff --git a/examples/solid/kitchen-sink-multi-file/README.md b/examples/solid/kitchen-sink-multi-file/README.md deleted file mode 100644 index 32519da48c..0000000000 --- a/examples/solid/kitchen-sink-multi-file/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Example - -To run this example: - -- `pnpm install` -- `pnpm start` diff --git a/examples/solid/kitchen-sink-multi-file/index.html b/examples/solid/kitchen-sink-multi-file/index.html deleted file mode 100644 index 128e63aeb5..0000000000 --- a/examples/solid/kitchen-sink-multi-file/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - Solid-Router Kitchen Sink - - - - -
- - - diff --git a/examples/solid/kitchen-sink-multi-file/package.json b/examples/solid/kitchen-sink-multi-file/package.json deleted file mode 100644 index e411f22d92..0000000000 --- a/examples/solid/kitchen-sink-multi-file/package.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "tanstack-router-solid-example-kitchen-sink-multi-file", - "version": "0.0.0", - "private": true, - "scripts": { - "dev": "vite --port=3000", - "build": "vite build", - "serve": "vite preview", - "start": "vite" - }, - "dependencies": { - "@tanstack/solid-router": "workspace:*", - "@tanstack/solid-loaders": "workspace:*", - "@tanstack/solid-actions": "workspace:*", - "vite": "^2.8.6", - "zod": "^3.19.1", - "immer": "^9.0.15" - }, - "devDependencies": { - "solid-js": "^1.6.10", - "vite-plugin-solid": "^2.5.0" - } -} diff --git a/examples/solid/kitchen-sink-multi-file/src/App.tsx b/examples/solid/kitchen-sink-multi-file/src/App.tsx deleted file mode 100644 index 0bcd0c4902..0000000000 --- a/examples/solid/kitchen-sink-multi-file/src/App.tsx +++ /dev/null @@ -1,130 +0,0 @@ -import { ActionClientProvider } from '@tanstack/solid-actions' -import { LoaderClientProvider } from '@tanstack/solid-loaders' -import { RouterProvider } from '@tanstack/solid-router' - -import { createContext, JSXElement, useContext } from 'solid-js' -import { createStore } from 'solid-js/store' -import { actionClient } from './actionClient' -import { loaderClient } from './loaderClient' -import { router } from './router' -import { useSessionStorage } from './utils' - -function App() { - // This stuff is just to tweak our sandbox setup in real-time - const [loaderDelay, setLoaderDelay] = useSessionStorage('loaderDelay', 500) - const [actionDelay, setActionDelay] = useSessionStorage('actionDelay', 500) - - const [defaultLoaderMaxAge, setDefaultLoaderMaxAge] = useSessionStorage( - 'defaultLoaderMaxAge', - 0, - ) - - return ( - <> -
-
Loader Delay: {loaderDelay()}ms
-
- setLoaderDelay(e.currentTarget.valueAsNumber)} - class="w-full" - /> -
- -
Action Delay: {actionDelay}ms
-
- setActionDelay(e.currentTarget.valueAsNumber)} - class="w-full" - /> -
-
- Loader Max Age:{' '} - {defaultLoaderMaxAge ? `${defaultLoaderMaxAge}ms` : 'Off'} -
-
- - setDefaultLoaderMaxAge(e.currentTarget.valueAsNumber) - } - class='w-full"' - /> -
-
- - - - - - - - - ) -} - -type AuthContextStore = { - status: 'loggedOut' | 'loggedIn' - username?: string -} - -type AuthContextUtils = { - login: (username: string) => void - logout: () => void -} - -const AuthContext = createContext<[AuthContextStore, AuthContextUtils]>(null!) - -export function AuthProvider(props: { children: JSXElement }) { - const [store, setStore] = createStore({ - status: 'loggedOut', - }) - - const utils = { - login(username: string) { - setStore({ status: 'loggedIn', username }) - }, - logout() { - setStore('status', 'loggedOut') - }, - } - - return ( - - {props.children} - - ) -} - -export function useAuth() { - const auth = useContext(AuthContext) - - if (!auth) { - throw new Error('useAuth must be used under an auth context') - } - - return auth! -} - -export default App diff --git a/examples/solid/kitchen-sink-multi-file/src/actionClient.tsx b/examples/solid/kitchen-sink-multi-file/src/actionClient.tsx deleted file mode 100644 index a3716170a1..0000000000 --- a/examples/solid/kitchen-sink-multi-file/src/actionClient.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import { ActionClient } from '@tanstack/solid-actions' -import { updateInvoiceAction } from './routes/dashboard/invoices/invoice' -import { createInvoiceAction } from './routes/dashboard/invoices/invoices' - -export const actionClient = new ActionClient({ - getActions: () => [createInvoiceAction, updateInvoiceAction], -}) - -declare module '@tanstack/solid-actions' { - interface Register { - actionClient: typeof actionClient - } -} diff --git a/examples/solid/kitchen-sink-multi-file/src/components/InvoiceFields.tsx b/examples/solid/kitchen-sink-multi-file/src/components/InvoiceFields.tsx deleted file mode 100644 index 911d9f2294..0000000000 --- a/examples/solid/kitchen-sink-multi-file/src/components/InvoiceFields.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { Invoice } from '../mockTodos' - -export function InvoiceFields(props: { invoice: Invoice; disabled?: boolean }) { - return ( -
-

- -

-
-