Skip to content

Commit

Permalink
Remove double decoding of encrypted closures
Browse files Browse the repository at this point in the history
With the new serverModuleMap config we don't need this second pass to decode
server references.
  • Loading branch information
sebmarkbage committed Oct 20, 2024
1 parent 1647232 commit 5153fe7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
21 changes: 4 additions & 17 deletions packages/next/src/server/app-render/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
import 'server-only'

/* eslint-disable import/no-extraneous-dependencies */
import {
renderToReadableStream,
decodeReply,
} from 'react-server-dom-webpack/server.edge'
import { renderToReadableStream } from 'react-server-dom-webpack/server.edge'
/* eslint-disable import/no-extraneous-dependencies */
import {
createFromReadableStream,
encodeReply,
} from 'react-server-dom-webpack/client.edge'
import { createFromReadableStream } from 'react-server-dom-webpack/client.edge'

import { streamToString } from '../stream-utils/node-web-streams-helper'
import {
Expand Down Expand Up @@ -118,17 +112,10 @@ export async function decryptActionBoundArgs(
moduleMap: isEdgeRuntime
? clientReferenceManifestSingleton.edgeRscModuleMapping
: clientReferenceManifestSingleton.rscModuleMapping,
serverModuleMap: null, // getServerModuleMap()
serverModuleMap: getServerModuleMap(),
},
}
)

// This extra step ensures that the server references are recovered.
const serverModuleMap = getServerModuleMap()
const transformed = await decodeReply(
await encodeReply(deserialized),
serverModuleMap
)

return transformed
return deserialized
}
17 changes: 13 additions & 4 deletions test/e2e/app-dir/actions/app/encryption/page.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
async function otherAction() {
'use server'
return 'hi'
}
// Test top-level encryption (happens during the module load phase)
function wrapAction(value) {
function wrapAction(value, action) {
return async function () {
'use server'
console.log(value)
const v = await action()
if (v === 'hi') {
console.log(value)
}
}
}

const action = wrapAction('some-module-level-encryption-value')
const action = wrapAction('some-module-level-encryption-value', otherAction)

// Test runtime encryption (happens during the rendering phase)
export default function Page() {
Expand All @@ -21,7 +28,9 @@ export default function Page() {
return 'success'
}}
>
<button type="submit">Submit</button>
<button type="submit" id="submit">
Submit
</button>
</form>
)
}

0 comments on commit 5153fe7

Please sign in to comment.