Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove double decoding of encrypted closures #71527

Merged
merged 1 commit into from
Oct 20, 2024
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
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>
)
}
Loading