Skip to content

Commit d6331b1

Browse files
fix: revert rewrite fix
this reverts #6201 the correct fix from #6172 was applied instead.
1 parent 6500285 commit d6331b1

7 files changed

Lines changed: 9 additions & 80 deletions

File tree

‎e2e/react-start/i18n-paraglide/src/server.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import handler from '@tanstack/react-start/server-entry'
33

44
export default {
55
fetch(req: Request): Promise<Response> {
6-
return paraglideMiddleware(req, ({ request }) => handler.fetch(request))
6+
return paraglideMiddleware(req, () => handler.fetch(req))
77
},
88
}

‎examples/react/i18n-paraglide/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TanStack Router - i18n with Paraglide Example
22

3-
This example shows how to use Paraglide with TanStack Router. The source code can be found [in the Paraglide monorepo](https://github.com/opral/monorepo/tree/main/inlang/packages/paraglide/paraglide-js/examples/tanstack-router).
3+
This example shows how to use Paraglide with TanStack Router.
44

55
- [TanStack Router Docs](https://tanstack.com/router)
66
- [Paraglide Documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs)

‎examples/react/start-i18n-paraglide/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TanStack Start example with Paraglide
22

3-
This example shows how to use Paraglide with TanStack Start. The source code can be found [in the Paraglide monorepo](https://github.com/opral/monorepo/tree/main/inlang/packages/paraglide/paraglide-js/examples/tanstack-start).
3+
This example shows how to use Paraglide with TanStack Start.
44

55
- [TanStack Router Docs](https://tanstack.com/router)
66
- [Paraglide Documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs)
@@ -81,7 +81,7 @@ import { paraglideMiddleware } from './paraglide/server.js'
8181
import handler from '@tanstack/react-start/server-entry'
8282
export default {
8383
fetch(req: Request): Promise<Response> {
84-
return paraglideMiddleware(req, ({ request }) => handler.fetch(request))
84+
return paraglideMiddleware(req, () => handler.fetch(req))
8585
},
8686
}
8787
```

‎examples/solid/i18n-paraglide/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TanStack Router example
22

3-
This example shows how to use Paraglide with TanStack Router. The source code can be found [here](https://github.com/opral/monorepo/tree/main/inlang/packages/paraglide/paraglide-js/examples/tanstack-router).
3+
This example shows how to use Paraglide with TanStack Router.
44

55
## Getting started
66

‎examples/solid/start-i18n-paraglide/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TanStack Start example
22

3-
This example shows how to use Paraglide with TanStack Start. The source code can be found [here](https://github.com/opral/monorepo/tree/main/inlang/packages/paraglide/paraglide-js/examples/tanstack-start).
3+
This example shows how to use Paraglide with TanStack Start.
44

55
## Getting started
66

@@ -71,7 +71,7 @@ import handler from '@tanstack/solid-start/server-entry'
7171

7272
export default {
7373
fetch(req: Request): Promise<Response> {
74-
return paraglideMiddleware(req, ({ request }) => handler.fetch(request))
74+
return paraglideMiddleware(req, () => handler.fetch(req))
7575
},
7676
}
7777
```

‎packages/react-router/tests/router.test.tsx‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,55 +3125,6 @@ describe('Router rewrite functionality', () => {
31253125
expect(history.location.pathname).toBe('/user')
31263126
})
31273127

3128-
it('should not cause redirect loops with i18n locale prefix rewriting', async () => {
3129-
// This test simulates an i18n middleware that:
3130-
// - Input: strips locale prefix (e.g., /en/home -> /home)
3131-
// - Output: adds locale prefix back (e.g., /home -> /en/home)
3132-
3133-
const rootRoute = createRootRoute({
3134-
component: () => <Outlet />,
3135-
})
3136-
3137-
const homeRoute = createRoute({
3138-
getParentRoute: () => rootRoute,
3139-
path: '/home',
3140-
component: () => <div data-testid="home">Home</div>,
3141-
})
3142-
3143-
const routeTree = rootRoute.addChildren([homeRoute])
3144-
3145-
// The history starts at the public-facing locale-prefixed URL.
3146-
// The input rewrite strips the locale prefix for internal routing.
3147-
const history = createMemoryHistory({ initialEntries: ['/en/home'] })
3148-
3149-
const router = createRouter({
3150-
routeTree,
3151-
history,
3152-
rewrite: {
3153-
input: ({ url }) => {
3154-
// Strip locale prefix: /en/home -> /home
3155-
if (url.pathname.startsWith('/en')) {
3156-
url.pathname = url.pathname.replace(/^\/en/, '')
3157-
}
3158-
return url
3159-
},
3160-
},
3161-
})
3162-
3163-
render(<RouterProvider router={router} />)
3164-
3165-
await waitFor(() => {
3166-
expect(screen.getByTestId('home')).toBeInTheDocument()
3167-
})
3168-
3169-
// The internal pathname should be /home (after input rewrite strips /en)
3170-
expect(router.state.location.pathname).toBe('/home')
3171-
3172-
// The publicHref should include the locale prefix (via output rewrite)
3173-
// Since we only have input rewrite here, publicHref equals the internal href
3174-
expect(router.state.location.publicHref).toBe('/home')
3175-
})
3176-
31773128
it('should handle i18n rewriting with navigation between localized routes', async () => {
31783129
// Tests navigation between routes with i18n locale prefix rewriting
31793130

‎packages/router-core/src/router.ts‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,33 +1188,11 @@ export class RouterCore<
11881188

11891189
const fullPath = url.href.replace(url.origin, '')
11901190

1191-
// Save the internal pathname for route matching (before output rewrite)
1192-
const internalPathname = url.pathname
1193-
1194-
// Compute publicHref by applying the output rewrite.
1195-
//
1196-
// The publicHref represents the URL as it should appear in the browser.
1197-
// This must match what buildLocation computes for the same logical route,
1198-
// otherwise the server-side redirect check will see a mismatch and trigger
1199-
// an infinite redirect loop.
1200-
//
1201-
// We always apply the output rewrite (not conditionally) because the
1202-
// incoming URL may have already been transformed by external middleware
1203-
// before reaching the router. In that case, the input rewrite has nothing
1204-
// to do, but we still need the output rewrite to reconstruct the correct
1205-
// public-facing URL.
1206-
//
1207-
// Clone the URL to avoid mutating the one used for route matching.
1208-
const urlForOutput = new URL(url.href)
1209-
const rewrittenUrl = executeRewriteOutput(this.rewrite, urlForOutput)
1210-
const publicHref =
1211-
rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash
1212-
12131191
return {
12141192
href: fullPath,
1215-
publicHref,
1193+
publicHref: href,
12161194
url: url,
1217-
pathname: decodePath(internalPathname),
1195+
pathname: decodePath(url.pathname),
12181196
searchStr,
12191197
search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
12201198
hash: url.hash.split('#').reverse()[0] ?? '',

0 commit comments

Comments
 (0)