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
24 changes: 24 additions & 0 deletions packages/plugin-rsc/e2e/source-map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,30 @@ test.describe('source map', () => {
}
})
}

test('preserves Server Function names in stack traces', async ({ page }) => {
await page.goto(f.url('/server-function-name'))
await waitForHydration(page)

const cases = [
{
referenceName: 'module-function-name',
functionName: 'moduleFunctionName',
},
{
referenceName: 'inline-function-name',
functionName: 'inlineFunctionName',
},
]

for (const item of cases) {
const button = page.getByRole('button', {
name: new RegExp(`^${item.referenceName}:`),
})
await button.click()
await expect(button).toContainText(`at ${item.functionName} (`)
}
})
})

async function createFunctionSourceMapResolver(page: Page, baseURL: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export async function moduleFunctionName() {
return new Error().stack?.split('\n')[1] ?? ''
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { SourceLocationCase } from '../../client'
import { moduleFunctionName } from './action'

export function ServerFunctionName() {
async function inlineFunctionName() {
'use server'
return new Error().stack?.split('\n')[1] ?? ''
}

return (
<section>
<h2>Server Function names</h2>
<ul>
<li>
<SourceLocationCase
name="module-function-name"
action={moduleFunctionName}
/>
</li>
<li>
<SourceLocationCase
name="inline-function-name"
action={inlineFunctionName}
/>
</li>
</ul>
</section>
)
}
8 changes: 8 additions & 0 deletions packages/plugin-rsc/examples/source-map/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MultipleExports } from './features/multiple-exports/server'
import { NamedFunction } from './features/named-function/server'
import { ServerActionError } from './features/server-action-error/server'
import { ServerComponentError } from './features/server-component-error/server'
import { ServerFunctionName } from './features/server-function-name/server'
import { ServerReferenceFromClient } from './features/server-reference-from-client/server'
import { Specifiers } from './features/specifiers/server'
import { TypescriptTsx } from './features/typescript-tsx/server'
Expand Down Expand Up @@ -65,6 +66,13 @@ const routes = [
description: 'Two generated registrations from one module.',
render: () => <MultipleExports />,
},
{
path: '/server-function-name',
title: 'Server Function names',
description:
'Module-level and inline Server Functions preserve their source names in stack traces.',
render: () => <ServerFunctionName />,
},
{
path: '/server-action-error',
title: 'Server Action error',
Expand Down
Loading