Skip to content

Commit

Permalink
Return early if there's no workUnitStore
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Dec 5, 2024
1 parent 75ecb09 commit 219d875
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/next/src/server/app-render/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ async function decodeActionBoundArg(actionId: string, arg: string) {
return decrypted.slice(actionId.length)
}

/**
* Encrypt the serialized string with the action id as the salt. Add a prefix to
* later ensure that the payload is correctly decrypted, similar to a checksum.
*/
async function encodeActionBoundArg(actionId: string, arg: string) {
const key = await getActionEncryptionKey()
if (key === undefined) {
Expand Down Expand Up @@ -115,14 +119,12 @@ export async function encryptActionBoundArgs(actionId: string, args: any[]) {

const workUnitStore = workUnitAsyncStorage.getStore()

const prerenderResumeDataCache = workUnitStore
? getPrerenderResumeDataCache(workUnitStore)
: null

const renderResumeDataCache = workUnitStore
? getRenderResumeDataCache(workUnitStore)
: null
if (!workUnitStore) {
return encodeActionBoundArg(actionId, serialized)
}

const prerenderResumeDataCache = getPrerenderResumeDataCache(workUnitStore)
const renderResumeDataCache = getRenderResumeDataCache(workUnitStore)
const cacheKey = actionId + serialized

const cachedEncrypted =
Expand All @@ -134,17 +136,14 @@ export async function encryptActionBoundArgs(actionId: string, args: any[]) {
}

const cacheSignal =
workUnitStore?.type === 'prerender' ? workUnitStore.cacheSignal : undefined
workUnitStore.type === 'prerender' ? workUnitStore.cacheSignal : undefined

cacheSignal?.beginRead()

// Encrypt the serialized string with the action id as the salt.
// Add a prefix to later ensure that the payload is correctly decrypted, similar
// to a checksum.
const encrypted = await encodeActionBoundArg(actionId, serialized)

cacheSignal?.endRead()
prerenderResumeDataCache?.encryptedBoundArgs?.set(cacheKey, encrypted)
prerenderResumeDataCache?.encryptedBoundArgs.set(cacheKey, encrypted)

return encrypted
}
Expand Down

0 comments on commit 219d875

Please # to comment.