You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4a0017d
Browse filesBrowse the repository at this point in the historyBrowse files
feat!: locator routes — publicPrefix, per-collection catch-all routes from createRoutes, shadowed-locator checks, and redirects when a published URL moves (3c(ii)) (#43)
Chain step 21 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order.
Co-authored-by: jherr <jherr@pobox.com>
Collections served at their locators. A collection's `publicPrefix` (`'/docs'`, or `'/'` for the site root) serves each document at `{publicPrefix}/{locator}`: `createRoutes()` mounts a catch-all `{publicPrefix}/$` per such collection (the new `collections` spec key drops, limits or replaces them), and the prefix gives the collection a default `path`, so the sitemap, "View" links and page navigation use the same URL. `definition.collections()` carries `publicPrefix`. New exports: `documentPath`, `publicPrefixOf` and `normalizePublicPrefix` from `@tanstack/cms-core`, and `normalizePublicPrefix`, `SHADOWED_LOCATORS_KEY` and the `ShadowedLocators` type from `@tanstack/cms-core/definition`. `tanstackCms()` passes the route segments that shadow each collection's locators to the build as a `define`.
7
+
8
+
**Breaking:**
9
+
10
+
- When a commit, approval or scheduled publish changes the URL of a published document (from `path` or `publicPrefix`), the engine adds a permanent redirect from the old URL to the new one in the redirects collection, in the same transaction, and retargets redirects that pointed at the old URL. This applies to existing `path` functions built from the slug too, and only when the CMS has a redirects collection.
11
+
- Writes to a `publicPrefix` collection fail with `VALIDATION_FAILED` when the locator's first segment is another route under the prefix (`api` or the admin base path at the site root, an app or plugin route, another collection's prefix). A generated slug steps past it.
12
+
- A collection with `publicPrefix: '/'` mounts its catch-all at `/$` in place of `notFound`. `createRoutes()` throws when `notFound` is replaced by your own file, when a catch-all path is another route's, or when a prefix starts inside the admin or API routes. `defineCmsDefinition()` and `defineCms()` throw when two collections share a prefix.
13
+
- When the `page` collection has a `publicPrefix`, the home page, site nav and docs sidebar link to its locator URLs instead of `/p/<id>`.
| `CollectionHooks` | Pre-commit lifecycle hooks: `preValidate`, `postValidate`, `preDelete`, plus the `postRead` response transform. `afterChange` / `afterDelete` are deprecated in favour of `defineEventHandler`. See [Events & Hooks](../architecture/events-and-hooks). |
785
785
| `ChangeHookArgs` | `{ doc, id, operation, actor }` — what a pre-commit mutating hook receives. |
TheCMSpackagesshipTanStackStartserverfunctionsandroutefilesthatyourapp's Start compiler must transform. The plugin keeps `@tanstack/cms-core`, `@tanstack/cms-api`, `@tanstack/cms-ui-react`, and `@tanstack/cms-client` (plus any `packages` you add) out of Vite'sSSRexternalsanddependencypre-bundling, andbundles`@tanstack/ai*`intoSSRalongsidethem. InSSR, `resolveId`and`load`serve`use-sync-external-store`asESMonReact's own `useSyncExternalStore`, so a production server bundle under pnpm loads one React. `routesDirectory` and `generatedDirectory` are read by `createRoutes()`, which resolves route files when the config loads. When `createRoutes(definition, { renderers })` names a renderers module, the plugin's`load`hookservesthepackage's `app-renderers` module (which every CMS page route imports) as code that binds it. Add it before `tanstackStart()`.
532
+
The CMS packages ship TanStack Start server functions and route files that your app's Start compiler must transform. The plugin keeps `@tanstack/cms-core`, `@tanstack/cms-api`, `@tanstack/cms-ui-react`, and `@tanstack/cms-client` (plus any `packages` you add) out of Vite's SSR externals and dependency pre-bundling, and bundles `@tanstack/ai*` into SSR alongside them. In SSR, `resolveId` and `load` serve `use-sync-external-store` as ESM on React's own `useSyncExternalStore`, so a production server bundle under pnpm loads one React. `routesDirectory` and `generatedDirectory` are read by `createRoutes()`, which resolves route files when the config loads. In return, the plugin passes the build the route segments that [shadow a collection's locators](./routes-and-endpoints#collection-routes), so writes can reject them. When `createRoutes(definition, { renderers })` names a renderers module, the plugin's `load` hook serves the package's `app-renderers` module (which every CMS page route imports) as code that binds it. Add it before `tanstackStart()`.
0 commit comments