Skip to content

Commit be6cbb5

Browse files
add counter?
1 parent 11e6545 commit be6cbb5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

e2e/react-start/server-functions/src/routes/middleware/retry-next.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import { createMiddleware, createServerFn } from '@tanstack/react-start'
33

4+
let count = 0
5+
46
const retryMiddleware = createMiddleware({ type: 'function' })
57
.client(async ({ next }) => {
68
await next()
79
return await next()
810
})
911
.server(async ({ next }) => {
12+
// Reset count when called a second time
13+
if (count == 4) {
14+
count = 0
15+
}
1016
await next()
1117
return await next()
1218
})
1319

1420
const serverFn = createServerFn()
1521
.middleware([retryMiddleware])
1622
.handler(() => {
17-
return 'success'
23+
return `called ${++count} times`
1824
})
1925

2026
export const Route = createFileRoute('/middleware/retry-next')({

e2e/react-start/server-functions/tests/server-functions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ test.describe('middleware', () => {
376376
async function runRetryTest(page: Page) {
377377
await page.waitForLoadState('networkidle')
378378
await expect(page.getByTestId('retry-success-result')).toContainText(
379-
'success',
379+
'called 4 times',
380380
)
381381
}
382382

0 commit comments

Comments
 (0)