Skip to content

feat!: locator routes — publicPrefix, per-collection catch-all routes from createRoutes, shadowed-locator checks, and redirects when a published URL moves (3c(ii)) - #43

Merged
jherr merged 1 commit into
mainfrom
cursor/locator-routes-a931
Nov 6, 2026

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements part (ii) of cms-refactor-plan.md § Phase 3 (3c), plus rules 6 and 7 of § "Decided: nested slugs": no shadowing of app routes, and renames write a redirect.

Merge chain: step 21 of 24. Base: main. Merge it right after #38. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit 2a891d8 (tree 4f31216).

What

  • Collection.publicPrefix. It takes a path such as '/docs', or '/' for the site root, and serves each document at {prefix}/{locator}.
    • It gives the collection a default path. An explicit path still wins.
    • The sitemap, the editor's "View" link and page navigation use documentPath(collection, doc, id).
    • Two collections with the same prefix throw.
    • New exports:
      • from core: documentPath, publicPrefixOf, normalizePublicPrefix;
      • from /definition: normalizePublicPrefix, SHADOWED_LOCATORS_KEY, ShadowedLocators, LocatorInput, LocatorStrategy.
  • Catch-all routes from createRoutes. Each prefixed collection gets a generated {prefix}/$ route.
    • Lookup: it calls get({ collection, locator }) first. If nothing matches, it tries the redirects collection, then returns a 404.
    • Spec key: the new collections key takes true, false, ['docs'] or { docs: false | './docs.$.tsx' }. It's separate from R2's renderers.
    • Root collection: a collection with prefix '/' takes over /$ from notFound.
  • Rule 6: no shadowing.
    • When routes are built, createRoutes throws if a catch-all collides with another route, or if a prefix starts inside the admin or API routes.
    • On every write, a locator whose first segment another route owns under the prefix is rejected with VALIDATION_FAILED. A generated slug steps past it instead, e.g. api-2. The tanstackCms() plugin passes the map of shadowed segments to builds. Without the plugin, core falls back to the checks it can make on its own.
  • Rule 7: redirects. writeDocument is the single path for commit, approve and scheduled publish. When a published document's URL changes, it writes a 301 from the old URL in the same transaction.
    • Chains are retargeted to stay one hop.
    • Redirects that would loop are trashed.
    • The id is deterministic.
    • Redirects are written only when a redirects collection exists.
  • Starlight on a nested slug. This covers examples/astro-starlight-after, its migration script, the skill and from-astro-starlight.md.
    • Pages use a nested: true slug under /docs.
    • Old Starlight URLs redirect.
    • The parity test checks that each page is served at /docs/<path>.
  • Fix to feat(ui-react)!: createRoutes(definition, spec) replaces cmsVirtualRoutes(options) #28's prefixed route copies: a $' in a path like /docs/$ was being read as a replacement pattern. The fix was made here while feat(ui-react)!: createRoutes(definition, spec) replaces cmsVirtualRoutes(options) #28 was on hold. On the merge chain it lands at this step, after feat(ui-react)!: createRoutes(definition, spec) replaces cmsVirtualRoutes(options) #28.
  • Docs and changeset: five reference pages and a new upgrading step (step 30 on the merge chain).

No schema migration. Redirects are ordinary documents, so nothing has to be ordered against 3c(i)'s v17/v9 or 4b's v16/v8.

Merge of #28: conflicts and resolutions (for replay)

File Resolution
scripts/codemods/index.ts union of the four codemods
.claude/skills/payload-to-tanstack-cms/SKILL.md, docs/migration/from-sanity.md #28's text, using readDocumentAs
docs/schema/building-pages.md both descriptions combined, and both sides' keywords
starters/contact-cards, starters/ecommerce-storefront cms.config.ts imports unioned
starters/documentation-kb, starters/multi-tenant-fleet cms.config.ts #28's file; the op bodies keep 2c's …As(ctx) reads. 3c(i)'s locatorStrategy moves into their cms.definition.ts.
app/base/src/model.ts #28's file. 2c's hook signatures are ported into collection-runtime.ts, where currentSession() is gone.
docs/deployment/upgrading.md #28's steps 20 and 21 come first. The B stack's steps are renumbered 22–25.

