TanStack / TanStack/router

Route generation does not allow plain template literals anymore after 1.166.31

Open
#7,216 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

information needed
Dominant language
TypeScript
Stars
15.1k
Forks
1.9k
Avg merge
1d 20h
Merged PRs (30d)
143

Description

Which project does this relate to?

Router

Describe the bug

Code that worked in router-cli@1.166.30 and below

const routeVarOfferDefinition = `/offers` as const;

const routeApi = getRouteApi(
  `/$locale/_main/(offers)${routeVarOfferDefinition}/$actionId/$tab`,
);

export const Route = createFileRoute(
  `/$locale/_main/(offers)${routeVarOfferDefinition}/$actionId/$tab`,
)({

now in 1.166.31+ throws this error during route generation

Error: Error transforming route file /front/spa/src/routes/$locale/_main/(offers)/-offer/$actionId/$tab.tsx: 
Error: expected route id to be a string literal or plain template literal in /$locale/_main/(offers)/offers/$actionId/$tab

We were relying heavily on semi dynamic URLs (we generate routeVarOfferDefinition like consts during prepare step before TanStack Router kicks in) and actually the error implies that it should work but does not.

I guess this PR is to blame
https://github.com/TanStack/router/pull/7167

Your Example Website or App

https://stackblitz.com/edit/github-t8vtvecd?file=src%2Froutes%2Fabout.tsx,package.json

Steps to Reproduce the Bug or Issue
  1. Go to https://stackblitz.com/edit/github-t8vtvecd?file=src%2Froutes%2Fabout.tsx,package.json
  2. Ctrl + c in terminal
  3. tsr generate -> all good
  4. update version to 1.166.31
  5. npm install
  6. tsr generate fails with expected route id to be a string literal or plain template literal as About page has dynamic part.
Expected behavior

I would expect it to continute working. One of the best Tanstack Router features for our platform as we need to support deep variations for different markets.

Screenshots or Videos

No response

Platform

@tanstack/router-cli@1.166.30

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the linked StackBlitz example by running tsr generate on router-cli@1.166.30 and again on 1.166.31. Start by tracing route generation and reviewing PR 7167; done means the example and equivalent plain template literals generate successfully on the newer version without weakening the stated route-id validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.