Skip to content

Commit f5d22d1

Browse files
committed
Add tests for constant functionId and update serverFns config logic.
1 parent 800d4db commit f5d22d1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import type { Page } from '@playwright/test'
66

77
const PORT = await getTestServerPort(packageJson.name)
88

9+
test('Server function URLs correctly include constant ids', async ({
10+
page,
11+
}) => {
12+
for (const currentPage of ['/submit-post-formdata', '/formdata-redirect']) {
13+
await page.goto(currentPage)
14+
await page.waitForLoadState('networkidle')
15+
16+
const form = page.locator('form')
17+
const actionUrl = await form.getAttribute('action')
18+
19+
expect(actionUrl).toMatch(/^\/_serverFn\/constant_id/)
20+
}
21+
})
22+
923
test('invoking a server function with custom response status code', async ({
1024
page,
1125
}) => {

e2e/react-start/server-functions/vite.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ import tsConfigPaths from 'vite-tsconfig-paths'
33
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
44
import viteReact from '@vitejs/plugin-react'
55

6+
const FUNCTIONS_WITH_CONSTANT_ID = [
7+
'src/routes/submit-post-formdata.tsx--greetUser_createServerFn_handler',
8+
'src/routes/formdata-redirect/index.tsx--greetUser_createServerFn_handler',
9+
]
10+
611
export default defineConfig({
712
plugins: [
813
tsConfigPaths({
914
projects: ['./tsconfig.json'],
1015
}),
11-
tanstackStart(),
16+
tanstackStart({
17+
serverFns: {
18+
functionId: (opts) => {
19+
if (FUNCTIONS_WITH_CONSTANT_ID.includes(opts.currentId))
20+
return 'constant_id'
21+
else return undefined
22+
},
23+
},
24+
}),
1225
viteReact(),
1326
],
1427
})

0 commit comments

Comments
 (0)