Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { createFakeFn } from './createFakeFn'
import { reexportFactory } from './reexportIndex'
// Test star re-export syntax: `export * from './module'`
import { starReexportFactory } from './starReexportIndex'
// Test nested star re-export syntax: A -> B -> C chain
import { nestedReexportFactory } from './nestedReexportA'

export const fooFn = createFooServerFn().handler(({ context }) => {
return {
Expand Down Expand Up @@ -115,3 +117,14 @@ export const starReexportedFactoryFn = starReexportFactory().handler(
}
},
)

// Test that nested star re-exported factories (A -> B -> C chain) work correctly
// The middleware from nestedReexportFactory should execute and add { nested: 'nested-middleware-executed' } to context
export const nestedReexportedFactoryFn = nestedReexportFactory().handler(
({ context }) => {
return {
name: 'nestedReexportedFactoryFn',
context,
}
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Top-level module in the nested re-export chain.
* Re-exports everything from nestedReexportB.
*
* Chain: nestedReexportA (this file) -> nestedReexportB -> nestedReexportC
*/
export * from './nestedReexportB'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Middle module in the nested re-export chain.
* Re-exports everything from nestedReexportC.
*
* Chain: nestedReexportA -> nestedReexportB (this file) -> nestedReexportC
*/
export * from './nestedReexportC'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* This is the deepest module in the nested re-export chain.
* It defines a server function factory with middleware.
*
* Chain: nestedReexportA -> nestedReexportB -> nestedReexportC (this file)
*/
import { createMiddleware, createServerFn } from '@tanstack/react-start'

const nestedMiddleware = createMiddleware({ type: 'function' }).server(
({ next }) => {
console.log('nested middleware triggered')
return next({
context: { nested: 'nested-middleware-executed' } as const,
})
},
)

export const nestedReexportFactory = createServerFn({
method: 'GET',
}).middleware([nestedMiddleware])
11 changes: 11 additions & 0 deletions e2e/react-start/server-functions/src/routes/factory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
fooFnPOST,
localFn,
localFnPOST,
nestedReexportedFactoryFn,
reexportedFactoryFn,
starReexportedFactoryFn,
} from './-functions/functions'
Expand Down Expand Up @@ -152,6 +153,16 @@ const functions = {
context: { starReexport: 'star-reexport-middleware-executed' },
},
},
// Test that nested star re-exported factories (A -> B -> C chain) work correctly
// The middleware from nestedReexportFactory should execute and add { nested: 'nested-middleware-executed' } to context
nestedReexportedFactoryFn: {
fn: nestedReexportedFactoryFn,
type: 'serverFn',
expected: {
name: 'nestedReexportedFactoryFn',
context: { nested: 'nested-middleware-executed' },
},
},
} satisfies Record<string, TestCase>

interface TestCase {
Expand Down
24 changes: 24 additions & 0 deletions e2e/react-start/server-functions/tests/server-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,27 @@ test('star re-exported server function factory middleware executes correctly', a
page.getByTestId('fn-comparison-starReexportedFactoryFn'),
).toContainText('equal')
})

test('nested star re-exported server function factory middleware executes correctly', async ({
page,
}) => {
// This test specifically verifies that when a server function factory is re-exported
// through a nested chain (A -> B -> C) using `export * from './module'` syntax,
// the middleware still executes correctly.
await page.goto('/factory')

await expect(page.getByTestId('factory-route-component')).toBeInViewport()

// Click the button for the nested re-exported factory function
await page.getByTestId('btn-fn-nestedReexportedFactoryFn').click()

// Wait for the result
await expect(
page.getByTestId('fn-result-nestedReexportedFactoryFn'),
).toContainText('nested-middleware-executed')

// Verify the full context was returned (middleware executed)
await expect(
page.getByTestId('fn-comparison-nestedReexportedFactoryFn'),
).toContainText('equal')
})
Loading
Loading