Upgrading numbering. #42 had resolved the same conflict the other way. The merge chain settles a single sequence: upgrading steps are numbered in merge order, and this PR's step is 30.

Scratch merge with origin/main: 25 conflicts, all caused by the squash merge of R1a (#22). That squash commit has the same tree as cursor/explicit-roles-6828, which is already in this branch's history, so the branch side was taken everywhere.

Breaking changes

  • Redirects on URL changes. A published URL change adds a redirect when a redirects collection exists. That includes existing slug-built paths such as /post/${slug}.
  • Shadowed locators. Writes to a prefixed collection reject a locator whose first segment is shadowed.
  • Root collections. A root collection takes over /$. createRoutes and the definition also throw in the new cases described above.
  • page links. When the page collection has a prefix, home, nav and the docs sidebar link to locator URLs. /p/$id still serves pages.
  • Starlight output. The Starlight example and skill output now use a slug field and /docs/<slug> URLs.

How verified

  • New core tests/locator-routes.test.ts (9 tests):
    • the default path, and path winning over it;
    • prefixes;
    • shadowing at build and on write;
    • the generated-slug step-past;
    • redirects: written, retargeted, loop-trashed, skipped when unpublished, and skipped when no redirects collection exists.
  • New ui-react tests cover the catch-all routes and the collections spec key.
  • New blog E2E covers a nested locator (/docs/guides/getting-started) and a redirect after a rename.
  • Local CI (GitHub Actions is out of billing), on scratch head b704ecc, which merges 610d8e9 into origin/main 3b4a112.
Check Result
pnpm install --frozen-lockfile passes
pnpm test:ci (174 tasks) Only the known @tanstack/cms-api:test:oxlint fails. Core 660, ui-react 99, every starter passes.
test:dts / test:definitions pass / 26
test:dialects Exits 0. One extra non-test queryDocuments match comes from a storage-level call, not the deprecated verb.
test:scripts 100 pass
E2E blog / base 30 / 12 pass

The first full run caught two failures, both fixed in 610d8e9:

  • the definition-split codemod's export list was missing the new /definition exports;
  • a retired dialect marker matched one of the new createRoutes error messages.

One base E2E test failed once, after a dev-server "Failed to fetch", and passed on three later runs.

Assumptions (conservative defaults where the plan gives none)

  • publicPrefix is opt-in, so no existing URL changes. path wins over it.
  • Starlight is served under /docs, not at the site root.
  • At a root mount, the index route still owns /.
  • Dynamic route segments don't shadow locators.
  • Without the plugin, writes fall back to the checks core can make on its own.
  • No boot-time scan for stored locators that are already shadowed.
  • Redirects are system revisions with no hooks or events. Imports, seeds and content migrations don't create them.
  • collections follows the public setting by default.

Divergence from plan

Follow-ups

  • The review queue could flag clashing pending creates (3c-b).
  • A bulk section rename with a prefix redirect.

Merge chain (local verification, CI down)

This PR's commits are squashed into one commit on the linear merge chain. That commit holds this PR's own changes, resolved against every PR before it, with the integration rehearsal's fixes for this PR applied. Seven conflicts, resolved as in the rehearsal: vite.ts, virtual-routes.ts and its test, internal.ts, cms-ui-react.md, and the Starlight MIGRATION.md and migration test. routes/collection.$.tsx imports ../app-renderers, which #31 added. Its upgrading section is step 30. The commit was replayed from 8bd2116.

The chain tip's tree is exactly the integration rehearsal plus #46 (c4e6d7c), and the tip passes the full local suite. I simulated merging every PR in order, with a merge commit or a fast-forward at each step, and every step is clean. A plain squash of the next PR would conflict, because the squash commit isn't an ancestor of the next branch. To squash instead, first rebase the branch's one commit onto the new main; that rebase is always clean.

Open in Web Open in Cursor 

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a0017d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/cms-core Minor
@tanstack/cms-ui-react Minor
@tanstack/cms-api Minor
@tanstack/cms-cli Minor
@tanstack/cms-client Minor
@tanstack/cms-connect-atproto Patch
@tanstack/cms-migrate-wp Patch
@tanstack/cms-skills Patch
@tanstack/cms-media-s3 Minor
@tanstack/search-cms Patch
@tanstack/cms-store-libsql Minor
@tanstack/cms-store-postgres Patch
@tanstack/cms-ui-dom Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: TanStack/cms
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: a82e4de
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: 6056e657-6276-4daa-be17-9533aefe3297
Commits

Reviewing files that changed from the base of the PR and between a82e4de and 4a0017d.

Files selected for processing: 49

  • .changeset/locator-routes.md
  • .claude/skills/astro-starlight-to-tanstack-cms/SKILL.md
  • .claude/skills/astro-starlight-to-tanstack-cms/scripts/migrate-starlight.mjs
  • docs/api/cms-core.md
  • docs/api/cms-ui-react.md
  • docs/api/routes-and-endpoints.md
  • docs/architecture/routes-in-a-package.md
  • docs/deployment/upgrading.md
  • docs/migration/from-astro-starlight.md
  • docs/schema/collections-and-fields.md
  • examples/astro-starlight-after/MIGRATION.md
  • examples/astro-starlight-after/README.md
  • examples/astro-starlight-after/scripts/migrate-starlight.mjs
  • examples/astro-starlight-after/src/cms.definition.ts
  • examples/astro-starlight-after/src/migration.test.ts
  • examples/astro-starlight-after/src/routeTree.gen.ts
  • examples/astro-starlight-after/src/seed-data.ts
  • examples/blog/e2e/locators.spec.ts
  • examples/blog/src/cms.config.ts
  • examples/blog/src/cms.definition.ts
  • examples/blog/src/routeTree.gen.ts
  • examples/blog/tsconfig.json
  • packages/core/src/config.ts
  • packages/core/src/definition.ts
  • packages/core/src/index.ts
  • packages/core/src/lib/definition.ts
  • packages/core/src/lib/public-prefix.ts
  • packages/core/src/lib/ui.ts
  • packages/core/src/locator.ts
  • packages/core/src/schema.ts
  • packages/core/src/server/locator-redirects.ts
  • packages/core/src/server/locators.ts
  • packages/core/src/server/seo.ts
  • packages/core/src/server/store/internal.ts
  • packages/core/tests/locator-routes.test.ts
  • packages/ui-react/src/components/docs-nav.tsx
  • packages/ui-react/src/components/site-shell.tsx
  • packages/ui-react/src/lib/public-data.ts
  • packages/ui-react/src/routes/collection.$.tsx
  • packages/ui-react/src/routes/edit.$collection.$id.tsx
  • packages/ui-react/src/routes/index.tsx
  • packages/ui-react/src/routes/p.$id.tsx
  • packages/ui-react/src/routes/post.$id.tsx
  • packages/ui-react/src/virtual-routes.ts
  • packages/ui-react/src/vite.ts
  • packages/ui-react/tests/virtual-routes.test.ts
  • scripts/codemods/definition-split.ts
  • scripts/seo-snapshots/__snapshots__/examples__blog.json
  • scripts/seo-snapshots/seo-snapshots.test.ts

TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.

  • Ask an admin to upgrade

Open in CodeRabbit

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

cursor Bot pushed a commit that referenced this pull request Nov 6, 2026
…, shadowed locators, redirects on move)

Co-authored-by: jherr <jherr@pobox.com>
cursor Bot pushed a commit that referenced this pull request Nov 6, 2026
Co-authored-by: jherr <jherr@pobox.com>
@cursor
cursor Bot force-pushed the cursor/locator-routes-a931 branch from 610d8e9 to 2a891d8 Compare November 6, 2026 14:50
@cursor
cursor Bot force-pushed the cursor/locators-a931 branch from 29df10d to 31e8607 Compare November 6, 2026 14:50
@cursor
cursor Bot changed the base branch from cursor/locators-a931 to main November 6, 2026 14:58
… 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>
@jherr
jherr force-pushed the cursor/locator-routes-a931 branch from 2a891d8 to 4a0017d Compare November 6, 2026 15:09
@jherr
jherr merged commit d410e7c into main Nov 6, 2026
@jherr
jherr deleted the cursor/locator-routes-a931 branch November 8, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants