Skip to content

Commit 98413f7

Browse files
committed
simplify action entrypoint
1 parent 4b364ca commit 98413f7

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

packages/next/src/build/webpack/loaders/next-flight-action-entry-loader.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,11 @@ ${individualActions
3030
.join('\n')}
3131
}
3232
33-
async function endpoint(id, ...args) {
34-
const action = await actions[id]()
35-
return action.apply(null, args)
36-
}
37-
3833
// Using CJS to avoid this to be tree-shaken away due to unused exports.
3934
module.exports = {
4035
${individualActions
4136
.map(([id]) => {
42-
return ` '${id}': endpoint.bind(null, '${id}'),`
37+
return ` '${id}': actions['${id}'](),`
4338
})
4439
.join('\n')}
4540
}

packages/next/src/server/app-render/action-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ export async function handleAction({
870870
}
871871
}
872872

873-
const actionHandler = (
873+
const actionHandler = await (
874874
await ComponentMod.__next_app__.require(actionModId)
875875
)[
876876
// `actionId` must exist if we got here, as otherwise we would have thrown an error above

test/e2e/app-dir/actions/app-action.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,21 @@ describe('app-dir action handling', () => {
828828
).toBe(true)
829829
})
830830

831+
it('should keep action instances identical', async () => {
832+
const logs: string[] = []
833+
next.on('stdout', (log) => {
834+
logs.push(log)
835+
})
836+
837+
const browser = await next.browser('/identity')
838+
839+
await browser.elementByCss('button').click()
840+
841+
await retry(() => {
842+
expect(logs.join('')).toContain('result: true')
843+
})
844+
})
845+
831846
it.each(['node', 'edge'])(
832847
'should forward action request to a worker that contains the action handler (%s)',
833848
async (runtime) => {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use client'
2+
3+
export function Client({ foo, b }) {
4+
return (
5+
<button
6+
onClick={() => {
7+
foo(b)
8+
}}
9+
>
10+
Trigger
11+
</button>
12+
)
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Client } from './client'
2+
3+
export default async function Page() {
4+
async function b() {
5+
'use server'
6+
}
7+
8+
async function foo(a) {
9+
'use server'
10+
console.log('result:', a === b)
11+
}
12+
13+
return <Client foo={foo} b={b} />
14+
}

0 commit comments

Comments
 (0)